在pax-web的jetty.xml中(pax-web 6.0.3,jetty 9.3.14),我定义了一个像这样的RewriteHandler:
<Get name="handler">
<Call name="addHandler">
<Arg>
<Ref id="Rewrite"/>
</Arg>
</Call>
</Get>
问题是每个URL都被重写好了,但我得到了404。 我认为ServletHandler在链中的Rewrite之前,但是“insertHandler”调用导致了这个错误:
org.apache.cxf.cxf-rt-transports-http - 3.1.11 | Error registering CXF OSGi servlet STARTED
java.lang.IllegalStateException: STARTED
at org.eclipse.jetty.server.handler.HandlerCollection.setHandlers(HandlerCollection.java:83) [166:org.eclipse.jetty.server:9.3.14.v20161028]
at org.eclipse.jetty.server.handler.HandlerCollection.addHandler(HandlerCollection.java:154) [166:org.eclipse.jetty.server:9.3.14.v20161028]
at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:168) [167:org.eclipse.jetty.servlet:9.3.14.v20161028]
at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:128) [167:org.eclipse.jetty.servlet:9.3.14.v20161028]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.<init>(HttpServiceContext.java:116) [179:org.ops4j.pax.web.pax-web-jetty:6.0.3]
at org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper.addContext(JettyServerWrapper.java:290) [179:org.ops4j.pax.web.pax-web-jetty:6.0.3]
at org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper.getOrCreateContext(JettyServerWrapper.java:209) [179:org.ops4j.pax.web.pax-web-jetty:6.0.3]
at org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper.getOrCreateContext(JettyServerWrapper.java:190) [179:org.ops4j.pax.web.pax-web-jetty:6.0.3]
at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl.addServlet(JettyServerImpl.java:324) [179:org.ops4j.pax.web.pax-web-jetty:6.0.3]
at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl$Started.addServlet(ServerControllerImpl.java:289) [179:org.ops4j.pax.web.pax-web-jetty:6.0.3]
at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl.addServlet(ServerControllerImpl.java:110) [179:org.ops4j.pax.web.pax-web-jetty:6.0.3]
at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerServlet(HttpServiceStarted.java:239) [180:org.ops4j.pax.web.pax-web-runtime:6.0.3]
at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerServlet(HttpServiceStarted.java:215) [180:org.ops4j.pax.web.pax-web-runtime:6.0.3]
at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerServlet(HttpServiceStarted.java:199) [180:org.ops4j.pax.web.pax-web-runtime:6.0.3]
at org.ops4j.pax.web.service.internal.HttpServiceProxy.registerServlet(HttpServiceProxy.java:65) [180:org.ops4j.pax.web.pax-web-runtime:6.0.3]
at org.apache.cxf.transport.http.osgi.ServletExporter.updated(ServletExporter.java:108) [58:org.apache.cxf.cxf-rt-transports-http:3.1.11]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189) [7:org.apache.felix.configadmin:1.8.14]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152) [7:org.apache.felix.configadmin:1.8.14]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85) [7:org.apache.felix.configadmin:1.8.14]
at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1463) [7:org.apache.felix.configadmin:1.8.14]
at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1419) [7:org.apache.felix.configadmin:1.8.14]
at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141) [7:org.apache.felix.configadmin:1.8.14]
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109) [7:org.apache.felix.configadmin:1.8.14]
at java.lang.Thread.run(Thread.java:745) [?:?]
如何让RewriteHandler工作?
答案 0 :(得分:0)
在启动Jetty服务器之前添加处理程序。
错误是因为一旦服务器启动,处理程序列表就是不可变的。