Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Filter Configuration in Websphere Application Server 6.1

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Men call me Jim. Women look past me to this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic