我创建了一个使用javax.xml.soap创建SoapMessage的代码。 当我将这段代码作为java应用程序启动时,一切正常,但当我在tomcat上将其作为Web应用程序启动时,我将SoapMessage清空。
SOAPMessage message = MessageFactory.newInstance()。createMessage(); printSOAPMessage(消息);
结果: SOAP消息=
<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body/></SOAP-ENV:Envelope>
SOAPMessage message = MessageFactory.newInstance()。createMessage(); printSOAPMessage(消息);
结果: SOAP消息=( NOTHING )
private void printSOAPMessage(SOAPMessage soapMessage) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapMessage.getSOAPPart().getContent();
System.out.print("\nSOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}