I'm attempting to send a SOAP message with an attachment, using WebServiceMessageCallback to add the attachment like so:
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: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);
I've set some breakpoints to see if my attachment byte array is null or something, but it appears to be ok.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>
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


Reply With Quote