Raghavendra Nandagopal

Greenhorn
+ Follow
since Jul 29, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Raghavendra Nandagopal

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
13 years ago