javagoogle-app-engineservletsrestletcapedwarf

TaskQueue failing to do HTTP call - Missing mandatory headers?


Error is in this code:

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;
}

Error is "Couldn't find the mandatory "Host" HTTP header.":

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]

Code that triggered this is basic:

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

From what it seems the call coming from this queue is missing something, so Restlet is throwing out. The odd thing is, this same code works in GAE cloud (Appspot) and even on AppScale, it is only CapeDwarf that is throwing out this error. What could be wrong?


Solution

  • Here's a work-around I did:

    @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);
            }
    
        }
    

    But instead of getting less errors, it wreck havoc into Capedwarf runtime:

    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]
    

    Best solution I have is to run with the GAE SDK:

    ./dev_appserver.sh <path_to_app> 
    

    And it works perfect without issues, it seems Capedwarf missed to pass important stuff in the servlet chain.