Java Soap客户端太慢

时间:2019-01-18 09:31:34

标签: 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;
}

1 个答案:

答案 0 :(得分:0)

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

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

请参阅: the new Core Bot

相关问题