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

Accessing HttpServletRequest from Restful webservice

Balaji Sundararaju
Greenhorn

Joined: Dec 17, 2008
Posts: 3
I'm trying to access HTTPServletRequest from Restful webservice. Please let me know on how to do it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
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

Joined: Dec 17, 2008
Posts: 3
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

Joined: Aug 19, 2005
Posts: 2922
    
    5
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

Joined: Oct 11, 2008
Posts: 9
CFX has nothing to do with Jersey with one exception: almost everything. The differences should be minuscule.


We don't know if the climate change whosey-whatsit is man made or just a part of the end of days.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing HttpServletRequest from Restful webservice