我编写了以下代码来实现SAAJ。
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://xxx.xxx.x.xx:8080/IssuerWebService";
soapResponse = soapConnection.call(createSOAPRequest(conf.TOKEN,conf.VERSION,
conf.CALLER_ID,conf.USER_ID,
conf.PASSWORD,strXML), url);
try{
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapResponse.writeTo(out);
String response= out.toString();
但变量响应包含
com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl@7096faf1
createSOAPRequest()
的代码如下所示
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String headerNameSpace = "https://paysecure/merchant.soap.header/";
String bodyNameSpace = "https://paysecure/merchant.soap/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("mer", headerNameSpace);
envelope.addNamespaceDeclaration("mer1", bodyNameSpace);
/*
Constructed SOAP Request Message:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mer="https://paysecure/merchant.soap.header/" xmlns:mer1="https://paysecure/merchant.soap/">
<soapenv:Header>
<RequestorCredentials xmlns="https://paysecure/merchant.soap.header/">
<Token>AF165FBD-4E85-4c66-BEB1-C54DC16CD48B</Token>
<Version>1.0.0.0</Version>
<CallerID>720203</CallerID>
<UserCredentials>
<UserID>test@acculynk.com</UserID>
<Password>Password!1</Password>
</UserCredentials>
</RequestorCredentials>
</soapenv:Header>
<soapenv:Body>
<CallPaySecure xmlns="https://paysecure/merchant.soap/">
<strCommand>Issuer_initiate</strCommand>
<strXML><paysecure><partner_id>ACCUTEST</partner_id><card_no>6073849900004960</card_no><auth_method>OTP</auth_method><language_code>en</language_code></paysecure></strXML>
</CallPaySecure>
</soapenv:Body>
</soapenv:Envelope>
*/
// Soap Header
SOAPHeader soapHeader = envelope.getHeader();
SOAPElement RequestorCredentials = soapHeader.addChildElement("RequestorCredentials", "mer");
SOAPElement Token = RequestorCredentials.addChildElement("Token");
Token.addTextNode("AF165FBD-4E85-4c66-BEB1-C54DC16CD48B");
SOAPElement Version = RequestorCredentials.addChildElement("Version");
Version.addTextNode("1.0.0.0");
SOAPElement CallerID = RequestorCredentials.addChildElement("CallerID");
CallerID.addTextNode("720203");
SOAPElement UserCredentials = RequestorCredentials.addChildElement("UserCredentials");
SOAPElement UserID = UserCredentials.addChildElement("UserID");
UserID.addTextNode("test@acculynk.com");
SOAPElement Password = UserCredentials.addChildElement("Password");
Password.addTextNode("Password!1");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement CallPaySecure = soapBody.addChildElement("CallPaySecure", "mer1");
SOAPElement strCommand = CallPaySecure.addChildElement("strCommand");
strCommand.addTextNode("Issuer_Initiate");
SOAPElement strXML = CallPaySecure.addChildElement("strXML");
strXML.addTextNode("<paysecure><card_no>60738499004978</card_no> <card_exp_date>122014</card_exp_date><card_holder_status> </card_holder_status><cvd2>0320</cvd2><language_code>en</language_code> <tran_id>000000000000025236 </tran_id></paysecure>");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", headerNameSpace + "CallPaySecure");
soapMessage.saveChanges();
return soapMessage;
}
如何获取响应中的元素?