Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing HttpServletRequest from Restful webservice

 
Balaji Sundararaju
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to access HTTPServletRequest from Restful webservice. Please let me know on how to do it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps a little information on how you are implementing the API might be helpful, do you think?

If it's the Jersey project, there's a simple annotation (@Context) that will inject this into a field member.
[ December 19, 2008: Message edited by: Bear Bibeault ]
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Balaji Sundararaju:
I'm trying to access HTTPServletRequest from Restful webservice.


Why? Even with JAX-RS (Jersey) there is no guarantee that the web service is deployed inside a servlet container. Some of the equivalent functionality may be found elsewhere - but what specifically are you looking for?
 
Balaji Sundararaju
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a JAX-RS (Jersey) project and I used the @Context annotation to get hold of the WebServiceContext object.

When I tried accessing the message context from the web service context object I'm getting null.

Please let me know what I'm missing here.

Below is the beans.xml I'm using

 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Balaji Sundararaju:
It is a JAX-RS (Jersey) project


Looks to me that it actually is an Apache CXF JAX-RS project - which as far as I can tell has nothing to do with Jersey.

According to the JSR-311 API (JAX-RS) you should be able to get

javax.ws.rs.core.UriInfo
javax.ws.rs.core.Request
javax.ws.rs.core.HttpHeaders
javax.ws.rs.core.SecurityContext
javax.ws.rs.ext.Providers

from javax.ws.rs.core.Context

javax.xml.ws.WebServiceContext and javax.xml.ws.handler.MessageContext are JAX-WS objects that have no meaning in the JAX-RS context.
[ December 22, 2008: Message edited by: Peer Reynders ]
 
Richard O'Shay
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CFX has nothing to do with Jersey with one exception: almost everything. The differences should be minuscule.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic