Java Soap 客户端太慢

标签 java xml soap

我有一个 Java Soap 客户端,它通过服务和方法向远程服务器发送 XML 请求,但它通常很慢并且无法专业使用。 有没有办法加快速度或者有更快的方法来执行 Soap 请求?

谢谢您的回答。这是我的 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;
}

最佳答案

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

如果您使用 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");

参见: Tracing XML request/responses with JAX-WS

关于Java Soap 客户端太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54251037/

相关文章:

xml - 在 R 中,如何从 XML 文件中提取两个值,遍历 5603 个文件并写入表

c# - 服务引用未加载 : Schema with target namespace could not be found

java - 父面板未正确重绘

java - 使用表设计 Hibernate 类

c# - 不使用 try/catch 检查格式正确的 XML?

javascript - 如何在 node.js 中使用 node-soap 或 strong-soap 添加 soap header

java - 如何在 REST 应用程序上使用 SOAP Web 服务

java - 将 JTable 用于 JTree 单元格编辑器

java - 无法使用 versionone java sdk 检索投影/多重关系字段 Requests.Custom_SFDCChangeReqID2

android - 无法将按钮标签包装在 Material Button Toggle Group 内