通过 Togglz 管理控制台编辑功能时出现错误 404

Error 404 when editing feature thru Togglz Admin Console

我在带有 Spring 4.0.5.RELEASE 和 Jetty 9.2.1.v20140609.

的 Web 应用程序中使用 Togglz 2.0.1.Final

当我尝试使用 Togglz 管理控制台编辑功能时,POST 请求收到 404 状态代码。

请求Headers

POST /my-app/togglz/edit HTTP/1.1
Host: my-host
Connection: keep-alive
Content-Length: 78
Pragma: no-cache
Cache-Control: no-cache
Authorization: Basic *****
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://my-host
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://my-host/my-app/togglz/edit?f=MY_FEATURE_TOGGLE
Accept-Encoding: gzip, deflate
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4

请求表单数据

f=MY_FEATURE_TOGGLE&enabled=enabled&strategy=&p1=&p2=&p3=&p4=&p5=&p6=&p7=&p8=

回复Headers

HTTP/1.1 404 Not Found
Server: nginx
Date: Wed, 20 May 2015 18:24:12 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Content-Encoding: gzip

在server-side中抛出以下异常:

javax.ws.rs.NotFoundException: Could not find resource for full path: http://my-host/my-app/
        at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:112) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.core.registry.RootNode.match(RootNode.java:43) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.8.Final.jar:na]
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.8.Final.jar:na]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [servlet-api-3.1.jar:3.1.0]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751) [jetty-servlet-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:566) [jetty-servlet-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:596) [jetty-security-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498) [jetty-servlet-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:191) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.Dispatcher.error(Dispatcher.java:77) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ErrorHandler.handle(ErrorHandler.java:91) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.Response.sendError(Response.java:589) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.Response.sendError(Response.java:547) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:626) [jetty-servlet-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:554) [jetty-security-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498) [jetty-servlet-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.Server.handle(Server.java:461) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244) [jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:534) [jetty-io-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607) [jetty-util-9.2.1.v20140609.jar:9.2.1.v20140609]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:536) [jetty-util-9.2.1.v20140609.jar:9.2.1.v20140609]
        at java.lang.Thread.run(Thread.java:745) [na:1.7.0_60]

请注意,异常会抱怨地址 (http://my-host/my-app/) different from the called one (http://my-host/my-app/togglz/edit),就好像重定向或转发已到位。

分析 Togglz 源代码,特别是 EditPageHandler class,当 POST 成功时确实有一个 sendRedirect() 调用,但它应该以返回 302 状态代码并重定向到 /togglz/index URI.

我无法找到 404 可能发生的位置,而且我无法调试它,因为该问题只发生在生产环境中(在开发环境中它很好,而且我已经检查 Jetty 版本,它们是相同的)。

有人知道这件事吗?

提前致谢。

经过一番努力,我找到了问题的原因!

Togglz 无法写入功能所在的 .properties 文件(缺少权限)。

现在,不要问我为什么 FeatureConsoleServlet 没有记录原始异常以及为什么它会导致转发到根 URI。 (如果有人对此有答案,请随时编辑此答案)。