Problem with ConversationScoped / cid parameter

Splash Forums Rewrite Users Problem with ConversationScoped / cid parameter

This topic contains 10 replies, has 3 voices, and was last updated by  Lincoln Baxter III 2 years, 5 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #25768

    yesar
    Participant

    I have a problem getting rewrite working with my conversation scope.

    I have the following configuration

    
    ConfigurationBuilder.begin()
    .addRule(Join.path("/participate/test/{page}/{cid}").to("/__surveys/test/page{page}.xhtml"))
    .when(Resource.exists("/__surveys/test/page{page}.xhtml"))
    

    I start my conversation within a bean and return an url like this

    
    return participation.getViewId() + "?cid=" + participation.getConversation().getId();
    

    Now I get redirected to “participate/test/1/1” but my conversation is not active – but params map shows {cid=1, page=1, =}. If I open the url /__surveys/test/page1.xhtml?cid=1 directly, everything is working fine.

    Did I missed anything in my configuration?

    edit:
    I’m using Wildfly 8.0 Beta 1.

    Another independent question: is it possible to use an @EJB in my @RewriteConfiguration class?

    • This topic was modified 2 years, 6 months ago by  yesar.
    #25771

    Hmmm. I’m not sure what is going wrong here. Maybe Weld is trying to read the cid query parameter before Rewrite creates it. That could explain it. But unfortunately I’ve no idea how to work around that. I guess it would require some research in the Weld code to verify this.

    Regarding your other question. If you include rewrite-integration-cdi in you project, Rewrite will also automatically pick up CDI beans when looking for your ConfigurationProvider. So you could basically drop the RewriteConfiguration annotation and @EJB should work in this case.

    #25772

    yesar
    Participant

    I also tried

    
    .addRule()
    .when(Direction.isInbound().and(Path.matches("/participate/test/{page}/{cid}")))
    .perform(Forward.to("/__surveys/test/page{page}.xhtml?cid={cid}"))
    

    but with no luck. What can I do to help finding the issue?

    By the way: your suggestion with CDI bean (@Named) works, my EJB service got injected and configuration is accessed.

    edit:
    I updated my Wildfly to 8.0.0CR1 and now I can’t get my conversation loaded…
    I’ll have a deeper look into this and hopefully can find the problem

    • This reply was modified 2 years, 6 months ago by  yesar.
    • This reply was modified 2 years, 6 months ago by  yesar.
    #25774

    It is possible that the ‘cid’ parameter does not behave as other parameters. CDI’s ConversationFilter may actually be looking for a request parameter that does not exist due to the way you have your URLs mapped. This may be a filter ordering issue, or it may be an incompatibility. I’m not sure to be honest.

    #25776

    The problem is that you cannot modify the filter ordering because the ConversationFilter is added by the container. AFAIK.

    #25780

    yesar
    Participant

    I (with great support of Lincoln, thanks again!) found the problem here.
    You need to add the conversation filter mapping after rewrite filter mapping and specify the methods. web.xml should look like this:

    <listener>
    		<listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletRequestListener</listener-class>
    	</listener>
    	
    	<listener>
    		<listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletContextListener</listener-class>
    	</listener>
    	
    	<filter>
    		<filter-name>OCPsoft Rewrite Filter</filter-name>
    		<filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
    		<async-supported>true</async-supported>
    	</filter>
    	<filter-mapping>
    		<filter-name>OCPsoft Rewrite Filter</filter-name>
    		<url-pattern>/*</url-pattern>
    		<dispatcher>FORWARD</dispatcher>
    		<dispatcher>REQUEST</dispatcher>
    		<dispatcher>INCLUDE</dispatcher>
    		<dispatcher>ASYNC</dispatcher>
    		<dispatcher>ERROR</dispatcher>
    	</filter-mapping>
    
    	<filter-mapping>
    		<filter-name>CDI Conversation Filter</filter-name>
    		<url-pattern>/*</url-pattern>
    		<dispatcher>FORWARD</dispatcher>
    		<dispatcher>REQUEST</dispatcher>
    		<dispatcher>INCLUDE</dispatcher>
    		<dispatcher>ASYNC</dispatcher>
    		<dispatcher>ERROR</dispatcher>
    	</filter-mapping>
    

    This is now working with Wildfly 8.0.0CR1

    #25848

    yesar
    Participant

    After some work on my application I found a new “problem” with conversation.

    Normally you have an exception handling for your NonexistentConversationException, something like

    
    <error-page>
    	<exception-type>org.jboss.weld.context.NonexistentConversationException</exception-type>
    	<location>/errors/noconversation.xhtml?nocid=true</location>
    </error-page>
    

    But this exception will get caught in RewriteFilter

    
    try {
    	rewrite(event);
    }
    catch (ServletException e) {
    	throw e;
    }
    catch (Exception e) { // <-- here
    	throw new ServletException("Error during Rewrite processing. Please inspect stack trace for root cause.", e);
    }
    

    and wrapped in a ServletException. The result is that my exception handling config will not work and instead of my error page, I get the server error page with stack trace…

    My workaround is to have a filter configured before rewrite filter (in web.xml), with following code:

    
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    	try {
    		chain.doFilter(request, response);
    	} catch (ServletException se) {
    		Throwable t = ExceptionUtils.getRootCause(se); // ExceptionUtils from apache commons
    		if (t instanceof NonexistentConversationException) {
    			throw (NonexistentConversationException) t;
    		}
    		throw se;
    	}
    }
    

    Maybe you can adjust your code to pass the exception?
    Also if you have any ideas to better deal with this I’m up for suggestions.

    • This reply was modified 2 years, 5 months ago by  yesar.
    #25850

    Hey Yesar,

    You are absolutely correct. I’ll fix this right now. We should not be wrapping exceptions here. I’ll let you know when it’s ready.

    ~Lincoln

    #25851

    Could you please try with the latest 2.0.12-SNAPSHOT version and let me know if this resolves your issue? Instructions for using snapshot versions can be found here: http://ocpsoft.org/rewrite/#section-4

    Alternatively you could check out the sources and build it locally, if the snapshots are not an option for you.

    Thanks!
    ~Lincoln

    #25854

    yesar
    Participant

    I tested the snapshot put sadly NonexistentConversationException gets thrown (server error page with stacktrace) and not catched by jsf because it’s now wrapped in a RuntimeException…

    Here is the stacktrace:

    
    10:50:03,785 ERROR [io.undertow.request] (default task-4) UT005023: Exception handling request to /__surveys/test/start.xhtml: java.lang.RuntimeException: org.jboss.weld.context.NonexistentConversationException: WELD-000321: No conversation found to restore for id 1
    	at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:181) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41) [rewrite-servlet-2.0.12-SNAPSHOT.jar:2.0.12-SNAPSHOT]
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268) [rewrite-servlet-2.0.12-SNAPSHOT.jar:2.0.12-SNAPSHOT]
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188) [rewrite-servlet-2.0.12-SNAPSHOT.jar:2.0.12-SNAPSHOT]
    	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:56) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:70)
    	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:67) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:70) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:164) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:654) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
    	at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
    Caused by: org.jboss.weld.context.NonexistentConversationException: WELD-000321: No conversation found to restore for id 1
    	at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:238) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
    	at org.jboss.weld.servlet.ConversationContextActivator.activateConversationContext(ConversationContextActivator.java:100) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
    	at org.jboss.weld.servlet.ConversationContextActivator.startConversationContext(ConversationContextActivator.java:80) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
    	at org.jboss.weld.servlet.ConversationFilter.doFilter(ConversationFilter.java:68) [weld-core-impl-2.1.1.Final.jar:2013-12-03 09:59]
    	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:56) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205) [rewrite-servlet-2.0.12-SNAPSHOT.jar:2.0.12-SNAPSHOT]
    	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:56) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:229) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:172) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:158) [undertow-servlet-1.0.0.Beta30.jar:1.0.0.Beta30]
    	... 32 more
    
    • This reply was modified 2 years, 5 months ago by  yesar.
    #25859

    Hmm, could you perhaps upload a sample maven project that demonstrates this issue? I’d like to take a look.

    Thanks!

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

Comments are closed.