title: Arbitrary HTTP 501 Not Implemented errors in Tomcat due to SOAP Envelope/Header mixup
body: <p>we're encountering strange "501 not implemented" errors on a machine (Ubunut 12.04.4 LTS) we've set up for test purposes. The server web application is running in a Tomcat 7.0.55 (tested with other 7.x version as well) and with Java 7 resp. Java 8 (20) (several versions tested). We're using Jax WS 2.2.8 on the server side. Requests can have very different sizes, complexities, etc.</p>
  
  <p>Approximately 1% of all SOAP requests (out of several thousands) end up with in the following error:</p>
  
  <pre><code>com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 501: Not Implemented
      at com.sun.xml.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:323)
      at com.sun.xml.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:272)
      at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:230)
      at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:143)
      at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:110)
      at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
      at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
      at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
      at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
      at com.sun.xml.ws.client.Stub.process(Stub.java:464)
      at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:174)
      at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
      at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:91)
      at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:154)
      at com.sun.proxy.$Proxy89.addToIndex(Unknown Source)
      at com.jv.pm.server.ReIndexService$IndexThread.run(ReIndexService.java:85)
      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:745)
  </code></pre>
  
  <p>On server side, Tomcat logs the following:</p>
  
  <pre><code>127.0.0.1 - - [17/Jul/2014:22:10:41 +0200] "/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1148
  127.0.0.1 - - [18/Jul/2014:09:41:59 +0200] "&gt;&lt;/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1164
  127.0.0.1 - - [18/Jul/2014:09:48:55 +0200] "dy&gt;&lt;/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1168
  127.0.0.1 - - [11/Aug/2014:14:16:41 +0200] "velope&gt;POST /application/methodname HTTP/1.1" 501 1138
  127.0.0.1 - - [11/Aug/2014:16:24:26 +0200] "velope&gt;POST /application/methodname HTTP/1.1" 501 1138
  127.0.0.1 - - [11/Aug/2014:16:25:00 +0200] "velope&gt;POST /application/methodname HTTP/1.1" 501 1138
  127.0.0.1 - - [11/Aug/2014:16:25:37 +0200] "velope&gt;POST /application/methodname HTTP/1.1" 501 1138
  127.0.0.1 - - [11/Aug/2014:16:25:53 +0200] "velope&gt;POST /application/methodname HTTP/1.1" 501 1138
  127.0.0.1 - - [11/Aug/2014:16:28:43 +0200] ":Envelope&gt;POST /application/methodname HTTP/1.1" 501 1144
  127.0.0.1 - - [12/Aug/2014:19:35:02 +0200] "S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1146
  127.0.0.1 - - [12/Aug/2014:19:35:20 +0200] "&gt;&lt;/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1164
  127.0.0.1 - - [12/Aug/2014:19:35:45 +0200] "dy&gt;&lt;/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1168
  127.0.0.1 - - [21/Aug/2014:16:51:16 +0200] "Envelope&gt;POST /application/methodname HTTP/1.1" 501 1142
  127.0.0.1 - - [21/Aug/2014:16:51:40 +0200] "/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1148
  127.0.0.1 - - [26/Aug/2014:17:35:29 +0200] "lope&gt;POST /application/methodname HTTP/1.1" 501 1134
  127.0.0.1 - - [03/Sep/2014:13:46:11 +0200] "pe&gt;POST /application/methodname HTTP/1.1" 501 1130
  127.0.0.1 - - [03/Sep/2014:13:46:12 +0200] "pe&gt;POST /application/methodname HTTP/1.1" 501 1130
  127.0.0.1 - - [03/Sep/2014:13:46:26 +0200] "ody&gt;&lt;/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1170
  127.0.0.1 - - [04/Sep/2014:13:56:49 +0200] "nvelope&gt;POST /application/methodname HTTP/1.1" 501 1140
  127.0.0.1 - - [04/Sep/2014:13:57:03 +0200] "pe&gt;POST /application/methodname HTTP/1.1" 501 1130
  127.0.0.1 - - [04/Sep/2014:13:57:28 +0200] "/S:Envelope&gt;POST /application/methodname HTTP/1.1" 501 1148
  </code></pre>
  
  <p>As you can see, somehow the body of the HTTP message seems to be mixed up with the header (?). Even more strange: It happens on arbitrary connections and data, so one and the same request (carrying exactly the same data) can end up in a HTTP 501 response and a second later in a HTTP 200 response. So for us it feels to be indeterministic and we can only reproduce it reliably if we send several hundred or more requests to the server - there will be a reliable (roughly) 1 % of 501 errors.</p>
  
  <p>We're facing the problem as well with a completely different web application which primarily deals with binary input data. So the problems seems to be completely independent from the running application or the structure of the SOAP requests.</p>
  
  <p>It may be important to notice that the requests are running over the local loopback interface (so the client sending the SOAP requets runs on the same machine). On client-side, different Java versions (7 and 8) have been tested as well. Stub creation happened with "wsimport" (in Java 7).</p>
  
  <p>We're somehow at our wits' end and we'd really appreciate if someone could lead us into the right direction to track this error down.</p>
  
  <p>Thanks and best regards</p>