简体   繁体   中英

Java Soap client is too slow

I have a Java Soap client that send XML requests with service and method to a remote server but it is anormally slow and can't be used professionnaly. Is there a way to speed it up or is there a faster way to do Soap requests ?

Thank you for your answers. Here is an extract of my Soap client.

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;
}

You should enable all the trace/log information of the framework that you are using for the client in order to see where the problem is.

If you are using jax-ws a simple way would be:

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");

See: Tracing XML request/responses with JAX-WS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM