我正在尝试将 SOAP 调用集成到我的 Java 应用程序中。我已经在线学习了各种教程,但是当我运行应用程序时,它会给出错误,sm.saveChanges()
如果该行被注释掉,它会给出错误sm.writeTo(System.out)
。
下面是代码:
//Create a SOAPConnection
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage sm = mf.createMessage();
SOAPPart sp = sm.getSOAPPart();
SOAPEnvelope sv = sp.getEnvelope();
SOAPHeader sh = sm.getSOAPHeader();
//SOAPHeaderElement headerElement = sh.addHeaderElement(sv.createName("Signature", "SOAP-SEC", "http://schemas.xmlsoap.org/soap/security/2000-12"));
SOAPBody sb = sm.getSOAPBody();
//sh.detachNode();
MimeHeaders headers = sm.getMimeHeaders();
headers.addHeader("SOAPAction", "\"\"");
//QName bodyName = new QName("http://quoteCompany.com", "GetQuote", "d");
//QName bodyName = new QName(msisdn, "GetRioInformationsRequest", "ser");
//QName bodyName = new QName("http://schemas.xmlsoap.org/soap/encoding/", "GetRioInformationsRequest", XMLConstants.DEFAULT_NS_PREFIX);
QName bodyName = new QName("http://quoteCompany.com/", "GetQuote", "ser");
//QName bodyName = sv.createQName("http://quoteCompany.com/", "GetQuote", "ser");
Name bodyName2 = sv.createName("GetQuote","ser", "http://quoteCompany.com/");
SOAPBodyElement bodyElement = sb.addBodyElement(bodyName2);
//QName qn = new QName("aName");
//Name qn = sv.createName("rioSearchRequest");
QName qn = new QName("returnCode");
SOAPElement quotation = bodyElement.addChildElement(qn);
//quotation.addChildElement(qn2);
//Name qn2 = sv.createName("msisdn");
//qn2.
//quotation.addAttribute(qn2, msisdn);
//quotation.addTextNode("TextMode");
quotation.addTextNode(msisdn);
System.out.println("Saving SOAP message.");
sm.saveChanges();
System.out.println("\n Soap Request:\n");
sm.writeTo(System.out);
System.out.println("Request Outputted for viewing.");
//URL endpoint = new URL("http://yourServer.com");
URL endpoint = new URL("http://127.0.0.1:8088/mockSoapBinding");
System.out.println("URL entered.");
SOAPMessage response = connection.call(sm, endpoint);
System.out.println("Resquest Sent!");
System.out.println(response.getContentDescription());
System.out.println("Response obtained!");
相应的错误是:
XSL-1101: (Fatal Error) DOMSource node as this type not supported.
Jun 27, 2012 4:37:45 PM com.sun.xml.messaging.saaj.soap.MessageImpl saveChanges
SEVERE: SAAJ0539: Unable to get header stream in saveChanges
Jun 27, 2012 4:37:45 PM com.sun.xml.messaging.saaj.soap.MessageImpl saveChanges
SEVERE: SAAJ0540: Error during saving a multipart message
SOAP Call Issue: Error during saving a multipart message
com.sun.xml.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
at com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1209)
at com.application.package.SOAPCalls.SOAPCall(SOAPCalls.java:66)
at com.application.package.Main.<init>(Main.java:97)
at com.application.package.Main.main(Main.java:253)
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Unable to get header stream in saveChanges:
at com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1179)
... 3 more
Caused by: java.io.IOException: XSL-1101: (Fatal Error) DOMSource node as this type not supported.
at com.sun.xml.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:306)
at com.sun.xml.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:317)
at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:324)
at com.sun.xml.messaging.saaj.soap.MessageImpl.getHeaderBytes(MessageImpl.java:1020)
at com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1171)
... 3 more
有什么建议么?