no

How to access HttpServletRequest and HttpServletResponse in REST and SOAP

There are times when we need either HttpServletRequest or HttpServletResponse in our REST or SOAP api. These objects are readily available i...

There are times when we need either HttpServletRequest or HttpServletResponse in our REST or SOAP api. These objects are readily available if you know how to inject them.

Common usage of HttpServletRequest is when getting the request variables or for HttpServletResponse when downloading a file.

How to inject:
REST:

In REST it's as simply as injecting the HttpServlet object. For example:

@Context 
private HttpServletResponse httpServletResponse;

@Context 
private HttpServletRequest httpServletRequest;


As for SOAP, it's almost the same:
@Resource
protected WebServiceContext webServiceContext;

MessageContext mc = webServiceContext.getMessageContext();
HttpServletResponse response = (HttpServletResponse) mc.get(MessageContext.SERVLET_RESPONSE);

Related

javaee-rest 2158096107397994097

Post a Comment Default Comments

Outsourcing

Are you looking for freelancers in the Philippines? Get in touch.

Donations

If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.

item