Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusing the SOAP client with Axis

Tags:

java

soap

axis

I'm using Apache Axis to make a SOAP request to a service. I noticed that sometimes, it take a couple of seconds to get a response even though the service is a simple echo for now. So I'm wondering if establishing the connection is what takes the time, even though the server does HTTP/1.1 connection keep alive.

Should somehow reuse the client between requests or if it's ok to get a new one for every request?

This is my code. Should I keep locator and/or client around between requests or is it okay to forget it?

MyExampleServiceLocator locator = new MyExampleServiceLocator();
MyExampleServicePort client = locator.getMyExampleServicePort(url);
MyExampleRequest request = buildMyExampleRequest();
MyExampleResponse response = client.send(request);   // This takes time sometimes
like image 899
mprivat Avatar asked Jul 04 '26 17:07

mprivat


1 Answers

  • For complex services the cost of instantiating the locator may be high. Therefore you should always try to reuse it as much as possible. Locators are expected to be thread safe, so you can use them as singletons. Note however that in Axis 1.4 there is at least one thread safety issue regarding locators: AXIS-2498.
  • Creating a new stub (client) is less expensive, but reusing a stub is unproblematic. They are also expected to be thread safe (at least in Axis 1.4), except for scenarios that use the stub in a stateful way (e.g. HTTP sessions).
  • Axis' default HTTP transport only supports HTTP 1.0 and creates a new connection for every request.
like image 63
Andreas Veithen Avatar answered Jul 06 '26 09:07

Andreas Veithen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!