saaj发送soap消息出错
原代码:
package com.channelsoft.saaj.soap;
import java.io.IOException;
import java.net.URL;
import javax.xml.messaging.URLEndpoint;
import javax.xml.soap.*;
public class SOAPSender {
/**
* @param args
* @throws SOAPException
* @throws IOException
*/
public static void main(String[] args) throws IOException, SOAPException {
SOAPSender sender = new SOAPSender();
SOAPMessage message = sender.getMessage();
sender.send(message);
}
public void send(SOAPMessage message) throws IOException, SOAPException {
// Create SOAP connection
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection sc = scf.createConnection();
// Specify the endpoint
URL url = new URL("http://127.0.0.1:8080/saaj/Receiver");
// Send the SOAP message
SOAPMessage response = sc.call(message, url);
if (response != null) {
// Print the message to console
System.out.println("Receive SOAP message from localhost:");
response.writeTo(System.out);
} else {
System.err.println("No response received from partner!");
}
sc.close();
}
public SOAPMessage getMessage() throws SOAPException {
// Create a message factory
MessageFactory mf = MessageFactory.newInstance();
// Create a SOAP message
SOAPMessage message = mf.createMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
// Add a namespace declaration to envelope element
envelope.addNamespaceDeclaration("cwmp", "some uri");
// Create header element
SOAPHeader header = envelope.getHeader();
// Create body element
SOAPBody body = envelope.getBody();
SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName(
"Test", "cwmp", "uri"));
// add content to Test element
bodyElement.addTextNode("Just a test! ");
try {
// Print the message we have created above to console
message.writeTo(System.out);
} catch (IOException e) {
e.printStackTrace();
}
return message;
}
}
报错信息:
<?xml version="1.0" encoding="utf-8" standalone="yes"?><env:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cwmp="some uri" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header/><env:Body><cwmp:Test xmlns:cwmp="uri">Just a test! </cwmp:Test></env:Body></env:Envelope>Exception in thread "main" javax.xml.soap.SOAPException: Failed to send message: java.io.IOException: The server at http://127.0.0.1:8080/saaj/Receiver returned a 500 error code (Internal Server Error). Please ensure that your URL is correct, and the web service has deployed.
at weblogic.webservice.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:61)
at com.channelsoft.saaj.soap.SOAPSender.send(SOAPSender.java:36)
at com.channelsoft.saaj.soap.SOAPSender.main(SOAPSender.java:18)
Caused by: java.io.IOException: The server at http://127.0.0.1:8080/saaj/Receiver returned a 500 error code (Internal Server Error). Please ensure that your URL is correct, and the web service has deployed.
at weblogic.webservice.binding.http11.Http11ClientBinding.handleErrorResponse(Http11ClientBinding.java:123)
at weblogic.webservice.binding.http11.Http11ClientBinding.receive(Http11ClientBinding.java:220)
at weblogic.webservice.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:57)
... 2 more