You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Gr...@servicecanada.gc.ca on 2006/10/19 19:45:46 UTC

[slight OT] GZip compression filter

Has anyone gotten a compression filter to work with Tap4? I guess since Tap4 has a single servlet, and uses lots of redirects or something, I always get "Response already committed" for all my pages.

Thanks,
Greg


RE: [slight OT] GZip compression filter

Posted by Gr...@servicecanada.gc.ca.
Here's my web.xml, it's servlet2.3. Still no luck. Could be Websphere :|

[10/19/06 14:40:49:096 EDT] 2a73e0b6 SRTServletRes W WARNING: Cannot set header. Response already committed.
[10/19/06 14:40:49:096 EDT] 2a73e0b6 WebGroup      E SRVE0026E: [Servlet Error]-[Filter [GzipFilter]: filter is unavailable.]: 


  <filter>
    <filter-name>HibernateThreadFilter</filter-name>
    <filter-class>ca.gc.publiservice.commontools.hibernate.filters.HibernateThreadFilter</filter-class>
  </filter>
  <filter>
    <filter-name>GzipFilter</filter-name>
    <filter-class>ca.gc.publiservice.commontools.web.GzipFilter</filter-class>
  </filter>
  
  <filter-mapping>
    <filter-name>GzipFilter</filter-name>
    <!--<servlet-name>pctadmin</servlet-name>-->
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <filter-mapping>
    <filter-name>HibernateThreadFilter</filter-name>
    <servlet-name>pctadmin</servlet-name>
  </filter-mapping>


-----Original Message-----
From: Paul Ferraro [mailto:pmf8@columbia.edu]
Sent: Thursday, October 19, 2006 2:19 PM
To: Tapestry users
Subject: Re: [slight OT] GZip compression filter


Yes.  Since the filter applies http headers before the tapestry servlet
handles the request, you should be able to do this without issue.

How is your filter set up in your web.xml?

Here is mine (using pjl-comp-filter and servlet 2.4):
<filter>
  <filter-name>compress</filter-name>
<filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
  <!-- Adobe's plugin for IE chokes on gzip'ed PDFs -->
  <init-param>
    <param-name>excludeContentTypes</param-name>
    <param-value>application/pdf</param-value>
  </init-param>
  <init-param>
    <param-name>excludePathPatterns</param-name>
    <param-value>.*\.pdf</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>compress</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

Paul

On Thu, 2006-10-19 at 13:45 -0400, Greg.L.Cormier@servicecanada.gc.ca
wrote:
> Has anyone gotten a compression filter to work with Tap4? I guess since Tap4 has a single servlet, and uses lots of redirects or something, I always get "Response already committed" for all my pages.
> 
> Thanks,
> Greg
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: [slight OT] GZip compression filter

Posted by Gr...@servicecanada.gc.ca.
This looks great. Thanks for your help Paul!
 
-Greg
-----Original Message-----
From: Paul Ferraro [mailto:pmf8@columbia.edu]
Sent: Thursday, October 19, 2006 3:12 PM
To: Tapestry users
Subject: RE: [slight OT] GZip compression filter


I'm not immediately sure what's wrong with your filter.  Compare it to the implementation here:
http://sourceforge.net/projects/pjl-comp-filter

You may even want to use this implementation instead as it is a bit more robust.

Paul

On Thu, 2006-10-19 at 14:24 -0400, Greg.L.Cormier@servicecanada.gc.ca wrote: 

My web.xml is similar, except I had "/app" as my servlet-name under filter-mapping, and i had no <dispatcher> tag.



Hmm, perhaps it's my filter itself then doing something in the wrong order? It's a very tiny chunk of code



public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException

  {

    HttpServletRequest req = (HttpServletRequest) request;

    HttpServletResponse res = (HttpServletResponse) response;

    

    if (!isGzipSupported(req))	// check headers to see if supported

    {

      // Invoke resource normally.

      chain.doFilter(req, res);

    }

    else

    {

      // Tell browser we are sending it gzipped data.

      res.setHeader("Content-Encoding", "gzip");

      

      // Invoke resource, accumulating output in the wrapper.

      ResponseWrapper responseWrapper = new ResponseWrapper(res);

      chain.doFilter(req, responseWrapper);

      

      // Get character array representing output.

      char[] responseChars = responseWrapper.toCharArray();

      

      // Make a writer that compresses data and puts

      // it into a byte array.

      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();

      GZIPOutputStream zipOut = new GZIPOutputStream(byteStream);

      OutputStreamWriter tempOut = new OutputStreamWriter(zipOut);

      

      // Compress original output and put it into byte array.

      tempOut.write(responseChars);

      

      // Gzip streams must be explicitly closed.

      tempOut.close();

      

      // Update the Content-Length header.

      res.setContentLength(byteStream.size());

      

      // Send compressed result to client.

      OutputStream realOut = res.getOutputStream();

      byteStream.writeTo(realOut);

    }

    

  }









-----Original Message-----

From: Paul Ferraro [mailto: pmf8@columbia.edu]

Sent: Thursday, October 19, 2006 2:19 PM

To: Tapestry users

Subject: Re: [slight OT] GZip compression filter





Yes.  Since the filter applies http headers before the tapestry servlet

handles the request, you should be able to do this without issue.



How is your filter set up in your web.xml?



Here is mine (using pjl-comp-filter and servlet 2.4):

<filter>

  <filter-name>compress</filter-name>

<filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>

  <!-- Adobe's plugin for IE chokes on gzip'ed PDFs -->

  <init-param>

    <param-name>excludeContentTypes</param-name>

    <param-value>application/pdf</param-value>

  </init-param>

  <init-param>

    <param-name>excludePathPatterns</param-name>

    <param-value>.*\.pdf</param-value>

  </init-param>

</filter>

<filter-mapping>

  <filter-name>compress</filter-name>

  <url-pattern>/*</url-pattern>

  <dispatcher>REQUEST</dispatcher>

</filter-mapping>



Paul



On Thu, 2006-10-19 at 13:45 -0400,  Greg.L.Cormier@servicecanada.gc.ca

wrote:

> Has anyone gotten a compression filter to work with Tap4? I guess since Tap4 has a single servlet, and uses lots of redirects or something, I always get "Response already committed" for all my pages.

> 

> Thanks,

> Greg

> 



---------------------------------------------------------------------

To unsubscribe, e-mail:  users-unsubscribe@tapestry.apache.org

For additional commands, e-mail:  users-help@tapestry.apache.org




RE: [slight OT] GZip compression filter

Posted by Paul Ferraro <pm...@columbia.edu>.
I'm not immediately sure what's wrong with your filter.  Compare it to
the implementation here:
http://sourceforge.net/projects/pjl-comp-filter

You may even want to use this implementation instead as it is a bit more
robust.
 
Paul

On Thu, 2006-10-19 at 14:24 -0400, Greg.L.Cormier@servicecanada.gc.ca
wrote:

> My web.xml is similar, except I had "/app" as my servlet-name under filter-mapping, and i had no <dispatcher> tag.
> 
> Hmm, perhaps it's my filter itself then doing something in the wrong order? It's a very tiny chunk of code
> 
> public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException
>   {
>     HttpServletRequest req = (HttpServletRequest) request;
>     HttpServletResponse res = (HttpServletResponse) response;
>     
>     if (!isGzipSupported(req))	// check headers to see if supported
>     {
>       // Invoke resource normally.
>       chain.doFilter(req, res);
>     }
>     else
>     {
>       // Tell browser we are sending it gzipped data.
>       res.setHeader("Content-Encoding", "gzip");
>       
>       // Invoke resource, accumulating output in the wrapper.
>       ResponseWrapper responseWrapper = new ResponseWrapper(res);
>       chain.doFilter(req, responseWrapper);
>       
>       // Get character array representing output.
>       char[] responseChars = responseWrapper.toCharArray();
>       
>       // Make a writer that compresses data and puts
>       // it into a byte array.
>       ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
>       GZIPOutputStream zipOut = new GZIPOutputStream(byteStream);
>       OutputStreamWriter tempOut = new OutputStreamWriter(zipOut);
>       
>       // Compress original output and put it into byte array.
>       tempOut.write(responseChars);
>       
>       // Gzip streams must be explicitly closed.
>       tempOut.close();
>       
>       // Update the Content-Length header.
>       res.setContentLength(byteStream.size());
>       
>       // Send compressed result to client.
>       OutputStream realOut = res.getOutputStream();
>       byteStream.writeTo(realOut);
>     }
>     
>   }
> 
> 
> 
> 
> -----Original Message-----
> From: Paul Ferraro [mailto:pmf8@columbia.edu]
> Sent: Thursday, October 19, 2006 2:19 PM
> To: Tapestry users
> Subject: Re: [slight OT] GZip compression filter
> 
> 
> Yes.  Since the filter applies http headers before the tapestry servlet
> handles the request, you should be able to do this without issue.
> 
> How is your filter set up in your web.xml?
> 
> Here is mine (using pjl-comp-filter and servlet 2.4):
> <filter>
>   <filter-name>compress</filter-name>
> <filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
>   <!-- Adobe's plugin for IE chokes on gzip'ed PDFs -->
>   <init-param>
>     <param-name>excludeContentTypes</param-name>
>     <param-value>application/pdf</param-value>
>   </init-param>
>   <init-param>
>     <param-name>excludePathPatterns</param-name>
>     <param-value>.*\.pdf</param-value>
>   </init-param>
> </filter>
> <filter-mapping>
>   <filter-name>compress</filter-name>
>   <url-pattern>/*</url-pattern>
>   <dispatcher>REQUEST</dispatcher>
> </filter-mapping>
> 
> Paul
> 
> On Thu, 2006-10-19 at 13:45 -0400, Greg.L.Cormier@servicecanada.gc.ca
> wrote:
> > Has anyone gotten a compression filter to work with Tap4? I guess since Tap4 has a single servlet, and uses lots of redirects or something, I always get "Response already committed" for all my pages.
> > 
> > Thanks,
> > Greg
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

RE: [slight OT] GZip compression filter

Posted by Gr...@servicecanada.gc.ca.
My web.xml is similar, except I had "/app" as my servlet-name under filter-mapping, and i had no <dispatcher> tag.

Hmm, perhaps it's my filter itself then doing something in the wrong order? It's a very tiny chunk of code

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException
  {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    
    if (!isGzipSupported(req))	// check headers to see if supported
    {
      // Invoke resource normally.
      chain.doFilter(req, res);
    }
    else
    {
      // Tell browser we are sending it gzipped data.
      res.setHeader("Content-Encoding", "gzip");
      
      // Invoke resource, accumulating output in the wrapper.
      ResponseWrapper responseWrapper = new ResponseWrapper(res);
      chain.doFilter(req, responseWrapper);
      
      // Get character array representing output.
      char[] responseChars = responseWrapper.toCharArray();
      
      // Make a writer that compresses data and puts
      // it into a byte array.
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      GZIPOutputStream zipOut = new GZIPOutputStream(byteStream);
      OutputStreamWriter tempOut = new OutputStreamWriter(zipOut);
      
      // Compress original output and put it into byte array.
      tempOut.write(responseChars);
      
      // Gzip streams must be explicitly closed.
      tempOut.close();
      
      // Update the Content-Length header.
      res.setContentLength(byteStream.size());
      
      // Send compressed result to client.
      OutputStream realOut = res.getOutputStream();
      byteStream.writeTo(realOut);
    }
    
  }




-----Original Message-----
From: Paul Ferraro [mailto:pmf8@columbia.edu]
Sent: Thursday, October 19, 2006 2:19 PM
To: Tapestry users
Subject: Re: [slight OT] GZip compression filter


Yes.  Since the filter applies http headers before the tapestry servlet
handles the request, you should be able to do this without issue.

How is your filter set up in your web.xml?

Here is mine (using pjl-comp-filter and servlet 2.4):
<filter>
  <filter-name>compress</filter-name>
<filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
  <!-- Adobe's plugin for IE chokes on gzip'ed PDFs -->
  <init-param>
    <param-name>excludeContentTypes</param-name>
    <param-value>application/pdf</param-value>
  </init-param>
  <init-param>
    <param-name>excludePathPatterns</param-name>
    <param-value>.*\.pdf</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>compress</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

Paul

On Thu, 2006-10-19 at 13:45 -0400, Greg.L.Cormier@servicecanada.gc.ca
wrote:
> Has anyone gotten a compression filter to work with Tap4? I guess since Tap4 has a single servlet, and uses lots of redirects or something, I always get "Response already committed" for all my pages.
> 
> Thanks,
> Greg
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [slight OT] GZip compression filter

Posted by Paul Ferraro <pm...@columbia.edu>.
Yes.  Since the filter applies http headers before the tapestry servlet
handles the request, you should be able to do this without issue.

How is your filter set up in your web.xml?

Here is mine (using pjl-comp-filter and servlet 2.4):
<filter>
  <filter-name>compress</filter-name>
<filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
  <!-- Adobe's plugin for IE chokes on gzip'ed PDFs -->
  <init-param>
    <param-name>excludeContentTypes</param-name>
    <param-value>application/pdf</param-value>
  </init-param>
  <init-param>
    <param-name>excludePathPatterns</param-name>
    <param-value>.*\.pdf</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>compress</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

Paul

On Thu, 2006-10-19 at 13:45 -0400, Greg.L.Cormier@servicecanada.gc.ca
wrote:
> Has anyone gotten a compression filter to work with Tap4? I guess since Tap4 has a single servlet, and uses lots of redirects or something, I always get "Response already committed" for all my pages.
> 
> Thanks,
> Greg
>