-2

I have a Grails 2.2.4 application running. The application does some image uploading tasks and shows the uploaded images in a list. Everything works fine, but sometime I get the error below. I googled after that but I could not find a proper answer. I cannot find the how the error belongs to my code.

Sometime when I load my page an the error occurs I only see a white page with a 2000 and a 0 written on the top left of the page. There is no error in the console.

enter image description here

What produces this error and how can I prevent it?

Sep 11, 2013 8:29:59 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [] threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:349)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:314)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:279)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:270)
    at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:222)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.obtainContent(GrailsPageFilter.java:206)
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:152)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    at org.codehaus.groovy.grails.plugins.springsecurity.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:40)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.codehaus.groovy.grails.plugins.springsecurity.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:66)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
10
  • 3
    You're trying to forward a request after the response has already been committed, either knowingly or because of the framework itself. Post the related code. Sep 11, 2013 at 18:47
  • The problem is I do not know what the related code is. What could cause this problem so I can post the code?
    – Michael
    Sep 11, 2013 at 18:49
  • 2
    Is this a Déjà vu or are you still stuck with the same old issue?
    – dmahapatro
    Sep 11, 2013 at 18:50
  • @dmahapatro I still stuck with this issue.
    – Michael
    Sep 11, 2013 at 18:50
  • I suppose you have also tried closing the outstream?
    – dmahapatro
    Sep 11, 2013 at 18:54

3 Answers 3

2

Put the below condition before render or redirect statement in Grails controller and see if it can resolve the issue.

if(!response.isCommited())
{
 // render or redirect
}

Check if the control goes to inside the condition and based on that debug it.

5
  • What should I do if the response is commited?
    – Michael
    Sep 14, 2013 at 21:48
  • Should I do that also for forward?
    – Michael
    Sep 14, 2013 at 22:05
  • @confile: Try it wherever you are forwarding/render/redirect and debug it to check if response is already commited.
    – TP_JAVA
    Sep 14, 2013 at 23:10
  • Can you check my code here if there is any error? stackoverflow.com/questions/18658021/…
    – Michael
    Sep 14, 2013 at 23:11
  • I did add comment to your question about exception when rendering in stackoverflow.com/questions/18658021/…
    – Ivar
    Sep 17, 2013 at 15:43
1
+100

I had a similar error caused by the Browser detection plugin.

When you use the plugin in controller methods there is no problem with the session.

I had problems with my session when I use the GSP tags of this plugin like:

<browser:isMobile>

Hope that helps.

0
0

Try to change generate scope in your code(your stackoverflow question) to this

 generate {
                def outputStream = response.outputStream
                try {
                response.setHeader("Content-Type", "application/octet-stream;")
                response.setHeader("Content-disposition", "attachment; filename=\"${imageName}${imageExtension}\"")
                outputStream << imageByteArray
                outputStream.flush()
                } catch (Exception exception){
                    log.debug('getImage() - Canceled download?', exception)
                    try {
                        outputStream.close()
                    } catch (Exception exception) {
                        log.debug('Exception on close', exception)
                    }
                }
            }
6
  • 2
    Can you please explain what you have changed?
    – Michael
    Sep 18, 2013 at 9:50
  • 1
    I changed... >1)IOException to Exception(I guess you have other exception). >2)response.setContentType("image/jpeg") to response.setHeader("Content-Type", "application/octet-stream;") >3)included last statement(response.setHeader(...)) in try block.
    – Karen
    Sep 18, 2013 at 22:36
  • Why do you use octet-stream if I only transfer jpeg images?
    – Michael
    Sep 18, 2013 at 22:49
  • If you transfer only jpeg you can ignore my second change(but it would work also). Did you get exception again?
    – Karen
    Sep 18, 2013 at 23:26
  • yes, many people say that outputStream.close() and outputStream.flush() is not needed. Why do you use it?
    – Michael
    Sep 19, 2013 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.