Rewrite filter called twice, firing f:viewAction twice

Splash Forums Rewrite Users Rewrite filter called twice, firing f:viewAction twice

This topic contains 8 replies, has 4 voices, and was last updated by  djmj 5 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #26300

    dobe
    Participant

    Hi, I have a problem that my rewrite filters are being called twice. I checked for other posts on this forum with similar problems, but no solution worked for me so far.

    I have the following setup:

    index.xhtml:

    <f:metadata>
      <f:viewAction action="#{sessionManager.handleViewParams()}" onPostback="false" />
    </f:metadata>

    Rewrite rules:

    ConfigurationBuilder.begin()
    .addRule(Join.path("/venue/{venueID}").to("/protected/index.xhtml"))
    .addRule(Join.path("/user/{userID}").to("/protected/index.xhtml"))
    ...
    .perform(Log.message(Level.INFO, "Rewrite is active!"));
    
    // also tried: 
    
    .addRule(Join.path("/venue/{venueID}").to("/protected/index.xhtml").withInboundCorrection())
    

    but makes no difference

    SessionManager.java:

    public void handleViewParams() {
            System.out.println("Handle view params, stack trace:");
            Thread.dumpStack();
    		HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    		Map<String, String[]> parameterMap = request.getParameterMap();
    		for (String name : parameterMap.keySet()) {
    		                String[] obj = parameterMap.get(name);
    		                String value = obj[0];
    		                switch (name) {
    		                    case "venueID":
    		                        changeNavToVenue(value);
    		                        break;
    		                    case "userID":
    		                        changeNavToUser(value);
    		                        break;
    								...
    							// changeNavTo...() are just functions to load the appropiate variables from the view parameters (venueID, userID, etc.)
    						}
    			}
    }

    Now if I navigate to a view, for example: /venue/1, then handleViewParams is called twice and page loading is significantly slower. The ouput from Thread.dumpStack() is the same for both calls, in the log I see twice:

    Info:   Rewrite is active!
    Info:   Handle view params, stack trace:
    Severe:   java.lang.Exception: Stack trace
    	at java.lang.Thread.dumpStack(Thread.java:1329)
    	at com.dobe.hobbyleague.backingbeans.SessionManagerBean.handleViewParams(SessionManagerBean.java:157)
    	at com.dobe.hobbyleague.backingbeans.SessionManagerBean$Proxy$_$$_WeldClientProxy.handleViewParams(Unknown Source)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:483)
    	at javax.el.ELUtil.invokeMethod(ELUtil.java:326)
    	at javax.el.BeanELResolver.invoke(BeanELResolver.java:536)
    	at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
    	at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
    	at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    	at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    	at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    	at javax.faces.component.UIViewAction.broadcast(UIViewAction.java:562)
    	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:873)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
    	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
    	at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
    	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    	at java.lang.Thread.run(Thread.java:745)

    Any ideas what is causing this and how I can fix it?

    #26302

    Is this part of an EAR? Do you have multiple copies of rewrite libraries in the application?

    #26303

    dobe
    Participant

    It’s from a WAR that I deploy to a GlassFish4 server. There is only one rewrite in my pom.xml and when I check the dependencies in NetBeans, rewrite-servlet-2.0.12.Final.jar is only listed once. I used to have a dependency for rewrite-integration-faces too, but I removed that after I read in another post that two dependencies might be causing the problem. Should I post my pom.xml or something like that?

    #26319

    dobe
    Participant

    I migrated to Wildfly8 in the meanwhile, but the same problem still remains. Anyone has any ideas what I could try to fix it?

    The new Wildfly8 stacktrace:

    java.lang.Exception: Stack trace
    16:08:49,374 ERROR [stderr] at java.lang.Thread.dumpStack(Thread.java:1364)
    16:08:49,375 ERROR [stderr] at com.dobe.hobbyleague.backingbeans.SessionManagerBean.handleViewParams(SessionManagerBean.java:149)
    16:08:49,375 ERROR [stderr] at com.dobe.hobbyleague.backingbeans.SessionManagerBean$Proxy$_$$_WeldClientProxy.handleViewParams(Unknown Source)
    16:08:49,375 ERROR [stderr] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    16:08:49,375 ERROR [stderr] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    16:08:49,375 ERROR [stderr] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    16:08:49,375 ERROR [stderr] at java.lang.reflect.Method.invoke(Method.java:606)
    16:08:49,375 ERROR [stderr] at javax.el.ELUtil.invokeMethod(ELUtil.java:308)
    16:08:49,375 ERROR [stderr] at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
    16:08:49,375 ERROR [stderr] at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
    16:08:49,376 ERROR [stderr] at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
    16:08:49,376 ERROR [stderr] at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    16:08:49,376 ERROR [stderr] at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    16:08:49,376 ERROR [stderr] at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    16:08:49,376 ERROR [stderr] at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    16:08:49,376 ERROR [stderr] at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    16:08:49,376 ERROR [stderr] at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    16:08:49,376 ERROR [stderr] at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    16:08:49,376 ERROR [stderr] at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    16:08:49,376 ERROR [stderr] at javax.faces.component.UIViewAction.broadcast(UIViewAction.java:562)
    16:08:49,377 ERROR [stderr] at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    16:08:49,377 ERROR [stderr] at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    16:08:49,377 ERROR [stderr] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    16:08:49,377 ERROR [stderr] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    16:08:49,377 ERROR [stderr] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    16:08:49,377 ERROR [stderr] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    16:08:49,377 ERROR [stderr] at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    16:08:49,377 ERROR [stderr] at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
    16:08:49,377 ERROR [stderr] at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    16:08:49,377 ERROR [stderr] at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
    16:08:49,378 ERROR [stderr] at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
    16:08:49,378 ERROR [stderr] at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
    16:08:49,378 ERROR [stderr] at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
    16:08:49,378 ERROR [stderr] at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
    16:08:49,378 ERROR [stderr] at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
    16:08:49,378 ERROR [stderr] at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
    16:08:49,378 ERROR [stderr] at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    16:08:49,378 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,378 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,378 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,379 ERROR [stderr] at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:229)
    16:08:49,379 ERROR [stderr] at io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:172)
    16:08:49,379 ERROR [stderr] at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:159)
    16:08:49,379 ERROR [stderr] at org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41)
    16:08:49,379 ERROR [stderr] at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268)
    16:08:49,379 ERROR [stderr] at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188)
    16:08:49,379 ERROR [stderr] at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
    16:08:49,379 ERROR [stderr] at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
    16:08:49,379 ERROR [stderr] at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
    16:08:49,380 ERROR [stderr] at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
    16:08:49,380 ERROR [stderr] at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    16:08:49,380 ERROR [stderr] at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    16:08:49,380 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,380 ERROR [stderr] at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
    16:08:49,380 ERROR [stderr] at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
    16:08:49,380 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,380 ERROR [stderr] at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
    16:08:49,380 ERROR [stderr] at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
    16:08:49,380 ERROR [stderr] at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
    16:08:49,381 ERROR [stderr] at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
    16:08:49,381 ERROR [stderr] at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
    16:08:49,381 ERROR [stderr] at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
    16:08:49,381 ERROR [stderr] at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
    16:08:49,381 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,381 ERROR [stderr] at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    16:08:49,381 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,381 ERROR [stderr] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    16:08:49,381 ERROR [stderr] at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
    16:08:49,381 ERROR [stderr] at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
    16:08:49,382 ERROR [stderr] at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
    16:08:49,382 ERROR [stderr] at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
    16:08:49,382 ERROR [stderr] at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
    16:08:49,382 ERROR [stderr] at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
    16:08:49,382 ERROR [stderr] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    16:08:49,382 ERROR [stderr] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    16:08:49,382 ERROR [stderr] at java.lang.Thread.run(Thread.java:744)

    #26322

    Sorry, it’s very difficult to tell what is causing this without having access to a working sample.

    Could you perhaps provide a minimal Maven sample app the reproduces this issue?

    #26323

    dobe
    Participant

    Thanks for your reply. I went ahead with your suggestion to create a sample app, but couldn’t reproduce the error, even though I was using all the same app and server configurations, package dependencies, etc.

    I found out what actually caused the error. The problem was not caused by Rewrite itself, but how I handle navigation in my code. The problem was that in my navigation handling code, from the view parameters, I would load the appropriate data from the database. For example, index.xhtml?user=1, in my navigation handler would get a parameter user, with value 1.

    Now to the error, on index.xhtml I have the following component:

    <p:graphicImage url=”#{selection.pictureURL}”/>

    When selection.pictureURL is empty or null, it will generate this html: , not sure why it puts ?pfrid_c in there, but it does. Before using Rewrite, this would make a get request for index.xhtml?pfrid_c, in my navigation handler, pfrid_c would not be recognised as a valid navigation rule and so just exit. With using Rewrite and the rules I have configured it with, it would make this request: /user/pfrid_c and then in my navigation handler, it would recoginse user as a valid navigation rule and try to load data for user with id pfrid_c from the database, …

    I should probably fix this in my navigation handler, but for the time being, this does the trick:

    <p:graphicImage url=”#{selection.pictureURL}” rendered=”#{not empty selection.pictureURL}”/>

    Thanks for your help in finding this bug!

    #26324

    Great to hear you found and fixed the problem. 😉

    #26325

    Great to hear you found and fixed the problem. 😉

    #27363

    djmj
    Participant

    This is a rewrite BUG.

    This problem occurs whenever a resource such as CSS or JS or an image could not be found and mojarra renders the RES_NOT_FOUND instead.

    I had a missing resource, since its url was wrong and wondered why my view-scoped bean @PostConstruct was called twice when i accessed the site via the rewritten URL.

    Resolving the RES_NOT_FOUND issue also solved the issue of the double bean instantiation.

    I am not sure if this is a regression in rewrite library. I just observed it with alpha 10 now.

    • This reply was modified 5 months ago by  djmj.
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

Comments are closed.