内容类型缺少Java SOAP客户端中的“start =”标记,服务器未找到附件

时间:2010-10-06 20:16:37

标签: java soap attachment

我正在为一个带有附件的SOAP服务创建一个Java客户端。我正在使用之前使用的java.xml.soap类,但不使用附件。服务器声称我的附件未包含在内。

我使用了SoapUI,并使用wireshark将我的SOAP消息与工作的SOAP消息进行比较。一个很大的区别是我的标题不包含“start =”。

工作内容类型如下所示:

内容类型:multipart / related;类型= “文本/ xml” 的;开始= “”;边界= “---- = _ Part_23_6341950.1286312374228”

我从Java代码中获取的Content-Type是这样的:

内容类型:multipart / related;类型= “文本/ xml” 的;边界= “---- = _ Part_23_6341950.1286312374228”

无启动=即使在根元素上设置了内容ID。工作和失败的SOAP消息几乎完全相同。如何生成开始标记,或者服务器可能看不到附件的其他原因是什么?

由于

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

1 个答案:

答案 0 :(得分:0)

这对我有用:

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