开发者

Content-Type Missing "start=" Tag in Java SOAP Client, Attachment not Found by Server

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 ca开发者_StackOverflow中文版n 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("<rootpart@here.com>");

        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);


This works for me:

soapMessage.getMimeHeaders().setHeader("Content-Type", 
  soapMessage.getMimeHeaders().getHeader("Content-Type")[0]+
    "; start=\"<rootpart@here.com>\"");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜