I spent nearly 3 weeks on a response wrapping problem, I didn't yet figured out the cause, I'm deploying my web app to JRUN4 server. the problem arise when I tried to filter struts actions (*.do) with a response wrapping filter, so in WEB.XML I wrote :
<filter> <filter-name>My Response Wrapper</filter-name> <filter-class>filters.WrapperFilter</filter-class> </filter>
<filter-mapping> <filter-name>My Response Wrapper</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>
the code in my filter is :
WrapperFilter.java
-------------------------
OutputStream out = response.getOutputStream();
out.write("<HR>PRE HTML FOR TEST <HR>".getBytes());
GenericResponseWrapper wrapper = new GenericResponseWrapper ((HttpServletResponse) response);
chain.doFilter(request, wrapper);
out.write(wrapper.getData());
out.write("<HR>POST HTML FOR TEST<HR>".getBytes());
out.close();
==========================================
GenericResponseWrapper.java : ------------------------------------------- package filters;
import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; import java.io.ByteArrayOutputStream; import java.io.PrintWriter;
public class GenericResponseWrapper extends HttpServletResponseWrapper { private ByteArrayOutputStream output; private int contentLength; private String contentType;
public GenericResponseWrapper(HttpServletResponse response) { super(response); output = new ByteArrayOutputStream(); }
public byte[] getData() { return output.toByteArray(); }
public ServletOutputStream getOutputStream() { return new FilterServletOutputStream(output); }
public void setContentLength(int length) { this.contentLength = length; super.setContentLength(length); }
public int getContentLength() { return contentLength; }
public void setContentType(String type) { this.contentType = type; super.setContentType(type); }
public String getContentType() { return contentType; }
public PrintWriter getWriter() { return new PrintWriter(getOutputStream(), true); }
} ========================================================
when an action URL (http://localhost:8100/emgr/login.do) is called in browser,the page shows NOTHING ,that action is doing certain process and than forwarding to tile defininition : main.home.page , the logged error is :
jrun.servlet.io.ClosedIOException: Response has been closed at jrun.servlet.io.ClosedOutputStream.write(ClosedOutputStream.java:23) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109) at jrun.servlet.http.WebOutputStream.write(WebOutputStream.java:64) at java.io.OutputStream.write(OutputStream.java:58) at filters.WrapperFilter.doFilter(WrapperFilter.java:176) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) .....
Also I noticed that the same filter is working fine if my action is forwarding to a JSP instead of a tiles definition name
so instead of mapping the filter to *.do I mapped it to *.jsp :
<filter-mapping> <filter-name>My Response Wrapper</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>
that time the page shows correctly with the pre/post text embedded. I'm confused, is it a struts , tiles or JRUN problem ?
any help will be appreciated.
Regards.
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]