aspose file tools*
The moose likes Servlets and the fly likes Filter Configuration in Websphere Application Server 6.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filter Configuration in Websphere Application Server 6.1" Watch "Filter Configuration in Websphere Application Server 6.1" New topic
Author

Filter Configuration in Websphere Application Server 6.1

Raghavendra Nandagopal
Greenhorn

Joined: Jul 29, 2009
Posts: 1
Hi All,
We are facing an issue in Filter configuration to a Servlet. Basically, once the servlet filter is finished with its execution,
it is not redirecting to the specified page. The response content after the servlet filter execution is null.
We are using WebSphere Application Server 6.1

The dofilter method code of GZIPFilter is given below.
try {

HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpServletRequest httpRequest = (HttpServletRequest) request;

/*
* Conditions
* i) if the browser accepts 'gzip' functionality.
* ii) if the response object is not committed.
* Then compress response data.
*/
if (accepts(httpRequest, "gzip")
&& (!httpResponse.isCommitted())) {
/* Set the response header to encode data as 'gzip' */
httpResponse.setHeader("Content-Encoding", "gzip");
httpResponse.setHeader("Pragma", "No-Cache");
httpResponse.setHeader("Cache-Control", "no-Cache");
httpResponse.setHeader("Cache-Control", "no-store"); //HTTP 1.1
httpResponse.setDateHeader("Expires", 0);

/* A generic wrapper object to handle httpResponse object*/
GenericResponseWrapper wrapper =
new GenericResponseWrapper(httpResponse);

chain.doFilter(request, wrapper);
//printMe("doFilter - Size Before Compression",String.valueOf(wrapper.getData().length));
/* Conditions
* i) if response object is not cached.
* ii) if request object is not included.
* iii) if response object length is not zero
* i.e., user didn't click on exit button
*/
if (!isCached(wrapper)
&& !isIncluded(request)
&& wrapper.getData() != null
&& wrapper.getData().length != 0) {
ByteArrayOutputStream compressed =
new ByteArrayOutputStream();
GZIPOutputStream gzout = new GZIPOutputStream(compressed);
gzout.write(wrapper.getData());
gzout.flush();
gzout.close();
OutputStream out = response.getOutputStream();
out.write(compressed.toByteArray());
//printMe("doFilter - Size After Compression",String.valueOf(compressed.size()));
out.flush();
out.close();
}
}
/*
* if the browser doesn't handle gzip functionality then do
* not compress response data.
*/
else {
GenericResponseWrapper wrapper =
new GenericResponseWrapper(httpResponse);
chain.doFilter(request, wrapper);
OutputStream out = response.getOutputStream();
/* Condition
* i) if response object length is not zero
* i.e., user didn't click on exit button
*/
if (wrapper.getData() != null && wrapper.getData().length != 0) {
out.write(wrapper.getData());
out.flush();
out.close();
}
}
} catch (Throwable ex) {
/*printError(
"doFilter",
"Error occured, due to closing window abruptly",
ex);*/
}

The servelt filter code is given below:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
{
processTask(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
{
processTask(request, response);
}

private void processTask(HttpServletRequest request, HttpServletResponse response)
{
try
{
getServletContext().getRequestDispatcher("pricing/testing.jsp").forward(request, response);
} catch (ServletException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}

The Web.xml configuration is given below.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID">
<display-name>
GZipFilter</display-name>
<filter>
<description>
</description>
<display-name>
GZIPFilter</display-name>
<filter-name>GZIPFilter</filter-name>
<filter-class>com.training.cse.pricing.filter.GZIPFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>GZIPFilter</filter-name>
<url-pattern>/GZIPFilter</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>GZIPFilter</filter-name>
<servlet-name>PricingControlServlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<description>
</description>
<display-name>
PricingControlServlet</display-name>
<servlet-name>PricingControlServlet</servlet-name>
<servlet-class>
com.training.cse.pricing.commonComp.PricingControlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PricingControlServlet</servlet-name>
<url-pattern>/PricingControlServlet</url-pattern>
</servlet-mapping>
</web-app>

Regards,
Raghav
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter Configuration in Websphere Application Server 6.1