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...
https://www.czetsuyatech.com/2017/09/javaee-rest-servlet-request-and-response.html
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:
As for SOAP, it's almost the same:
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);
Post a Comment