我正在为JAX-WS客户端开发邮政编码查找服务。我跟踪请求xml如下:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getRequest xmlns:ns2="http://www-schema/WSAddressLookup/">
<ACSH>
<USERID>d19107</USERID>
<ROLEID>tester</ROLEID>
</ACSH>
<ACAH>
<COMPLETIONCODE>0</COMPLETIONCODE>
<SERVICENAME>paris.CALS.1.Get.XXINFO</SERVICENAME>
</ACAH>
<ACXMLBODY>
<AddressLookupRequest>
<RequestRecord>
<OperationType>Get</OperationType>
<AddressListKey>10376051.00</AddressListKey>
</RequestRecord>
</AddressLookupRequest>
</ACXMLBODY>
</ns2:getRequest>
</S:Body>
</S:Envelope>
我使用SOAP UI对其进行了测试,结果超时。
它希望在soap信封中声明ns2名称空间,如下所示:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www-schema/WSAddressLookup/" >
<S:Body>
<ns2:getRequest>
<ACSH>
<USERID>d19107</USERID>
<ROLEID>tester</ROLEID>
</ACSH>
<ACAH>
<COMPLETIONCODE>0</COMPLETIONCODE>
<SERVICENAME>paris.CALS.1.Get.XXINFO</SERVICENAME>
</ACAH>
<ACXMLBODY>
<AddressLookupRequest>
<RequestRecord>
<OperationType>Get</OperationType>
<AddressListKey>10376051.00</AddressListKey>
</RequestRecord>
</AddressLookupRequest>
</ACXMLBODY>
</ns2:getRequest>
</S:Body>
</S:Envelope>
所以我写了一个处理程序,如下所示:
public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {
private static final Logger LOG = LoggerFactory.getLogger(LoggingHandler.class);
FileOutputStream fop = null;
File file;
FileOutputStream fop1 = null;
File file1;
public boolean handleMessage (SOAPMessageContext c) {
LOG.info("Inside handleMessage of LoggingHandler");
SOAPMessage msg = c.getMessage();
try {
boolean request = ((Boolean) c.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();
file = new File("c:/work/soapRequest.txt");
fop = new FileOutputStream(file);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
if (request) { // This is a request message.
// Write the message to the output stream
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope(); //get the SOAP Message envelope
envelope.addNamespaceDeclaration("ns2", "http://www-schema/WSAddressLookup/");
msg.saveChanges();
c.setMessage(msg);
msg.writeTo(fop);
}
}
catch (Exception e) {}
finally{
try {
if (fop != null) {
fop.close();
}
} catch (IOException e) {
LOG.info("Logging handler Exception: ", e);
}
}
return true;
}
public boolean handleFault (SOAPMessageContext c) {
SOAPMessage msg = c.getMessage();
try {
file = new File("c:/work/soapResponse.txt");
fop = new FileOutputStream(file);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
msg.writeTo (fop);
LOG.info("soap fault written");
}
catch (Exception e) {}
finally{
try {
if (fop != null) {
fop.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
public void close (MessageContext c) {
}
public Set getHeaders() {
// Not required for logging
return null;
}
}
我在信封中添加了一个名称空间声明,并将请求xml写入本地文件。请求xml现在与上面显示的预期请求完全相同。我使用SOAP UI测试了它,它返回正确的响应xml。但是,当我从应用程序调用服务时,它会超时。故障处理程序方法将故障消息写入本地文件,并显示超时消息。
是否有可能跟踪的请求不是用于调用服务的请求?(尽管行msg.saveChanges();
和c.setMessage(msg);
非常感谢任何帮助......