as by Sun servlet 2.3 specs, I'm using httpServletResponseWrapper to wrapp response object, the technique didn't work and I didn't yet figured out the cause, I'm deploying my web app to JRUN (I don't know if JRUN4 container is related to the problem)
my question is :
is there something wrong in the following code in order to wrap response object with struts/tiles ? , is this has to do with "flush=true" in tiles:insert ? or is there any limitations for wrapping response in Struts framework? or is it a Tiles limitation ?


in my 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
-------------------------

package filters;

import java.io.IOException;
import javax.servlet.Filter;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class WrapperFilter implements javax.servlet.Filter {

   public void doFilter(   javax.servlet.ServletRequest  request,
                           javax.servlet.ServletResponse response,
                           javax.servlet.FilterChain chain  )
        throws IOException, ServletException {

ServletContext context = filterConfig.getServletContext();
HttpServletRequest req = (HttpServletRequest) request;
OutputStream out = response.getOutputStream();
out.write("<HR>PRE<HR>".getBytes());
GenericResponseWrapper wrapper = new GenericResponseWrapper((HttpServletResponse) response);
chain.doFilter(request, wrapper);
out.write(wrapper.getData());
context.log(wrapper.getData().toString());
out.write("<HR>POST<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);
  }

}
========================================================


so when an action URL (http://localhost:8100/emgr/login.do) is called in browser,the page shows NOTHING (empty page) , that login.do action is doing a simple 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 ?


Regards.


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to