Results 1 to 4 of 4

Thread: Missing start boundary on messages with attachments

  1. #1
    Join Date
    Dec 2007
    Posts
    23

    Question Missing start boundary on messages with attachments

    I'm attempting to send a SOAP message with an attachment, using WebServiceMessageCallback to add the attachment like so:
    Code:
    WebServiceMessageCallback requestCallback = new WebServiceMessageCallback() {
      public void doWithMessage(WebServiceMessage message)
          throws IOException, TransformerException {
        
        SoapMessage soapMessage = (SoapMessage) message;
        
        // Put the XMLObject for the request body into the SOAP body.
        SoapBody soapBody = soapMessage.getSoapBody();
        Transformer transformer = MyClient.this.transformerFactory.newTransformer();
        transformer.transform(new StreamSource(myBodyDocument.newReader(xmlOptions)), 
            soapBody.getPayloadResult());
        
        // Add the XMLObject MyHeader to the SOAP header.
        SoapHeader soapHeader = soapMessage.getSoapHeader();
        transformer = MyClient.this.transformerFactory.newTransformer();
        transformer.transform(new StreamSource(myHeaderDocument.newReader(xmlOptions)), 
            soapHeader.getResult());
        
        soapMessage.addAttachment(
            generateContentId("ReceiptsAttachment"), // Content-ID 
            new ByteArrayResource(attachmentData),   // Data
            "application/octet-stream");        // Content-Type
      }
    }; 
    
    serviceTemplate.sendAndReceive(
      "https://foo.bar.com/SendSubmissionReceipts", 
      requestCallback, responseExtractor);
    But I get a fault response back with a faultstring "Decoding of request failed: Missing start boundary" and an HTTP response code "HTTP/1.1 415 Unsupported Media Type". And sure enough, when I examine the message that I sent, the Content-Type was the correct "multipart/related", and a mime boundary value was declared, but the HTTP message body doesn't use the MIME boundary before the XML part, and the attachment part isn't even present. Case in point:

    Code:
    Accept-Encoding: gzip
    Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_3D927F4433B32F68641210953465313; type="text/xml"; start="0.urn:uuid:3D927F4433B32F68641210953465314@apache.org"; charset="UTF-8"
    SOAPAction: ""
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: foo.bar.com
    Cookie: $Version=0; JSESSIONID=0001JGVZICF0ATPGIDRKW5J1LHY:11p9fo6l7; $Path=/
    Content-Length: 3978
    
    <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header>[contents intentionally omitted]</soapenv:Header><soapenv:Body>[contents intentionally omitted]</soapenv:Body></soapenv:Envelope>
    I've set some breakpoints to see if my attachment byte array is null or something, but it appears to be ok.

    Any idea why the HTTP request is incorrect? Am I adding the attachment correctly and at the correct point in the message creation process? Should I use a ClientInterceptor to add the attachment instead? Suppose I'll try that next....

    Spring 2.5.2
    Spring-WS 1.5.1
    CommonsHttpMessageSender
    AxiomSoapMessageFactory
    Java 5
    Last edited by barsimp47; May 16th, 2008 at 01:34 PM.

  2. #2
    Join Date
    Dec 2007
    Posts
    23

    Thumbs down

    Just tried the same thing inside the handleRequest() of a ClientInterceptor, but I got the same bad results.

  3. #3
    Join Date
    Dec 2007
    Posts
    23

    Question PostMethod vs. MultipartPostMethod

    After stepping through the code starting with WebServiceTemplate.sendAndReceive() and digging down through to the HttpClient calls, it appears that the CommonsHttpMessageSender is returning a connection that uses a org.apache.commons.httpclient.methods.PostMethod instead of a org.apache.commons.httpclient.methods.MultipartPos tMethod.

    Can someone tell me how to configure the message sender to return connections with a MultipartPostMethod?

  4. #4
    Join Date
    Dec 2007
    Posts
    23

    Unhappy

    Upon further investigation, it appears that Commons Http's MultipartPostMethod is deprecated in favor of setting the PostMethod's request entity to a MultipartRequestEntity. The only place I can find Spring-WS calling PostMethod.setRequestEntity is in CommonsHttpConnection.onSendAfterWrite() where it uses a ByteArrayRequestEntity, which apparently doesn't create the HTTP parts correctly (at all).
    Code:
    protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
      postMethod.setRequestEntity(new ByteArrayRequestEntity(requestBuffer.toByteArray()));
      requestBuffer = null;
      httpClient.executeMethod(postMethod);
    }
    It would seem to me that onSendAfterWrite() should be checking the WebServiceMessage to see if there are any attachments, and if there are, creating the necessary Parts and passing them to a MultipartRequestEntity instead of sending the entire request to a ByteArrayRequestEntity.

    I suppose I should post this as a bug in Jira unless someone speaks up to show me the correct way to make this work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •