Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Wrapping response causing premature stream closure

Wrapping response causing premature stream closure

2004-01-15       - By Derek Richardson

 Back
I am attempting to wrap the HttpServletResponse to apply gzip compression on
data sent to the client when gzip is supported. I have written a filter (based
on published code) that works fine with static content. I, however, have a
problem when applying it to dynamic content. The dynamic content is written
using Struts and it seems to be breaking during the tiles includes. However,
struts does not seem to be the culprit - the same code works fine without the
filter.

The problem is straightforward - I receive a "java.io.IOException Source code of java.io.IOException: Stream
closed" message. I am not including the stack trace because, in my mind (which
I am out of with frustration at this moment), the problem is not where the
closed stream is detected, but where it is closed. I placed a log statement in
my wrapper to dump a stack trace when close() is called and this stack trace is
included below. It seems that close() is being called from org.apache.catalina
.core.ApplicationDispatcher.doForward(). But my confusion is how my wrapper
could be causing this closure, since the application works fine without the
wrapper.

My question is: what could I be doing in the request or output stream wrappers
that would cause the stream to be closed?

The wrapper source code is also below.

Thanks,

Derek Richardson

********************************************************************************

2004-01-15 16:34:21,092 [http8080-Processor3] DEBUG com.appiancorp.ap2.Compressi
onResponseStream - ^^^^^^^^^^^^^^^^^^^^^^^^ Closing...
java.lang.Exception Source code of java.lang.Exception
       at com.appiancorp.ap2.CompressionResponseStream.close(Unknown Source)
       at sun.nio.cs.StreamEncoder$CharsetSE.implClose(StreamEncoder.java:431)
       at sun.nio.cs.StreamEncoder.close(StreamEncoder.java:160)
       at java.io.OutputStreamWriter Source code of java.io.OutputStreamWriter(OutputStreamWriter.java:222)
       at java.io.PrintWriter Source code of java.io.PrintWriter(PrintWriter.java:137)
       at org.apache.jasper.runtime.JspWriterImpl Source code of org.apache.jasper.runtime.JspWriterImpl(JspWriterImpl.java:223)

       at java.io.PrintWriter Source code of java.io.PrintWriter(PrintWriter.java:137)
       at org.apache.jasper.runtime.JspWriterImpl Source code of org.apache.jasper.runtime.JspWriterImpl(JspWriterImpl.java:223)

       at java.io.PrintWriter Source code of java.io.PrintWriter(PrintWriter.java:137)
       at org.apache.jasper.runtime.JspWriterImpl Source code of org.apache.jasper.runtime.JspWriterImpl(JspWriterImpl.java:223)

       at java.io.PrintWriter Source code of java.io.PrintWriter(PrintWriter.java:137)
       at org.apache.jasper.runtime.JspWriterImpl Source code of org.apache.jasper.runtime.JspWriterImpl(JspWriterImpl.java:223)

       at java.io.PrintWriter Source code of java.io.PrintWriter(PrintWriter.java:137)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:453)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:356)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.
java:1069)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(TilesRequestP
rocessor.java:274)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(Reques
tProcessor.java:455)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(Ti
lesRequestProcessor.java:320)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.ja
va:279)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:148
2)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:525)

       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:760)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:575)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:498)
       at org.apache.jasper.runtime.JspRuntimeLibrary Source code of org.apache.jasper.runtime.JspRuntimeLibrary(JspRuntimeLibrary
.java:822)
       at org.apache.jasper.runtime.PageContextImpl Source code of org.apache.jasper.runtime.PageContextImpl(PageContextImpl.jav
a:398)
       at org.apache.struts.tiles.TilesUtilImpl Source code of org.apache.struts.tiles.TilesUtilImpl(TilesUtilImpl.java:13
7)
       at org.apache.struts.tiles.TilesUtil Source code of org.apache.struts.tiles.TilesUtil(TilesUtil.java:177)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:756
)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(Inser
tTag.java:881)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:473)

       at org.apache.jsp.portlet_default_jsp._jspx_meth_t_insert_0(portlet_defa
ult_jsp.java:1099)
       at org.apache.jsp.portlet_default_jsp._jspService(portlet_default_jsp.ja
va:364)
       at org.apache.jasper.runtime.HttpJspBase Source code of org.apache.jasper.runtime.HttpJspBase(HttpJspBase.java:137)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.jasper.servlet.JspServletWrapper Source code of org.apache.jasper.servlet.JspServletWrapper(JspServletWrapper
.java:210)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:2
95)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:241)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:575)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:498)
       at org.apache.jasper.runtime.JspRuntimeLibrary Source code of org.apache.jasper.runtime.JspRuntimeLibrary(JspRuntimeLibrary
.java:822)
       at org.apache.jasper.runtime.PageContextImpl Source code of org.apache.jasper.runtime.PageContextImpl(PageContextImpl.jav
a:398)
       at org.apache.struts.tiles.TilesUtilImpl Source code of org.apache.struts.tiles.TilesUtilImpl(TilesUtilImpl.java:13
7)
       at org.apache.struts.tiles.TilesUtil Source code of org.apache.struts.tiles.TilesUtil(TilesUtil.java:177)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:756
)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(Inser
tTag.java:881)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:473)

       at org.apache.jsp.portletarea_jsp._jspService(portletarea_jsp.java:275)
       at org.apache.jasper.runtime.HttpJspBase Source code of org.apache.jasper.runtime.HttpJspBase(HttpJspBase.java:137)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.jasper.servlet.JspServletWrapper Source code of org.apache.jasper.servlet.JspServletWrapper(JspServletWrapper
.java:210)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:2
95)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:241)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:575)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:498)
       at org.apache.jasper.runtime.JspRuntimeLibrary Source code of org.apache.jasper.runtime.JspRuntimeLibrary(JspRuntimeLibrary
.java:822)
       at org.apache.jasper.runtime.PageContextImpl Source code of org.apache.jasper.runtime.PageContextImpl(PageContextImpl.jav
a:398)
       at org.apache.struts.tiles.TilesUtilImpl Source code of org.apache.struts.tiles.TilesUtilImpl(TilesUtilImpl.java:13
7)
       at org.apache.struts.tiles.TilesUtil Source code of org.apache.struts.tiles.TilesUtil(TilesUtil.java:177)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:756
)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(Inser
tTag.java:881)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:473)

       at org.apache.jsp.template_default_jsp._jspx_meth_t_insert_3(template_de
fault_jsp.java:785)
       at org.apache.jsp.template_default_jsp._jspService(template_default_jsp.
java:357)
       at org.apache.jasper.runtime.HttpJspBase Source code of org.apache.jasper.runtime.HttpJspBase(HttpJspBase.java:137)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.jasper.servlet.JspServletWrapper Source code of org.apache.jasper.servlet.JspServletWrapper(JspServletWrapper
.java:210)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:2
95)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:241)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:575)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:498)
       at org.apache.jasper.runtime.JspRuntimeLibrary Source code of org.apache.jasper.runtime.JspRuntimeLibrary(JspRuntimeLibrary
.java:822)
       at org.apache.jasper.runtime.PageContextImpl Source code of org.apache.jasper.runtime.PageContextImpl(PageContextImpl.jav
a:398)
       at org.apache.struts.tiles.TilesUtilImpl Source code of org.apache.struts.tiles.TilesUtilImpl(TilesUtilImpl.java:13
7)
       at org.apache.struts.tiles.TilesUtil Source code of org.apache.struts.tiles.TilesUtil(TilesUtil.java:177)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:756
)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(Inser
tTag.java:881)
       at org.apache.struts.taglib.tiles.InsertTag Source code of org.apache.struts.taglib.tiles.InsertTag(InsertTag.java:473)

       at org.apache.jsp.portal_jsp._jspx_meth_t_insert_0(portal_jsp.java:133)
       at org.apache.jsp.portal_jsp._jspService(portal_jsp.java:104)
       at org.apache.jasper.runtime.HttpJspBase Source code of org.apache.jasper.runtime.HttpJspBase(HttpJspBase.java:137)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.jasper.servlet.JspServletWrapper Source code of org.apache.jasper.servlet.JspServletWrapper(JspServletWrapper
.java:210)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:2
95)
       at org.apache.jasper.servlet.JspServlet Source code of org.apache.jasper.servlet.JspServlet(JspServlet.java:241)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:432)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:356)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.
java:1069)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(TilesRequestP
rocessor.java:274)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(Reques
tProcessor.java:455)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(Ti
lesRequestProcessor.java:320)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.ja
va:279)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:148
2)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:525)

       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:760)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:432)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:356)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.
java:1069)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(TilesRequestP
rocessor.java:274)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(Reques
tProcessor.java:455)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(Ti
lesRequestProcessor.java:320)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.ja
va:279)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:148
2)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:525)

       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:760)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:432)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:356)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.
java:1069)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(TilesRequestP
rocessor.java:274)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(Reques
tProcessor.java:455)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(Ti
lesRequestProcessor.java:320)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.ja
va:279)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:148
2)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:525)

       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:760)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDisp
atcher.java:684)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationD
ispatcher.java:432)
       at org.apache.catalina.core.ApplicationDispatcher Source code of org.apache.catalina.core.ApplicationDispatcher(ApplicationDis
patcher.java:356)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.
java:1069)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(TilesRequestP
rocessor.java:274)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(Reques
tProcessor.java:455)
       at org.apache.struts.tiles.TilesRequestProcessor Source code of org.apache.struts.tiles.TilesRequestProcessor(Ti
lesRequestProcessor.java:320)
       at org.apache.struts.action.RequestProcessor Source code of org.apache.struts.action.RequestProcessor(RequestProcessor.ja
va:279)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:148
2)
       at org.apache.struts.action.ActionServlet Source code of org.apache.struts.action.ActionServlet(ActionServlet.java:525)

       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:760)
       at javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(Appl
icationFilterChain.java:247)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(ApplicationF
ilterChain.java:193)
       at com.appiancorp.ap2.EntryFilter.doFilter(Unknown Source)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(Appl
icationFilterChain.java:213)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(ApplicationF
ilterChain.java:193)
       at com.appiancorp.ap2.AuthenticationFilter.doFilter(Unknown Source)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(Appl
icationFilterChain.java:213)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(ApplicationF
ilterChain.java:193)
       at com.appiancorp.ap2.WrapFilter.doFilter(Unknown Source)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(Appl
icationFilterChain.java:213)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(ApplicationF
ilterChain.java:193)
       at com.appiancorp.ap2.CompressionFilter.doFilter(Unknown Source)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(Appl
icationFilterChain.java:213)
       at org.apache.catalina.core.ApplicationFilterChain Source code of org.apache.catalina.core.ApplicationFilterChain(ApplicationF
ilterChain.java:193)
       at org.apache.catalina.core.StandardWrapperValve Source code of org.apache.catalina.core.StandardWrapperValve(StandardWrapperV
alve.java:256)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline(StandardPipeline.jav
a:480)
       at org.apache.catalina.core.ContainerBase Source code of org.apache.catalina.core.ContainerBase(ContainerBase.java:995)

       at org.apache.catalina.core.StandardContextValve Source code of org.apache.catalina.core.StandardContextValve(StandardContextV
alve.java:191)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline(StandardPipeline.jav
a:480)
       at org.apache.catalina.core.ContainerBase Source code of org.apache.catalina.core.ContainerBase(ContainerBase.java:995)

       at org.apache.catalina.core.StandardContext Source code of org.apache.catalina.core.StandardContext(StandardContext.java:
2417)
       at org.apache.catalina.core.StandardHostValve Source code of org.apache.catalina.core.StandardHostValve(StandardHostValve.j
ava:180)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
       at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
       at org.apache.catalina.valves.ErrorReportValve Source code of org.apache.catalina.valves.ErrorReportValve(ErrorReportValve.j
ava:172)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline(StandardPipeline.jav
a:480)
       at org.apache.catalina.core.ContainerBase Source code of org.apache.catalina.core.ContainerBase(ContainerBase.java:995)

       at org.apache.catalina.core.StandardEngineValve Source code of org.apache.catalina.core.StandardEngineValve(StandardEngineVal
ve.java:174)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
       at org.apache.catalina.core.StandardPipeline Source code of org.apache.catalina.core.StandardPipeline(StandardPipeline.jav
a:480)
       at org.apache.catalina.core.ContainerBase Source code of org.apache.catalina.core.ContainerBase(ContainerBase.java:995)

       at org.apache.coyote.tomcat4.CoyoteAdapter Source code of org.apache.coyote.tomcat4.CoyoteAdapter(CoyoteAdapter.java:19
3)
       at org.apache.coyote.http11.Http11Processor Source code of org.apache.coyote.http11.Http11Processor(Http11Processor.java
:781)
       at org.apache.coyote.http11.Http11Protocol Source code of org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:549)
       at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:589)
       at org.apache.tomcat.util.threads.ThreadPool Source code of org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:666)
       at java.lang.Thread Source code of java.lang.Thread(Thread.java:534)

********************************************************************************

package com.appiancorp.ap2;

import java.io.IOException Source code of java.io.IOException;
import java.io.OutputStreamWriter Source code of java.io.OutputStreamWriter;
import java.io.PrintWriter Source code of java.io.PrintWriter;

import javax.servlet.ServletOutputStream Source code of javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse Source code of javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper Source code of javax.servlet.http.HttpServletResponseWrapper;

import org.apache.log4j.Logger Source code of org.apache.log4j.Logger;

public class CompressionResponseWrapper extends HttpServletResponseWrapper {
 protected ServletOutputStream stream = null;
 protected PrintWriter writer = null;

 public CompressionResponseWrapper(HttpServletResponse response) {
   super(response);
 }

 public ServletOutputStream createOutputStream() throws IOException {
   return new CompressionResponseStream((HttpServletResponse)getResponse());
 }

 public void finishResponse() {
   if (_log.isDebugEnabled()) _log.error("In finishResponse()");
   if (writer != null) writer.close();
   else {
     try {
       if (stream != null) stream.close();
     } catch (IOException e) {
       if (_log.isDebugEnabled()) _log.error("Couldn't close stream",e);
     }
   }
 }

 public void flushBuffer() throws IOException {
   stream.flush();
 }

 public ServletOutputStream getOutputStream() throws IOException {
   if (stream != null) return stream;
   if (writer != null) {
     throw new IllegalStateException("getWriter() has already been called!");
   }
   stream = createOutputStream();
   return stream;
 }

 public PrintWriter getWriter() throws IOException {
   if (writer != null) return writer;
   if (stream != null) {
     throw new IllegalStateException("getOutputStream() has already been
called!");
   }
   stream = createOutputStream();
   writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8 (See http://UTF-8.ora-code.com)"));
   return writer;
 }

 public void setContentLength(int length) { /* noop - set in stream.close() */
}
 private static Logger _log = Logger.getLogger(CompressionResponseWrapper
.class);
}

********************************************************************************

package com.appiancorp.ap2;

import java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream;
import java.io.IOException Source code of java.io.IOException;
import java.util.zip.GZIPOutputStream Source code of java.util.zip.GZIPOutputStream;

import javax.servlet.ServletOutputStream Source code of javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse Source code of javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger Source code of org.apache.log4j.Logger;

public class CompressionResponseStream extends ServletOutputStream {
 protected ByteArrayOutputStream baos = null;
 protected GZIPOutputStream gzipstream = null;
 protected boolean closed = false;
 protected HttpServletResponse response = null;
 protected ServletOutputStream output = null;

 public CompressionResponseStream(HttpServletResponse response)
   throws IOException {
   super();
   closed = false;
   this.response = response;
   this.output = response.getOutputStream();
   baos = new ByteArrayOutputStream();
   gzipstream = new GZIPOutputStream(baos);
 }

 public void close() throws IOException {
   if (_log.isDebugEnabled()) _log.debug("^^^^^^^^^^^^^^^^^^^^^^^^ Closing..."
, new Exception());
   if (closed) {
     _log.warn("This output stream has already been closed");
     //throw new IOException("This output stream has already been closed");
     return;
   }
   gzipstream.finish();

   byte[] bytes = baos.toByteArray();

   response.addHeader("Content-Length", Integer.toString(bytes.length));
   response.addHeader("Content-Encoding", "gzip");
   output.write(bytes);
   output.flush();
   output.close();
   closed = true;
 }

 public void flush() throws IOException {
   if (closed) {
     throw new IOException("Cannot flush a closed output stream");
   }
   gzipstream.flush();
 }

 public void write(int b) throws IOException {
   if (closed) {
     throw new IOException("Cannot write to a closed output stream");
   }
   gzipstream.write((byte) b);
 }

 public void write(byte b[]) throws IOException {
   write(b, 0, b.length);
 }

 public void write(byte b[], int off, int len) throws IOException {
   if (closed) {
     throw new IOException("Cannot write to a closed output stream");
   }
   gzipstream.write(b, off, len);
 }

 public boolean closed() {
   return (this.closed);
 }

 public void reset() {
   if (_log.isDebugEnabled()) _log.debug("*************************** reset");
   //noop
 }
 private static Logger _log = Logger.getLogger(CompressionResponseStream.class
);
}

-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)




©2008 junlu.com - Jax Systems, LLC, U.S.A.