首页 > 解决方案 > Java Soap 客户端太慢了

问题描述

我有一个 Java Soap 客户端,它将带有服务和方法的 XML 请求发送到远程服务器,但它异常缓慢并且不能专业使用。有没有办法加快速度,或者有没有更快的方法来做肥皂请求?

谢谢您的回答。这是我的 Soap 客户端的摘录。

private SOAPMessage makeMessage(String nodeName, String xmlStr, boolean asResponse) throws Exception {
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();

envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/1999/XMLSchema-instance");
envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/1999/XMLSchema");

SOAPBody body = envelope.getBody();

SOAPElement element = body.addChildElement(envelope.createName("ns1:" + this.method + (asResponse ? "Response" : "")));
element.addAttribute(envelope.createName("xmlns:ns1"), "urn:" + this.service);
element.addAttribute(envelope.createName("ns1"), "http://schemas.xmlsoap.org/soap/encoding");

SOAPElement ele2 = element.addChildElement(envelope.createName(nodeName));
ele2.addAttribute(envelope.createName("xsi:type"), "xsd:string");
ele2.addTextNode(xmlStr);


if (!asResponse) message.saveChanges();

return message;
}

private boolean sendRequest() throws Exception {
 try {
  SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
  SOAPConnection con = conFactory.createConnection();
  URL endpoint = new URL(this.getURI());

  SOAPMessage message = this.makeMessage("msgstr", this.request.toString(), false);
  SOAPMessage retval = con.call(message, endpoint);
    //extraction du XML en String lisible du message SOAP
  this.response = extractXML(retval);

} catch (Exception e) {
  this.response = e.getMessage();
}
return true;
}

标签: javaxmlsoap

解决方案


您应该启用您正在为客户端使用的框架的所有跟踪/日志信息,以便查看问题出在哪里。

如果您使用的是 jax-ws,一种简单的方法是:

System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");

请参阅: 使用 JAX-WS 跟踪 XML 请求/响应


推荐阅读