Exception occured "java.lang.IllegalStateException: Context is already active"

Splash Forums PrettyFaces Users Exception occured "java.lang.IllegalStateException: Context is already active"

This topic contains 16 replies, has 3 voices, and was last updated by  Christian Kaltepoth 5 years, 8 months ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #18019

    meirka
    Participant

    Hi, when i use prettyfaces with the next url:

    http://localhost:8080/WebApplication1/faces/testAdmin?testid=90

    in every version of glashfish,

    With the next pretty faces:

    <pretty-config xmlns=”http://ocpsoft.com/prettyfaces/3.1.0&#8243;

    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;

    xsi:schemaLocation=”http://ocpsoft.com/prettyfaces/3.1.0

    http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.1.0.xsd“>

    <!– Begin RewriteRules –>

    <!– Begin UrlMappings –>

    <url-mapping id=”viewCategory”>

    <pattern value=”/electAdmin” />

    <query-param name=”testid”> #{candidate_handler.testid} </query-param>

    <view-id>/faces/manager/electionBuild.xhtml</view-id>

    </url-mapping>

    </pretty-config>

    ______________________________________________________________________________

    This is the web.xml:

    <?xml version=”1.0″ encoding=”UTF-8″?>

    <web-app version=”3.0″ xmlns=”http://java.sun.com/xml/ns/javaee&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd“>

    <!–

    – Location of the XML file that defines the root application context

    – Applied by ContextLoaderListener.

    –>

    <context-param>

    <param-name>javax.faces.PROJECT_STAGE</param-name>

    <param-value>Development</param-value>

    </context-param>

    <servlet>

    <servlet-name>Faces Servlet</servlet-name>

    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

    <servlet-name>Faces Servlet</servlet-name>

    <url-pattern>/faces/*</url-pattern>

    </servlet-mapping>

    <session-config>

    <session-timeout>

    30

    </session-timeout>

    </session-config>

    <welcome-file-list>

    <welcome-file>faces/index.xhtml</welcome-file>

    </welcome-file-list>

    </web-app>

    ______________________________________________________________________________

    This exception occured:

    java.lang.IllegalStateException: Context is already active

    at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:311)

    at org.jboss.weld.jsf.WeldPhaseListener.activateConversations(WeldPhaseListener.java:110)

    at org.jboss.weld.jsf.WeldPhaseListener.beforePhase(WeldPhaseListener.java:84)

    at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)

    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)

    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)

    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)

    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:785)

    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)

    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483)

    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454)

    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350)

    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:785)

    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)

    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483)

    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454)

    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350)

    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300)

    at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)

    at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:364)

    at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)

    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)

    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)

    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)

    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)

    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)

    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)

    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)

    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)

    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)

    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)

    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)

    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)

    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

    at java.lang.Thread.run(Thread.java:662).

    Please help.

    #21302

    What version of PrettyFaces are you using?

    #21303

    I’m guessing there’s either a secondary exception happening somewhere else, or your bean is ConversationScoped, which is not really a good idea because of the way ConversationScope was implemented in CDI 1.0. I would try a RequestScoped bean.

    #21304

    meirka
    Participant

    Hi, it’s empty project.

    I am using version 3.3.0

    And the problem occur even when RequestScope.

    As you say – maybe one Exception is behind this, as you can see in the log:

    INFO: Exception when handling error trying to reset the response.

    java.lang.NullPointerException

    at com.sun.faces.context.flash.ELFlash.doLastPhaseActions(ELFlash.java:607)

    at com.sun.faces.context.ExternalContextImpl.responseFlushBuffer(ExternalContextImpl.java:857)

    at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:155)

    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)

    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)

    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)

    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)

    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)

    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)

    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)

    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)

    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)

    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)

    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)

    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)

    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

    at java.lang.Thread.run(Thread.java:662)

    WARNING: JSF1087: Unable to generate Facelets error page as the response has already been committed.

    SEVERE: javax.faces.FacesException

    javax.faces.FacesException

    at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:141)

    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)

    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)

    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)

    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)

    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)

    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)

    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)

    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)

    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)

    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)

    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)

    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)

    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

    at java.lang.Thread.run(Thread.java:662)

    Caused by: java.lang.NullPointerException

    at com.sun.faces.context.flash.ELFlash.doLastPhaseActions(ELFlash.java:607)

    at com.sun.faces.context.ExternalContextImpl.responseFlushBuffer(ExternalContextImpl.java:857)

    at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:155)

    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)

    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

    … 35 more

    #21305

    Which version of Mojarra are you using? This would help to identify the reason for the NullPointerException!

    #21306

    meirka
    Participant

    hi, i use Mojarra version 2.1.2

    #21307

    Do you have any other libraries in the project? This doesn’t look like a PrettyFaces issue. It looks like, in fact, an issue with JSP and JSF 2. Are you using JSP or Facelets? I believe that could be the cause.

    Could you also try upgrading to PF 3.3.1-SNAPSHOT and see if the problem is resolved?

    https://github.com/ocpsoft/prettyfaces/wiki/Snapshots

    #21308

    meirka
    Participant

    hi, it does not work with the version.

    #21309

    Hey there! I tested Mojarra 2.1.2 on Tomcat 7 and everything works fine.

    I also had a quick look at the Mojarra source. They are doing the following in ExternalContextImpl:

    @Override
    public void responseFlushBuffer() throws IOException {
    getELFlash().doLastPhaseActions(FacesContext.getCurrentInstance(), false);

    And in ELFlash:

    public void doLastPhaseActions(FacesContext context, boolean outgoingResponseIsRedirect) {
    ExternalContext extContext = context.getExternalContext();

    The access to context in doLastPhaseActions() seems to cause the NPE. This means that FacesContext.getCurrentInstance() returns null in ExternalContextImpl.

    Could you perhaps test the following: Add an URL action to your mapping like this:

    <url-mapping id="viewCategory">
    <pattern value="/electAdmin" />
    <action>#{testBean.testMethod}</action> <!-- LOOK HERE --->
    <query-param name="testid"> #{candidate_handler.testid} </query-param>
    <view-id>/faces/manager/electionBuild.xhtml</view-id>
    </url-mapping>

    And:

    public class TestBean {

    public void testMethod() {
    System.out.println("FacesContext ----> "+FacesContext.getCurrentInstance());
    }

    }

    I would be interested to see if the FacesContext is null even before RENDER_RESPONSE phase. I really think this is a Mojarra bug. I don’t think it is allowed that FacesContext.getCurrentInstance() returns null during RENDER_RESPONSE!

    #21310

    meirka
    Participant

    I am working with glashfish, not tomcat.

    #21311

    meirka
    Participant

    I will do later what you sugested and update wwith the results

    #21312

    Yeah, I know you are working on Glassfish, but I didn’t have a Glassfish installation around so I did a quick test with Tomcat.

    I’m looking forward to hear about your testing results.

    #21313

    meirka
    Participant

    i do not receive the new debug in my log.

    And the majorra is:

    INFO: Initializing Mojarra 2.1.3 (FCS b01) for context ‘/WebApplication1’

    Could it connect to the weld ?

    #21314

    My guess is that it is connected to Mojarra. Which of the two Exceptions (NullPointerException vs. “Context already active”) is the first one in the log file?

    BTW: I saw you posted the wrong URL in your first post. You wrote you are trying to access:

    http://localhost:8080/WebApplication1/faces/testAdmin?testid=90

    with this PrettyFaces mapping:

    <url-mapping id="viewCategory">
    <pattern value="/electAdmin" />
    <query-param name="testid"> #{candidate_handler.testid} </query-param>
    <view-id>/faces/manager/electionBuild.xhtml</view-id>
    </url-mapping>

    The correct URL to test this mapping is:

    http://localhost:8080/WebApplication1/electAdmin?testid=90

    Please note that you don’t have to add the /faces/ suffix when using PrettyFaces.

    You could also test if you are getting the same exception if don’t use the mapping at all and access the JSF view directly (bypassing PrettyFaces):

    http://localhost:8080/WebApplication1/faces/manager/electionBuild.xhtml

    But if you test this your query parameter won’t work, so you could hard code the ID somewhere in the code just to see if the page rendering works.

    #21315

    meirka
    Participant

    hi, full project work with the corect url.

    thanks

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic.

Comments are closed.