【发布时间】:2018-07-03 18:43:54
【问题描述】:
当我使用下面的 SOAPBOAY 代码时,我得到了 null,这是怎么回事。过去3天我很挣扎。在我的项目中,我想将响应转换为类对象,但是当我打印 message.getSOAPBody().toString() 时,它的值为 NULL。请任何答案,这将有助于我的服务自动化项目。
String resMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<soapenv:Envelope\r\n"
+ " xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n"
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\r\n"
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" + " <soapenv:Header>\r\n"
+ " <ns1:RequestHeader\r\n"
+ " soapenv:actor=\"http://schemas.xmlsoap.org/soap/actor/next\"\r\n"
+ " soapenv:mustUnderstand=\"0\"\r\n"
+ " xmlns:ns1=\"https://www.google.com/apis/ads/publisher/v201705\">\r\n"
+ " <ns1:networkCode>123456</ns1:networkCode>\r\n"
+ " <ns1:applicationName>DfpApi-Java-2.1.0-dfp_test</ns1:applicationName>\r\n"
+ " </ns1:RequestHeader>\r\n" + " </soapenv:Header>\r\n" + " <soapenv:Body>\r\n"
+ " <getAdUnitsByStatement xmlns=\"https://www.google.com/apis/ads/publisher/v201705\">\r\n"
+ " <filterStatement>\r\n" + " <query>WHERE parentId IS NULL LIMIT 500</query>\r\n"
+ " </filterStatement>\r\n" + " </getAdUnitsByStatement>\r\n" + " </soapenv:Body>\r\n"
+ "</soapenv:Envelope>";
// Create SoapMessage
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
// Load the SOAP text into a stream source
byte[] buffer = resMessage.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
StreamSource source = new StreamSource(stream);
// Set contents of message
soapPart.setContent(source);
// -- DONE
message.writeTo(System.out);
if (message != null) {
System.out.println("The Response Body is " + message.getSOAPBody().toString());
}
【问题讨论】: