jsfprettyfacesocpsoft-rewrite

Rewrite / PrettyFaces with parameter causes IllegalStateException: Cannot create a session after the response has been committed


I want to use some url rewriter with annotations in my JSF 2.2 application, so I've started to play around with Rewrite (PrettyFaces successor).

My application is still just an hello world running in TomEE 7.x, no fancy dependencies here, I guess. I run with no web.xml, empty faces-config.xml and empty beans.xml.

I've created a new dedicated backing bean and xhtml to test Rewrite, the problem is whenever I add a parameter in the Url, I get a IllegalStateException: Cannot create a session after the response has been committed

I've tried to downgrade to PrettyFaces 3.3.3 but exactly the same error occurs.

Here is the code of the Backing Bean

@Named
@javax.enterprise.context.RequestScoped
@URLMapping(id = "testroot", pattern = "/testRoot/#{testRootView.bar}", viewId = "xyz/TestRoot.jsf")
public class TestRootView implements Serializable {

    String foo = "my first String";

    String bar ="";

    // getters and setters ...
}

and the view

<?xml version="1.0" encoding="UTF-8"?>
<body jsf:id="root-body" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:jsf="http://xmlns.jcp.org/jsf">

<p>
This is my string : #{testRootView.foo}
</p>

<p>
And this is another string : #{testRootView.bar}
</p>

</body>

and the stack trace when I access http://localhost:8080/testRoot/aaa

java.lang.IllegalStateException: Cannot create a session after the response has been committed org.apache.catalina.connector.Request.doGetSession(Request.java:2952) org.apache.catalina.connector.Request.getSession(Request.java:2361) org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:896) javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) org.apache.myfaces.context.servlet.SessionMap.setAttribute(SessionMap.java:56) org.apache.myfaces.util.AbstractThreadSafeAttributeMap.put(AbstractThreadSafeAttributeMap.java:109) org.apache.myfaces.util.AbstractThreadSafeAttributeMap.put(AbstractThreadSafeAttributeMap.java:38) org.apache.myfaces.application.viewstate.ServerSideStateCacheImpl.saveSerializedViewInServletSession(ServerSideStateCacheImpl.java:250) org.apache.myfaces.application.viewstate.ServerSideStateCacheImpl.saveSerializedView(ServerSideStateCacheImpl.java:642) org.apache.myfaces.renderkit.html.HtmlResponseStateManager.saveState(HtmlResponseStateManager.java:138) org.apache.myfaces.application.StateManagerImpl.saveView(StateManagerImpl.java:279) org.apache.myfaces.shared.view.JspViewDeclarationLanguageBase.renderView(JspViewDeclarationLanguageBase.java:220) org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:313) com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.java:163) javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:58) javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:58) org.omnifaces.viewhandler.OmniViewHandler.renderView(OmniViewHandler.java:115) org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:116) org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:267) javax.faces.webapp.FacesServlet.service(FacesServlet.java:200) org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet.service(TomEEWorkaroundFacesServlet.java:47) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145) com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137)

Note that if I remove the parameter from the pattern (pattern = "/testRoot") and I access http://localhost:8080/testRoot there is no problem and the view is well rendered.

What am I doing wrong ? (I've given the version with prettyfaces, I can give the one with Rewrite's @Join too, but I think the problem is elsewhere as the error is the same...)


Solution

  • Thanks to chkal, I found the issue, it was indeed the lack of root ('/') in the viewId field (or the to field in the Rewrite version).

    Adding it solved this problem. I'm still wondering where my code were going to search for a session for that, and what it would have done if it had found one :)