• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Print Client IP

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Nilu Deshmukh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!
providing @Context HttpServletRequest
as a method param works perfect!

 
reply
    Bookmark Topic Watch Topic
  • New Topic