2009年11月18日水曜日

[Grails]IOException occurs when calling redirect() in case of using Compress plugin

IOException occurs when calling redirect() in case of using Compress plugin in Grails environment.
  • References

  • Description
    IOException occurs and outputs if you call redirect() in case of using Compress plugin(pjl Compression filter) under the Jetty as the servlet container. If you set the debug level of the log4j option to WARN or DEBUG for the org.mortbay java package in Config.groovy, the message "java.io.IOException: Closed" outputs into the stdout or debug file.
    (Maybe this problem will not occur if you use the Tomcat or other servlet container., but i don't know the detail of this in case of using the Tomcat or other servlet container.)

  • Error Messages
    Following is a error stack when calling redirect() method.
    java.io.IOException: Closed
    at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:627)
    at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:577)
    at java.util.zip.GZIPOutputStream.finish(GZIPOutputStream.java:91)
    at com.planetj.servlet.filter.compression.CompressingStreamFactory$GZIPCompressingStreamFactory$1.finish(CompressingStreamFactory.java:369)
    at com.planetj.servlet.filter.compression.ThresholdOutputStream.close(ThresholdOutputStream.java:131)
    at com.planetj.servlet.filter.compression.CompressingServletOutputStream.close(CompressingServletOutputStream.java:92)
    at com.opensymphony.module.sitemesh.filter.RoutableServletOutputStream.close(RoutableServletOutputStream.java:46)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:343)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:293)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:269)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:261)
    at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:181)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    ......
  • Cause
    This problem occures because the pjl Compression Filter tries to call the close() method for the OutputStream object which is already closed at the end of the response. When closing the output stream, flush() method is called before closing in org.mortbay.jetty.AbstractGenerator$Output.write object. When calling the org.mortbay.jetty.AbstractGenerator$Output.write method, System checks whether the Output object is already closed or not. If the object is already closed, JVM raises the IOException.

  • Solution(workaround)
    Before calling the redirect() method, response.getWriter().write("") calls as follows.
     def test={
    response.getWriter().write("");
    return redirect(url:"http://example.com");
    }

0 件のコメント: