SOAP请求!no SOAPAction header!错误怎么解决
苜蓿gt 2015-06-05 11:14:23 源码
/**创建SOAPMessage
*/
public SOAPMessage getMessage(String[] params) throws SOAPException, Exception {
// 创建消息对象
SOAPMessage message = msgFactory.createMessage();
// 获得一个SOAPPart对象
SOAPPart soapPart = message.getSOAPPart();
// 获得信封
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
// // 获得消息头
// SOAPHeader soapHeader = soapEnvelope.getHeader();
// *****************创建soap消息主体*****************
SOAPBody soapBody = soapEnvelope.getBody();
// 添加消息主体
soapBody.addBodyElement(soapEnvelope.createName("userID")).addTextNode(params[0]);
soapBody.addBodyElement(soapEnvelope.createName("userToken")).addTextNode(params[1]);
// *************************************************
// 更新SOAP消息
message.saveChanges();
return message;
}
public void send(String requestUrl,SOAPMessage message) throws SOAPException, IOException {
//创建SOAP连接
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection sc = scf.createConnection();
/*
* 实际的消息是使用 call()方法发送的,该方法接收消息本身和目的地作为参数,并返回第二个 SOAPMessage 作为响应。
* call方法的message对象为发送的soap报文,url为mule配置的inbound端口地址。
*/
URL urlEndpoint = new URL(requestUrl);
// 响应消息
SOAPMessage response = sc.call(message, urlEndpoint);
// *************************************************
if (response != null) {
//输出SOAP消息到控制台
System.out.println("Receive SOAP message:");
response.writeTo(System.out);
} else {
System.err.println("No response received from partner!");
}
// *************************************************
// 关闭连接
sc.close();
}
public static void main(String[] args) {
try {
String userID="12345678901234567890";
String userToken="99999999999999999900000010000001";
String []params={userID,userToken};
String string=HttpCode.URL_USER;
SoapSender sender = SoapSender.getInstance();
SOAPMessage message = sender.getMessage(params);
sender.send(string,message);
} catch (Exception e) {
e.printStackTrace();
}
}