.addRule – java.lang.IllegalStateException:

Splash Forums Rewrite Users .addRule – java.lang.IllegalStateException:

This topic contains 7 replies, has 3 voices, and was last updated by  matteo.manili 1 year, 6 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #26794

    matteo.manili
    Participant

    spring version 3.2.13.RELEASE
    javax.servlet 3.0.1
    apache-tomcat-7.0.57
    org.ocpsoft.rewrite – rewrite-servlet 2.0.12.Final

    MyCode

    @Override
    public Configuration getConfiguration(ServletContext context) {	
    	return ConfigurationBuilder.begin() 
    			.addRule()
    			 .when(Direction.isInbound())
    			 .perform(new HttpOperation() {
    				
    				@Override
    				public void performHttp(HttpServletRewrite event, EvaluationContext context) {
    					if(event.getResponse().isCommitted()) {
    				         event.setFlow(ServletRewriteFlow.ABORT_REQUEST); 
    				      }
    					}
    				})
    			
    	         .addRule()
    	         .perform(Log.message(Level.INFO, "Rewrite is active."))//  message(Log.message(Level.INFO, "Rewrite is active."))) 
         
    	         .addRule(Join.path("/home").to("/pages/index.jsp").withInboundCorrection());
    };

    Error

    INFORMAZIONI: Server startup in 4487 ms
    gen 27, 2015 9:24:20 PM org.ocpsoft.rewrite.config.Log
    INFORMAZIONI: Rewrite is active.
    gen 27, 2015 9:24:20 PM org.apache.catalina.core.StandardWrapperValve invoke
    GRAVE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/DogSitter_7_0] threw exception
    java.lang.IllegalStateException: Cannot forward after response has been committed
    	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:348)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
    	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:241)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Unknown Source)

    thanks for help 🙂

    #26795

    Well, to avoid this exception, you should use the following:

    @Override
    public Configuration getConfiguration(ServletContext context) {	
    	return ConfigurationBuilder.begin() 
    			.addRule()
    			 .when(Direction.isInbound().and(new HttpCondition() {
                                 public boolean evaluate(HttpServletRewrite event, EvaluationContext context)
                                 {
                                     return event.getResponse().isCommitted();
                                 }
                             }))
    			 .perform(Lifecycle.handled())
    			
    	         .addRule()
    	         .perform(Log.message(Level.INFO, "Rewrite is active."))//  message(Log.message(Level.INFO, "Rewrite is active."))) 
         
    	         .addRule(Join.path("/home").to("/pages/index.jsp").withInboundCorrection());
    };

    But why is the response committed? It probably shouldn’t be. You should try to find what is committing the response prematurely.

    #26797

    What are you trying to accomplish?

    #26798

    matteo.manili
    Participant

    Resolve the error, and the conversion of the urls from /index.jsp to /home.
    The application works, but this error is still present.

    #26799

    matteo.manili
    Participant

    Also in this way, it has the same error.

    @Override
     public Configuration getConfiguration(ServletContext context) {	
         return ConfigurationBuilder.begin() 
         .addRule()
         .perform(Log.message(Level.INFO, "Rewrite is active."))//  message(Log.message(Level.INFO, "Rewrite is active.")))
     
         .addRule(Join.path("/homeIndex").to("/pages/index.jsp").withInboundCorrection());
    }
    gen 28, 2015 8:15:33 AM org.apache.catalina.core.StandardWrapperValve invoke
    GRAVE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/DogSitter_7_0] threw exception
    java.lang.IllegalStateException: Cannot forward after response has been committed
    	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:348)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
    	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:241)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Unknown Source)
    • This reply was modified 1 year, 6 months ago by  matteo.manili.
    #26801

    This basically means that somebody has written to the response stream BEFORE Rewrite intercepts and forwards the request. Changing filter ordering may help here.

    #26802

    Any other filters in your app?

    You could add a Thread.dumpStack() do the operation you had in your first example and post the results.

    #26803

    matteo.manili
    Participant

    I solved the problem.
    I uninstalled and installed tomcat. I think the jar were in conflict.
    thank you 🙂

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

You must be logged in to reply to this topic.

Comments are closed.