How to access HttpServletRequest and HttpServletResponse in both REST and SOAP service
Tech-Today

How to access HttpServletRequest and HttpServletResponse in both REST and SOAP service


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);




- How To Download A File In Soap Api
First we define the interface like this: @WebMethod ActionStatus downloadFile(@WebParam(name = "file") String file); Implementation: public ActionStatus downloadFile(String filePath) { MessageContext mc = webServiceContext.getMessageContext(); // see...

- How To Download A File Using Rest Api
Normally I create an interface when defining a REST api, this is useful when testing using Arquillian. To define a download file api we must define the method below in the interface. @GET @Path("/downloadFile") ActionStatus downloadFile(@QueryParam("file")...

- How To Protect Your Page Using Webfilter In Javaee
This tutorial is to be use in conjunction with picketlink. Normally we want some pages to be accessible only after a user has logged in. In this case we need a real protection filter. The class below filters a url path and check if there's a logged...

- How To Implement No Caching On Jsf Pages
Currently there are 2 ways I know that can do this. 1.) By implementing Filter and manually overriding the cache controls. See code below (note: not my original I found this somewhere else long time ago): @WebFilter(servletNames = { "Faces Servlet" })...

- Creating Your First Enterprise Application Project On Eclipse-jee-helios
First you should create an ejb project as specified here: http://czetsuya-tech.blogspot.com/2011/03/creating-your-first-ejb3-project-in.html Take note that my interface were inside the ejb project. You can pull that out and place in its own project ipielEJB2Client....



Tech-Today








.