struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jitesh Vidhani" <jit...@covigna.com>
Subject Problem writing a Filter with Struts
Date Fri, 31 May 2002 18:49:13 GMT
Hi all,

I am trying to write a Filter around my struts layer.

Basically what I want to achieve is that when the User tries to go to a
particular URL, I make him go through the Filter. The filter calls
chain.doFilter() and I then I check to see if the ActionBean has set up a
particular attribute in the request. If it has been set then the Filter
modifies the response and outputs a different HTML onto the client.

Heres the code snippet from my Filter:

		ServletOutputStream out = response.getOutputStream();
		ResponseWrapper wrapper = new
ResponseWrapper((HttpServletResponse)response);
		chain.doFilter(request, wrapper);

		if(request.getAttribute("Modify")!=null)
		{
			CharArrayWriter caw = new CharArrayWriter();
			caw.write("<html><body>THIS IS THE MODIFIED PAGE</body></html>");
			response.setContentLength(caw.toString().length());
			out.print(caw.toString());
		}
		else


			byte[] bytes = wrapper.toByteArray();
			System.out.println("About to add: " + String.valueOf(bytes.length) + "
bytes to the stream: " + new String(bytes));
			out.write(bytes);
			response.setContentLength(bytes.length);
		}
		response.setContentType("text/html");
		out.flush();
		out.close();

I have a wrapper wherein I extend the HttpServletResponseWrapper and use a
ByteArrayOutoutStream and I have overridden the getWriter() and the
getOutputStream() methods of the HttpServletResponseWrapper.

Now when I try to use this URL in the client browser then I somehow see an
Empty page irrespective of whether the request attribute has been set or
not. I also tried to print the Bytes from the wrapper that I am writing out
to the response's ServletOutputStream and it seems to be right.

I have written a small test servlet and the Filter works just fine with that
Servlet.

I am not able to figure out where I am going wrong. Any help would be
appreciated.

Thanks,
Jitesh


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message