title: SOAPUI - REST request multipart/mixed - how to add attachment
body: <p>I am trying to test RESTful service which is configured to consume multipart/mixed using soapui tool.  </p>
  
  <pre><code>@POST
  @Path("requestXmlAndAttachment")
  @Consumes({ "multipart/mixed" })
  @Produces({ MediaType.APPLICATION_XML })
  public ResponseTO processRequestXmlAndAttachment(final       com.sun.jersey.multipart.MultiPart     multiPartRequest) {
   // application logic
  </code></pre>
  
  <p>}</p>
  
  <p>Within SOAPUI, I have setup REST resourse and added 2 parameters, first file pointing to request xml and second file with data (I selected style PLAIN from dropdown).</p>
  
  <pre><code>File1       file:request.xml
  File2       file:datafile.xls
  </code></pre>
  
  <p>On SOAPUI request editor window I have selected multipart/mixed for media type.  When I submit request to the server I do not see that files are being attached to the request.  Here is what can be viewed on the server log:</p>
  
  <pre><code>Feb 7, 2013 1:36:58 PM com.sun.jersey.api.container.filter.LoggingFilter filter
  INFO: 56 * Server in-bound request
  56&gt; POST http://localhost:7001/myservice/requestXmlAndAttachment
  56 &gt; Accept-Encoding: gzip,deflate
  56 &gt; Content-Type: multipart/mixed
  56 &gt; Content-Length: 0
  56 &gt; Host: localhost:7001
  56 &gt; Connection: Keep-Alive
  56 &gt; User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
  56 &gt;
  </code></pre>
  
  <p>As you can see Content-Length is 0.<br>
  I have been able to test this service from java junit program.  Here is the portion of the program:</p>
  
  <pre><code>BodyPart bp1 = new BodyPart();
  bp1.setEntity(requestXMLString);
  bp1.setMediaType(MediaType.APPLICATION_XML_TYPE);
  
  BodyPart bp2 = new BodyPart();
  bp2.setContentDisposition(ContentDisposition.type("file").fileName("datafaile.xls").build  ());
  bp2.setEntity(binaryData1);
  bp2.setMediaType(MediaType.APPLICATION_OCTET_STREAM_TYPE);
  
  
  MultiPart multiPart = new MultiPart().bodyPart(bp1).bodyPart(bp2);
  
  ClientConfig cc = new DefaultClientConfig();
  cc.getClasses().add(MultiPartWriter.class);
  Client client = Client.create(cc);
  WebResource webResource = client.resource ("http://localhost:7001/myservice/requestXmlAndAttachment");
  ClientResponse response = webResource.type(new MediaType("multipart", "mixed")).post(ClientResponse.class, multiPart);
  </code></pre>
  
  <p>I have also tried to change media type to multipart/formdata (just to experiment) on SOAP UI Request editor box, then I can see that Content-Length = 30654 and I see file content read on the server logs.</p>
  
  <p>I have also experimented adding http headers to the request (MIME-Version, etc), but it did not make any difference.</p>
  
  <p>Although I can unit test without SOAPUI, I would prefer to have this test working with SOAPUI, because I already have bunch of the other tests setup in soapui executing different methods in the same service.</p>
  
  <p>Is there anyway to use SOAP UI for testing multipart/mixed with attachments?<br>
  Thanks in advance for looking into it.</p>