views:

17

answers:

0

I am creating a Java client for a SOAP service that takes an attachment. I'm using java.xml.soap classes, which I have uses before, but not with attachments. The server claims that my attachment is not included.

I used SoapUI, which works, and wireshark to compare my SOAP message to a working SOAP message. One big difference is that my header does not include "start=".

The working Content-Type looks like this:

Content-Type: multipart/related; type="text/xml"; start=""; boundary="----=_Part_23_6341950.1286312374228"

The Content-Type I get from my Java code is like this:

Content-Type: multipart/related; type="text/xml"; boundary="----=_Part_23_6341950.1286312374228"

No start= even when the content ID is set on the root element. The working and failing SOAP messages are otherwise nearly identical. How can I get the start tag generated, or what are other reasons the server might not see the attachment?

Thanks

        SOAPMessage soapMessage = 
                       MessageFactory.newInstance().createMessage();            
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();         
        SOAPBody body = soapEnvelope.getBody(); 
        SOAPHeader header = soapMessage.getSOAPHeader();

        soapPart.setContentId("<[email protected]>");

        MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
        mimeHeaders.addHeader("SOAPAction", "addDocument");
        mimeHeaders.addHeader("Accept-Encoding", "gzip,deflate");

        Name bodyName = soapEnvelope.createName("Document", "doc", 
            "http://ns/Document");
        SOAPBodyElement document = body.addBodyElement(bodyName);

        Name filenameName = soapEnvelope.createName("Filename", "doc", 
            "http://ns/Document");

        SOAPElement filename = document.addChildElement(filenameName);
        filename.setValue("filename.txt");

        AttachmentPart attachment = soapMessage.createAttachmentPart(); 
        attachment.setContent("Some text", "application/octet-stream");
        attachment.setMimeHeader("Content-Transfer-Encoding", "binary");

        soapMessage.addAttachmentPart(attachment); 

        SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = scf.createConnection();
        URL url = new URL("http://host/Service");

        SOAPMessage reply = soapConnection.call(soapMessage, url);