title: Unable to send a multipart/mixed request to spring MVC based REST service
body: <p>I have a Spring MVC and Resteasy based REST service that i need to test by sending a multipart/mixed request. </p>
  
  <p>The service is coded as follows: </p>
  
  <pre><code>@POST
      @Path("/mixedMimeText")
      @Consumes("multipart/mixed")
      @ResponseStatus(HttpStatus.OK)
      public String createMime(@Context ServletContext servletContext, MultipartInput input) throws Exception, IOException {
  
          logger.info("Processing /mixedMimeText");
  
          for(InputPart p : input.getParts()){
              logger.info("Headers : " + p.getHeaders());
              logger.info("MediaType : " + p.getMediaType());
              logger.info("Body : " +  p.getBodyAsString());
              logger.info("--------------------------------------------------- ");
          }
  
          return "TEST";
      }
  </code></pre>
  
  <p>I am using the following file to send as the multipart mime content</p>
  
  <pre><code>--ABC123Boundary
  Content-Type: text/xml
  
  &lt;?xml version="1.0" ?&gt;
  &lt;request&gt;
  &lt;account-id&gt;XXXX-XXXX-XXXX-XXXX&lt;/account-id&gt;
  &lt;reference&gt;12345&lt;/reference&gt;
  &lt;app-name&gt;XXXXXXXXX&lt;/app-name&gt;
  &lt;information&gt;
  &lt;calling-party&gt;
  &lt;name&gt;Joe Bloggs&lt;/name&gt;
  &lt;identifier&gt;441234567890&lt;/identifier&gt;
  &lt;/calling-party&gt;
  &lt;called-party&gt;
  &lt;name&gt;John Smith&lt;/name&gt;
  &lt;identifier&gt;15551234567&lt;/identifier&gt;
  &lt;/called-party&gt;
  &lt;/information&gt;
  &lt;/request&gt;
  
  --ABC123Boundary
  Content-Type: text/xml
  
  UklGRkBAAABXQVZFZm10IBAAAAAHAAEAQB8AAEAfAAABAAgAZmFjdAQAAAAPQ
  AAAZGF0YRBAAABn5///////////////5///Z+fn///n////////5////////2f//2f//+f//+f////n/
  ///////52f//////2f//////2f/////5////////+f/////Z+f///////////////9n//9nZ/9n////5+f///9
  &lt;snip&gt;
  //+f//////2f/////////5//n//////////9n
  
  --ABC123Boundary--
  </code></pre>
  
  <p>I am sending the request using the curl client with the following command:</p>
  
  <pre><code>curl -X POST http://localhost:8080/MyRestServices/restportal/services/mixedMimeText -i -H "Content-Type: multipart/mixed; boundary="--ABC123Boundary" -T myfile.txt
  </code></pre>
  
  <p>The request does get to the service but all i see on the JBOSS terminal is that it produces the following error which does not really make sense. There is no stack trace or any other errors. </p>
  
  <pre><code>21:48:37,174 WARN  [org.apache.james.mime4j.parser.MimeEntity] (http--127.0.0.1-8080-1) Unexpected end of headers detected. Higher level boundary detected or EOF reached.
  21:48:37,175 WARN  [org.apache.james.mime4j.parser.MimeEntity] (http--127.0.0.1-8080-1) Invalid header encountered
  21:48:37,176 WARN  [org.apache.james.mime4j.parser.MimeEntity] (http--127.0.0.1-8080-1) Body part ended prematurely. Boundary detected in header or EOF reached.
  </code></pre>
  
  <p>It sounds like there is something wrong with the content but i am not quite sure. </p>
  
  <h2>Edit</h2>
  
  <p>@Perception - i changed the command as follows but it still produces that same error</p>
  
  <pre><code>curl http://localhost:8080/MyRestServices/restportal/services/mixedMimeText --data-binary @myfile.txt -X POST -i -H "Content-Type: multipart/mixed; boundary=--ABC123Boundary"
  </code></pre>
  
  <p>I wonder if the MultipartInput structure expects the content to be in a different format. </p>
  
  <h2>Edit</h2>
  
  <p>It looks like the data being sent is correct. Here is the output when i run the command using the --trace option</p>
  
  <pre><code>curl http://localhost:8080/MyRestServices/restportal/services/mixedMimeText --data-binary @myfile.txt -X POST -i -H "Content-Type: multipart/mixed; boundary=--ABC123Boundary" --trace trace.txt
  </code></pre>
  
  <p>Trace output</p>
  
  <pre><code>== Info: About to connect() to localhost port 8080 (#0)
  == Info:   Trying 127.0.0.1...
  == Info: connected
  == Info: Connected to localhost (127.0.0.1) port 8080 (#0)
  =&gt; Send header, 243 bytes (0xf3)
  0000: 50 4f 53 54 20 2f 4d 73 6d 52 65 73 74 53 65 72 POST /MyRestSer
  0010: 76 69 63 65 73 2f 72 65 73 74 2f 73 65 72 76 69 vices/rest/servi
  0020: 63 65 73 2f 6d 69 78 65 64 4d 69 6d 65 54 65 78 ces/mixedMimeTex
  0030: 74 20 48 54 54 50 2f 31 2e 31 0d 0a 55 73 65 72 t HTTP/1.1..User
  0040: 2d 41 67 65 6e 74 3a 20 63 75 72 6c 2f 37 2e 32 -Agent: curl/7.2
  0050: 34 2e 30 20 28 69 33 38 36 2d 70 63 2d 77 69 6e 4.0 (i386-pc-win
  0060: 33 32 29 20 6c 69 62 63 75 72 6c 2f 37 2e 32 34 32) libcurl/7.24
  0070: 2e 30 20 7a 6c 69 62 2f 31 2e 32 2e 35 0d 0a 48 .0 zlib/1.2.5..H
  0080: 6f 73 74 3a 20 6c 6f 63 61 6c 68 6f 73 74 3a 38 ost: localhost:8
  0090: 30 38 30 0d 0a 41 63 63 65 70 74 3a 20 2a 2f 2a 080..Accept: */*
  00a0: 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 ..Content-Type: 
  00b0: 6d 75 6c 74 69 70 61 72 74 2f 6d 69 78 65 64 3b multipart/mixed;
  00c0: 20 62 6f 75 6e 64 61 72 79 3d 2d 2d 41 42 43 31  boundary=--ABC1
  00d0: 32 33 42 6f 75 6e 64 61 72 79 0d 0a 43 6f 6e 74 23Boundary..Cont
  00e0: 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 37 37 31 0d ent-Length: 771.
  00f0: 0a 0d 0a                                        ...
  =&gt; Send data, 771 bytes (0x303)
  0000: 2d 2d 41 42 43 31 32 33 42 6f 75 6e 64 61 72 79 --ABC123Boundary
  0010: 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 ..Content-Type: 
  0020: 74 65 78 74 2f 78 6d 6c 0d 0a 0d 0a 3c 3f 78 6d text/xml....&lt;?xm
  0030: 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 l version="1.0" 
  0040: 3f 3e 0d 0a 3c 72 65 71 75 65 73 74 3e 0d 0a 3c ?&gt;..&lt;request&gt;..&lt;
  0050: 61 63 63 6f 75 6e 74 2d 69 64 3e 58 58 58 58 2d account-id&gt;XXXX-
  0060: 58 58 58 58 2d 58 58 58 58 2d 58 58 58 58 3c 2f XXXX-XXXX-XXXX&lt;/
  0070: 61 63 63 6f 75 6e 74 2d 69 64 3e 0d 0a 3c 72 65 account-id&gt;..&lt;re
  0080: 66 65 72 65 6e 63 65 3e 31 32 33 34 35 3c 2f 72 ference&gt;12345&lt;/r
  0090: 65 66 65 72 65 6e 63 65 3e 0d 0a 3c 61 70 70 2d eference&gt;..&lt;app-
  00a0: 6e 61 6d 65 3e 58 58 58 58 58 58 58 58 58 3c 2f name&gt;XXXXXXXXX&lt;/
  00b0: 61 70 70 2d 6e 61 6d 65 3e 0d 0a 3c 69 6e 66 6f app-name&gt;..&lt;info
  00c0: 72 6d 61 74 69 6f 6e 3e 0d 0a 3c 63 61 6c 6c 69 rmation&gt;..&lt;calli
  00d0: 6e 67 2d 70 61 72 74 79 3e 0d 0a 3c 6e 61 6d 65 ng-party&gt;..&lt;name
  00e0: 3e 4a 6f 65 20 42 6c 6f 67 67 73 3c 2f 6e 61 6d &gt;Joe Bloggs&lt;/nam
  00f0: 65 3e 0d 0a 3c 69 64 65 6e 74 69 66 69 65 72 3e e&gt;..&lt;identifier&gt;
  0100: 34 34 31 32 33 34 35 36 37 38 39 30 3c 2f 69 64 441234567890&lt;/id
  0110: 65 6e 74 69 66 69 65 72 3e 0d 0a 3c 2f 63 61 6c entifier&gt;..&lt;/cal
  0120: 6c 69 6e 67 2d 70 61 72 74 79 3e 0d 0a 3c 63 61 ling-party&gt;..&lt;ca
  0130: 6c 6c 65 64 2d 70 61 72 74 79 3e 0d 0a 3c 6e 61 lled-party&gt;..&lt;na
  0140: 6d 65 3e 4a 6f 68 6e 20 53 6d 69 74 68 3c 2f 6e me&gt;John Smith&lt;/n
  0150: 61 6d 65 3e 0d 0a 3c 69 64 65 6e 74 69 66 69 65 ame&gt;..&lt;identifie
  0160: 72 3e 31 35 35 35 31 32 33 34 35 36 37 3c 2f 69 r&gt;15551234567&lt;/i
  0170: 64 65 6e 74 69 66 69 65 72 3e 0d 0a 3c 2f 63 61 dentifier&gt;..&lt;/ca
  0180: 6c 6c 65 64 2d 70 61 72 74 79 3e 0d 0a 3c 2f 69 lled-party&gt;..&lt;/i
  0190: 6e 66 6f 72 6d 61 74 69 6f 6e 3e 0d 0a 3c 2f 72 nformation&gt;..&lt;/r
  01a0: 65 71 75 65 73 74 3e 0d 0a 0d 0a 2d 2d 41 42 43 equest&gt;....--ABC
  01b0: 31 32 33 42 6f 75 6e 64 61 72 79 0d 0a 43 6f 6e 123Boundary..Con
  01c0: 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f tent-Type: text/
  01d0: 78 6d 6c 0d 0a 0d 0a 55 6b 6c 47 52 6b 42 41 41 xml....UklGRkBAA
  01e0: 41 42 58 51 56 5a 46 5a 6d 31 30 49 42 41 41 41 ABXQVZFZm10IBAAA
  01f0: 41 41 48 41 41 45 41 51 42 38 41 41 45 41 66 41 AAHAAEAQB8AAEAfA
  0200: 41 41 42 41 41 67 41 5a 6d 46 6a 64 41 51 41 41 AABAAgAZmFjdAQAA
  0210: 41 41 50 51 0d 0a 41 41 41 5a 47 46 30 59 52 42 AAPQ..AAAZGF0YRB
  0220: 41 41 41 42 6e 35 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f AAABn5//////////
  0230: 2f 2f 2f 2f 2f 35 2f 2f 2f 5a 2b 66 6e 2f 2f 2f /////5///Z+fn///
  0240: 6e 2f 2f 2f 2f 2f 2f 2f 2f 35 2f 2f 2f 2f 2f 2f n////////5//////
  0250: 2f 2f 32 66 2f 2f 32 66 2f 2f 2b 66 2f 2f 2b 66 //2f//2f//+f//+f
  0260: 2f 2f 2f 2f 6e 2f 0d 0a 2f 2f 2f 2f 2f 2f 2f 35 ////n/..///////5
  0270: 32 66 2f 2f 2f 2f 2f 2f 32 66 2f 2f 2f 2f 2f 2f 2f//////2f//////
  0280: 32 66 2f 2f 2f 2f 2f 35 2f 2f 2f 2f 2f 2f 2f 2f 2f/////5////////
  0290: 2b 66 2f 2f 2f 2f 2f 5a 2b 66 2f 2f 2f 2f 2f 2f +f/////Z+f//////
  02a0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 39 6e 2f 2f 39 6e 5a /////////9n//9nZ
  02b0: 2f 39 6e 2f 2f 2f 2f 35 2b 66 2f 2f 2f 39 0d 0a /9n////5+f///9..
  02c0: 3c 73 6e 69 70 3e 0d 0a 2f 2f 2b 66 2f 2f 2f 2f &lt;snip&gt;..//+f////
  02d0: 2f 2f 32 66 2f 2f 2f 2f 2f 2f 2f 2f 2f 35 2f 2f //2f/////////5//
  02e0: 6e 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 39 6e 0d 0a 0d n//////////9n...
  02f0: 0a 2d 2d 41 42 43 31 32 33 42 6f 75 6e 64 61 72 .--ABC123Boundar
  0300: 79 2d 2d                                        y--
  == Info: upload completely sent off: 771 out of 771 bytes
  &lt;= Recv header, 17 bytes (0x11)
  0000: 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK.
  0010: 0a                                              .
  &lt;= Recv header, 27 bytes (0x1b)
  0000: 53 65 72 76 65 72 3a 20 41 70 61 63 68 65 2d 43 Server: Apache-C
  0010: 6f 79 6f 74 65 2f 31 2e 31 0d 0a                oyote/1.1..
  &lt;= Recv header, 19 bytes (0x13)
  0000: 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 2a 2f Content-Type: */
  0010: 2a 0d 0a                                        *..
  &lt;= Recv header, 19 bytes (0x13)
  0000: 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 Content-Length: 
  0010: 34 0d 0a                                        4..
  &lt;= Recv header, 37 bytes (0x25)
  0000: 44 61 74 65 3a 20 53 61 74 2c 20 31 38 20 46 65 Date: Sat, 18 Fe
  0010: 62 20 32 30 31 32 20 32 32 3a 34 33 3a 35 33 20 b 2012 22:43:53 
  0020: 47 4d 54 0d 0a                                  GMT..
  &lt;= Recv header, 2 bytes (0x2)
  0000: 0d 0a                                           ..
  &lt;= Recv data, 4 bytes (0x4)
  0000: 54 45 53 54                                     TEST
  == Info: Connection #0 to host localhost left intact
  == Info: Closing connection #0
  </code></pre>