5 Replies Latest reply on Sep 6, 2018 5:33 AM by kzivkovic

    Custom undertow filter unable to forward requst

    kzivkovic Newbie

      I configured custom filter in standalone.xml like this (bold lines):

       

      <subsystem xmlns="urn:jboss:domain:undertow:3.1">

        <buffer-cache name="default"/>

        <server name="default-server">

        <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>

        <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>

        <host name="default-host" alias="localhost">

        <location name="/" handler="welcome-content"/>

        <filter-ref name="server-header"/>

        <filter-ref name="x-powered-by-header"/>

        <filter-ref name="request-dumper"/>

        </host>

        </server>

        <servlet-container name="default">

        <jsp-config/>

        <websockets/>

        </servlet-container>

        <handlers>

        <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>

        </handlers>

        <filters>

        <response-header name="server-header" header-name="Server" header-value="WildFly/10"/>

        <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>

        <filter name="request-dumper" class-name="si.mycomp.requestDumpingHandler.DfsRequestDumpingHandler" module="si.telekom.requestDumpingHandler">

        <param name="timeLimit" value="0.1"/>

        </filter>

        </filters>

        </subsystem>

       

      In custom httphandler I want just to dump request to server.log and than forward request further like this:

      I created custom module for this.

       

      Here is excerpt from class:

       

      package si.mycomp.requestDumpingHandler;

       

      import java.io.BufferedReader;

      import java.io.IOException;

      import java.io.InputStream;

      import java.io.InputStreamReader;

      import java.nio.charset.StandardCharsets;

      import java.util.stream.Collectors;

       

      import io.undertow.UndertowLogger;

      import io.undertow.server.ExchangeCompletionListener;

      import io.undertow.server.HttpHandler;

      import io.undertow.server.HttpServerExchange;

       

      public class DfsRequestDumpingHandler implements HttpHandler {

       

          private static final UndertowLogger log = UndertowLogger.REQUEST_LOGGER;

       

          private HttpHandler next;

          private String param1;

       

          private String timeLimit;

          float responseTimeLimit;

       

          String requestStr;

       

          public DfsRequestDumpingHandler(HttpHandler next) {

              this.next = next;

          }

       

          @Override

          public void handleRequest(final HttpServerExchange exchange) throws Exception {

             

              //ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); 

          //HttpServletRequest request = (HttpServletRequest) context.getServletRequest(); 

         

              exchange.startBlocking();

              if (exchange.isInIoThread()) {

                  exchange.dispatch(this);

                  return;

              }

              InputStream inputStream = exchange.getInputStream();

              // inputStream.mark(2);

              final String reqString = toString(inputStream).trim();

              inputStream.mark(0);

       

              PostExchangeListener mylistener = new PostExchangeListener(reqString, exchange.getRequestStartTime());

              next.handleRequest(exchange);

          }

      ...

       

      I am getting this error if module is enabled, it seems there is problem inside: next.handleRequest(exchange); line - what could be wrong?

       

      12:28:01,195 SEVERE [com.sun.xml.ws.transport.http.HttpAdapter] (default task-1) Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog

      at [row,col {unknown-source}]: [1,0]: com.sun.xml.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog

      at [row,col {unknown-source}]: [1,0]

      at com.sun.xml.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:365)

      at com.sun.xml.ws.transport.http.HttpAdapter.decodePacket(HttpAdapter.java:277)

      at com.sun.xml.ws.transport.http.HttpAdapter.access$500(HttpAdapter.java:93)

      at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:457)

      at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)

      at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)

      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)

      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)

      at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

      at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

      at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)

      at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)

      at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)

      at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)

      at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

      at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

      at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

      at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

      at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

      at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

      at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)

      at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:197)

      at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:39)

      at io.undertow.server.handlers.HttpContinueReadHandler.handleRequest(HttpContinueReadHandler.java:65)

      at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:94)

      at org.wildfly.extension.undertow.Host$OptionsHandler.handleRequest(Host.java:295)

      at io.undertow.server.handlers.HttpContinueReadHandler.handleRequest(HttpContinueReadHandler.java:65)

      at si.mycomp.requestDumpingHandler.DfsRequestDumpingHandler.handleRequest(DfsRequestDumpingHandler.java:48)

      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)

      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)

      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

      at java.lang.Thread.run(Thread.java:748)

      Caused by: com.sun.xml.ws.streaming.XMLStreamReaderException: XML reader error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog

      at [row,col {unknown-source}]: [1,0]

      at com.sun.xml.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:267)

      at com.sun.xml.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:95)

      at com.sun.xml.ws.streaming.XMLStreamReaderUtil.nextContent(XMLStreamReaderUtil.java:110)

      at com.sun.xml.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:100)

      at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:175)

      at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:303)

      at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:129)

      at com.sun.xml.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:360)

      ... 52 more

      Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog

      at [row,col {unknown-source}]: [1,0]

      at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:661)

      at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2134)

      at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2040)

      at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)

      at com.sun.xml.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:92)

      at com.sun.xml.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:76)

      ... 58 more