2009年11月18日水曜日

[Grails]ignore the excludePathPatterns parameter when using the Compress Plugin

In Grails environment, Compress Plugin ignore the excludePathPatterns option and filter doesn't work fine.
  • References
  • Description
    The Compress Plugin ignores the excludePathPatterns parameter even though I set the excludePathPatterns parameter in grails-app/conf/Config.groovy as follows, the Compress filter tries to compress for the css or pdf files. the css and pdf files should be exclude and disable the compression process for these files.
    (If you need to use the excludePathPatterns, the value of includePathPattern has to be set to null or empty.)
    includePathPatterns = []
    excludePathPatterns = [".*\\.css",".*\\.gif",".*\\.ico",".*\\.jpg",".*\\.swf",".*\\.pdf"]
  • Solution(Workaround)
    Change the plugin's source code as follows in CompressGrailsPlugin.groovy and recompile or rebuild the application. Please check the exclamation mark carefully.
    line and source code
    55 // excludePathPatterns configuration
    56 'init-param' {
    57 'param-name'("excludePathPatterns")
    58 //changed the source code from line:59 to line:60
    59 //if (compress && !compress["excludePathPatterns"] && compress["excludePathPatterns"].isEmpty()) {
    60 if (compress && compress["excludePathPatterns"] && !compress["excludePathPatterns"].isEmpty()) {
    61 'param-value'(compress["excludePathPatterns"].join(","))
    62 } else {
    63 'param-value'(".*\\.gif, .*\\.ico, .*\\.jpg, .*\\.swf")
    64 }
    65 }

[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");
    }