aspose file tools*
The moose likes Struts and the fly likes IllegalStateException: Cannot create a session after the response has been committed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "IllegalStateException: Cannot create a session after the response has been committed" Watch "IllegalStateException: Cannot create a session after the response has been committed" New topic
Author

IllegalStateException: Cannot create a session after the response has been committed

Arne Andersen
Greenhorn

Joined: Oct 02, 2008
Posts: 8
After a recent upgrade of a system using spring and struts2 we have started to get IllegalStateExceptions on our production-servers (stacktrack at bottom). The errors are not frequent, we get about 1 a week on a system with about 1000 visitors a week. I'm having a real hard time debugging it, since I am not able to reproduce the errors locally or on our testservers. And there is no usefull information in the stacktrace as to where in the application the error has occured. We have a relativly simple front-end application and a more heavy backend-application.

At the moment, my best guess would be that it has something to do with the changes we did to our register-new-user form. This form is used by both users by themself, and by administrators to add users. To ease the task for the administrators we added a "Register new" button after the form has been submitted, and when this is clicked you should be directed back to the register-new-user form with 3 of the fields populated with the last value used.
This is our struts.xml relevant section:


This is the relevant "Register new button" at the page after submitting a new user:


We who built this are not struts2 experts, and would like to hear your opinions. Could this bit of code create the IllegalStateException shown below? Or should we look elsewhere?
Thanks in advance!

Stacktrace:
[2010-11-19 14:05:11,237, ERROR, , StandardWrapperValve.java:260] - Servlet.service() for servlet default threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2221)
at org.apache.catalina.connector.Request.getSession(Request.java:2031)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:832)
at no.nav.portal.filter.Decorator.doFilter(Decorator.java:50)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:773)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:895)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)
Brittney Berkenpas
Greenhorn

Joined: Mar 04, 2011
Posts: 2
Hi there, we're having a very similar issue with our struts2 web application, and IllegalStateExceptions on redirectActions. Were you ever able to come up with a solution for your problem?
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
What's this no.nav.portal.filter.Decorator class? I'm guessing that this class calls chain.doFilter before line 50 and that you have the struts2 filter configured to run after this filter. If thats the case then perhaps that class needs to be changed or moved to a later spot in the filter chain. Brittney, you may want to post your stack trace as well.
Brittney Berkenpas
Greenhorn

Joined: Mar 04, 2011
Posts: 2
My stack trace is as follows:
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:771)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.app.webapp.filter.CustomLayoutFilter.doFilter(AgentLayoutFilter.java:134)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:619)

The issue appears intermittently, and *could* be related to slightly higher concurrent users - though sometimes I am able to reproduce in a development enviro w/only a few others 'using' the site. I have been able to reproduce with each of our 'redirectAction' action results, as well as a redirect call that occurs in a jsp (I've since removed this call and moved every redirect to live inside the struts2 framework)

I also have a spring filter, and custom filter configured to run before my struts2 filter - which is setting a session and request attribute. Should I try changing my config such that the struts filter is applied first?

relevant web.xml entries:


Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
It looks likely to me that what is happening is that you are getting an exception in your JSP (I'm assuming you're using JSPs) after after the response header has already been sent to the client. The stack trace shows that the exception is occuring while struts2 is in the process of trying to give a message that indicates that an exception occured but it fails when it tries to update the response header to indicate that the request failed.

It could be tricky to figure out what the root issue is here if the problem only occurs intermittently or based on load. Have you checked your log files for errors that may be occuring just before this one? You might want to temporarily modify Dispatcher.sendError to write some more info to the log file when this occurrs. Particularly the stack trace of the exception that was passed into the method. This way you can see the initial error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateException: Cannot create a session after the response has been committed
 
Similar Threads
When Validation Error I Lose My Bean Value-Struts 2
Jsp file not compling
Losing hidden variable value during Struts 2 validation
getting selected fields from multiple select
Update Database with the newly entered value