title: SocketTimeoutException when JBoss routes request to tomcat both running locally
body: <p>I have two applications running <em>locally</em>, one is a JBoss and the other is running on tomcat. Jboss application is legacy one and I have made code changes in it to route the traffic to tomcat server. I want to test this code change locally first before it is deployed on our QA boxes. If the request is of certain type JBoss application builds <code>HttpClient</code> and makes a POST call with appropriate request, header etc to the tomcat application, I print this already so there is no issue here. Now in my tomcat application's console log,  I only see below <code>SocketTimeoutException</code> error, so the request is dying somewhere immediately. I'm lost here and don't know how to debug this further</p>
  
  <p>Things I have tried
  1. I have restarted applications multiple times
  2. Increased Socket timeouts and connection timeouts etc
  3. Started JBoss app in debug mode and made sure that before the actual routing to tomcat happens, request, header, http client config etc.</p>
  
  <pre><code>2016-05-06 14:36:53,920 ERROR [http-nio-8080-exec-2]  - 87d141f302e74 - ygpdY8VQsu - 
  util.ExceptionHandler - INTERNAL_SERVICE_ERROR_java.net.SocketTimeoutException_org.apache.tomcat.util.net.NioBlockingSelector_read_202
      java.net.SocketTimeoutException
          at org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:202)
          at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:251)
          at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:232)
          at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:133)
          at org.apache.coyote.http11.InternalNioInputBuffer$SocketInputBuffer.doRead(InternalNioInputBuffer.java:177)
          at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:110)
          at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:416)
          at org.apache.coyote.Request.doRead(Request.java:460)
          at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:338)
          at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:395)
          at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:363)
          at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:190)
          at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:505)
          at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:129)
          at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:226)
          at com.fasterxml.jackson.core.JsonFactory._createJsonParser(JsonFactory.java:1191)
          at com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1182)
          at com.fasterxml.jackson.core.JsonFactory.createJsonParser(JsonFactory.java:831)
          at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:671)
          at com.fasterxml.jackson.jaxrs.base.ProviderBase._createParser(ProviderBase.java:575)
          at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.readFrom(ResteasyJackson2Provider.java:111)
          at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:59)
          at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.readFrom(ServerReaderInterceptorContext.java:62)
          at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:51)
  </code></pre>
  
  <h2>Edit 1</h2>
  
  <p>After further debugging, I found that the error is happening in tomcat server's read interceptor at <code>context.proceed();</code> line</p>
  
  <pre><code>public class DecoratedReaderInterceptor implements ReaderInterceptor {
  
      @Override
      public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
  
          boolean validate = shouldValidateResource(context);
          Object obj =  context.proceed();
          if (obj instanceof Resource) {
              processResource((Resource) obj, validate);
          } else if (obj instanceof Resource[]) {
              for (Resource resource : (Resource[]) obj) {
                  processResource(resource, validate);
              }
          }
          return obj;
      }
  }
  </code></pre>
  
  <h2>Edit 2</h2>
  
  <p>Found the answer and I'm embarrassed. In JBoss server there was a debug statement I added to read the stream to output the request, now the stream was already read, tomcat server did not have anything to consume. Hence the <code>SocketTimeoutException</code></p>