3

错误在此代码中:

public String getVersion() {
    String result = null;
    int index = this.getRequest().getProtocol().indexOf(47);
    if (index != -1) {
        result = this.getRequest().getProtocol().substring(index + 1);
    }

    return result;
}

错误是“找不到强制性的“主机”HTTP 标头。”:

10:34:29,889 INFO  [org.restlet] (Thread-6 (HornetQ-client-global-threads-1773619305)) Couldn't find the mandatory "Host" HTTP header.
10:34:29,910 WARNING [org.restlet.Component.Server] (Thread-6 (HornetQ-client-global-threads-1773619305)) Error while handling an HTTP server call: java.lang.NullPointerException
    at org.restlet.ext.servlet.internal.ServletCall.getVersion(ServletCall.java:370) [org.restlet.ext.servlet-2.4.0.jar:]
    at org.restlet.engine.adapter.ServerAdapter.toRequest(ServerAdapter.java:229) [org.restlet-2.4.0.jar:]
    at org.restlet.ext.servlet.internal.ServletServerAdapter.toRequest(ServletServerAdapter.java:62) [org.restlet.ext.servlet-2.4.0.jar:]
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:141) [org.restlet-2.4.0.jar:]
    at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1117) [org.restlet.ext.servlet-2.4.0.jar:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

触发此事件的代码是基本的:

Queue queue = QueueFactory.getQueue(milkID + "-queue");
String taskUrl = "/milks/" + milkID;
queue.add(TaskOptions.Builder.withUrl(taskUrl)
    .param("param1", param1));

从这个队列来的调用看起来缺少一些东西,所以 Restlet 被扔掉了。奇怪的是,同样的代码在 GAE 云 (Appspot) 甚至在 AppScale 上也有效,只有 CapeDwarf 抛出了这个错误。有什么问题?

4

1 回答 1

0

这是我做的一个解决方法:

@Override
public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        String host = req.getHeader("Host");
        String _protocol = req.getProtocol(); // e.g. HTTP/1.1
        if(host == null || host.isEmpty() || _protocol == null || _protocol.isEmpty()) {
            host = "127.0.0.1:8080";
            HeaderMapRequestWrapper requestWrapper = new HeaderMapRequestWrapper(req, "HTTP/1.1");
            requestWrapper.addHeader("Host", host);
            System.out.println("====================================================");
            System.out.println("Updating Host: " + host);
            System.out.println("====================================================");
            chain.doFilter(requestWrapper, response); 
        } else {
            chain.doFilter(req, response);
        }

    }

但它不但没有减少错误,反而严重破坏了 Capedwarf 运行时:

00:52:14,692 INFO  [org.hornetq.ra] (ServerService Thread Pool -- 62) HQ151003: HornetQ resource adaptor stopped
00:52:14,663 ERROR [io.undertow.request] (Thread-0 (HornetQ-client-global-threads-710971154)) UT005023: Exception handling request to null: javax.servlet.ServletException: UT010051: Deployment ROOT.war has stopped
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:55) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at com.mycompany.HostFilter.doFilter(HostFilter.java:48) [classes:]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at org.jboss.capedwarf.appidentity.GAEFilter.doFilter(GAEFilter.java:62) [capedwarf-appidentity-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:248) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchMockRequest(ServletInitialHandler.java:235) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.spec.RequestDispatcherImpl.mock(RequestDispatcherImpl.java:425) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at org.jboss.as.capedwarf.services.Hack.invoke(Hack.java:50)
    at org.jboss.as.capedwarf.services.ServletExecutor.dispatch(ServletExecutor.java:82)
    at org.jboss.as.capedwarf.services.ServletExecutorConsumer.onMessage(ServletExecutorConsumer.java:126)
    at org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:103)
    at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:1116)
    at org.hornetq.core.client.impl.ClientConsumerImpl.access$500(ClientConsumerImpl.java:56)
    at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1251)
    at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:104)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_163]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_163]
    at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_163]

我拥有的最佳解决方案是使用 GAE SDK 运行:

./dev_appserver.sh <path_to_app> 

它运行完美,没有问题,Capedwarf 似乎错过了在 servlet 链中传递重要的东西。

于 2018-04-03T17:35:32.880 回答