No, the problem is that the implementation you are using is the same as the
one our programmer tried to use.  In the Servlet spec, you can write to
response 2 different ways.  Depending on the application server you are
using, this can be through the writer or stream, but not both.  This is the
problem you are seeing.

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#get
OutputStream()

Have your ResponseWrapper instead write to an object like this.  Also, in
your filter, before you wrap, check the instanceof the response to make sure
you don't double bag the response (servlet 2.3 spec).

public class ResponseToken 
{
        private byte[] content;
        private transient ByteArrayOutputStream outputStream = new
ByteArrayOutputStream();
        
        public ResponseToken()
        {
        }
        
        public ResponseToken(String content)
        {
                this.content = content.getBytes();
        }
        
        public void commit()
        {
                if (this.content == null)
                {
                        try
                        {
                                this.outputStream.close();
                        }
                        catch (IOException e)
                        {
                        }
                        this.content = this.outputStream.toByteArray();
                }
        }
        
        public OutputStream getOutputStream()
        {
                return outputStream;
        }
        
        public void setOutputStream(ByteArrayOutputStream outputStream)
        {
                this.outputStream = outputStream;
        }
        
        public void readExternal(ObjectInput input)
                throws IOException, ClassNotFoundException
        {
                this.content = (byte[]) input.readObject();
        }
        
        public void writeExternal(ObjectOutput output) throws IOException
        {
                this.commit();

                output.writeObject(this.content);
        }
        
        public void writeToResponse(HttpServletResponse response)
                        throws ServletException, IOException
        {
                this.commit();

                OutputStream os = new
BufferedOutputStream(response.getOutputStream());
                os.write(this.content);
                os.flush();
        }
}

Jacob Hookom
Senior Analyst/Programmer
McKesson Medical-Surgical
Golden Valley, Minnesota
http://www.mckesson.com

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 09, 2004 3:24 PM
To: [EMAIL PROTECTED]
Subject: RE: Compression Filter

Indeed, I got the exceptions you mentioned.  Presumably, this is because
requests for ".do"s ultimately either forward or redirect to JSP's, and, I
believe, either one will flush the response buffer and hence commit the
response.

So, does this mean there's no way to enable a filter-based compression with
Struts?


-----Original Message-----
From: Hookom, Jacob [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 09, 2004 4:04 PM
To: Struts Users Mailing List
Subject: RE: Compression Filter


Check your server logs for exceptions that say the response has already been
committed.  We had a programmer try to create a compression filter based on
the source from one of those articles and it did not work on our production
servers.  Worth a look...

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 09, 2004 2:56 PM
To: [EMAIL PROTECTED]
Subject: Compression Filter

I'm trying to implement a compression filter on the HTTP response similar to
that discussed in
http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html?page=1.

When requesting straight JSP's, it works fine, but any Struts ".do"s do not
work.  Specifically, it appears the compression filter itself functions
normally, but the browser responds with an empty page.  (The source code,
cryptically enough, does include <html><body></body></html>, but I suspect
that's being defaulted somewhere.)

I've tried:

- Configuring the filter to handle *.do as a url-pattern, instead of the
servlet-name "action".
- Commenting out the compression code entirely, leaving only
        GZIPResponseWrapper wrappedResponse = new GZIPResponseWrapper(res);
      chain.doFilter(req, wrappedResponse);
- Executing the compression on a subclass of ActionServlet (after the
super's doGet/doPost are called).

...but still the same results.

We are running Struts on Sybase EAServer 4.2, by the way.

Thanks in advance,

Shahak Nagiel
Software Engineer
Northrop Grumman Mission Systems

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

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

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

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

Reply via email to