1
我正在为需要附件的SOAP服务创建Java客户端。我使用的是之前使用的java.xml.soap类,但不使用附件。服务器声称我的附件不包括在内。Content-Type Missing“start =”Java SOAP客户端中的标记,服务器找不到附件
我使用SoapUI,它工作,wireshark将我的SOAP消息与工作的SOAP消息进行比较。一个很大的区别是我的头文件不包含“start =”。
工作的Content-Type看起来是这样的:
内容类型:多部分/相关;类型= “文本/ xml” 的;开始= “”;边界=“---- = _ Part_23_6341950.1286312374228”
内容类型,我从我的Java代码得到的是这样的:
内容类型:多部分/相关;类型= “文本/ xml” 的; border =“---- = _ 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("<[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);