I can get access to the HttpServlet Request object in a soap web service as follows: Declaring a private field for the WebServiceContext in the service implementation, and annotate it as a resource:
@Resource
private WebServiceContext context;
To get the HttpServletRequet object, I write the code as below:
MessageContext ctx = context.getMessageContext();
HttpServletRequest request =(HttpServletRequest)ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
But these things are not working in a restful web service. I am using Apache CXF for developing restful web service. Please tell me how can I get access to HttpServletRequest Object.
use this code for access request and response for each request:
I'd recommend using
org.apache.cxf.jaxrs.ext.MessageContext
You can use the
@Context
annotation to flag other types (such as ServletContext or the HttpServletRequest specifically). See Context Annotations.