aspose file tools*
The moose likes Web Services and the fly likes Print Client IP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Print Client IP" Watch "Print Client IP" New topic
Author

Print Client IP

Nilu Deshmukh
Greenhorn

Joined: Aug 03, 2009
Posts: 22
I am Using Rest Web services. I want to Insert Client IP address into database. I tried.. following



but I am getting Null Pointer Exception..

Can anybody help me regarding this..

Thanks in Advance..

Nilesh
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Edit: The code below is for JAX-WS web services, while the question was about RESTful web services.
---
First: If you are using an EJB to implement the web service, then you will not be able to obtain the HTTP request object.
If you are not using an EJB, try this:

Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Nilu Deshmukh
Greenhorn

Joined: Aug 03, 2009
Posts: 22
Thanks Ivan,

But how to run this code.. I am new into Rest web services and I only aware of RestEasy Web services.



I only know this kind of web services..

Please send me Complete code or yours and please also tell how to run this..


Thanks Again
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Sorry, my mistake!
I missed that you are using REST web services.
The code I provided is for JAX-WS web services.
I will post a solution to your problem as soon as I have some more time.
Best wishes!
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I modified one of the examples enclosed with JBoss RESTEasy and here is an example of a method in a REST resource that can access the HttpServletRequest object related to the incoming request:

By annotating a method parameter, you assure yourself that the request object is obtained in connection to processing a request.
I had a case once where injection into an instance field resulted in one single dependency injection, which very soon became stale.
To see what kind of objects you can have injected into a resource class using the @Context annotation, see section 6.1 (if I remember correctly) of the JAX-RS specification.
Best wishes!
ralph soika
Greenhorn

Joined: Jun 05, 2008
Posts: 11
Thanks a lot!
providing @Context HttpServletRequest
as a method param works perfect!

 
wood burning stoves
 
subject: Print Client IP