Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a connection timeout when using JAXRPC-RI web services client?

I'm working with a bit of a legacy component in which we interact with a SOAP web service (a technology which I absolutely, positively abhor) using some client code built using the JAXRPC-RI (reference implementation) library.

I'm interested in being able to set a timeout with the stubs so that in case the web services server does not reply within X seconds, the application isn't setting there forever waiting for a response.

I'm using to working with clients/stubs generated by Apache Axis, in which you can simply use org.apache.axis.client.Stub.setTimeout() to set a timeout.

For the life of me I can't figure out how to set a timeout when using Stubs created with JAXRPC-RI:

  • The port class I am instantiating extends com.sun.xml.rpc.client.StubBase and implements javax.xml.rpc.Stub and com.sun.xml.rpc.spi.runtime.StubBase.
  • The JavaDocs for none of these classes mention any sort of timeout or method to do this.
  • Trying code like stub._setProperty("axis.connection.timeout", 1000); results in an exception at runtime: javax.xml.rpc.JAXRPCException: Stub does not recognize property: axis.connection.timeout

Does anyone have any ideas on how to set/enforce a timeout when using a JAXRPC-RI client? Is it even possible?

like image 344
matt b Avatar asked Apr 30 '09 18:04

matt b


People also ask

What is JAX-RPC give two benefits?

JAX-RPC 1.1 provides core APIs for developing and deploying web services on a Java™ platform and is a part of the Web Services for Java Platform, Enterprise Edition (Java EE) platform. The Java EE platform enables you to develop portable web services. WebSphere® Application Server implements JAX-RPC 1.1 standards.

What is the equivalent of JAX-RPC service endpoint interface in WSDL file?

JAX-RPC Web Services Using a WSDL The WSDL portType is mapped to the Java service definition interface. To generate the service interface from the WSDL, use the wscompile command with -import option, passing it the location of the WSDL document.

Which SOAP bindings does JAX-RPC support?

JAX-RPC and JAX-WS both support SOAP 1.1. JAX-WS also supports SOAP 1.2.

Which of the following issue JAX-RPC specification does not address?

JAX-RPC does not address asynchronous invocation in its 1.0 rendition. A true asynchronous model would require callbacks ( onMessage , etc ) . The one-way invocation model defined in the API is considered synchronous. A model for defining a service, registering it, and invoking it within the J2EE and J2SE environments.


1 Answers

You may have luck setting properties such as sun.net.client.defaultConnectTimeout or sun.net.client.defaultReadTimeout, though that would then introduce a system-wide timeout.

In code the properties values are set using Strings:

System.setProperty("sun.net.client.defaultConnectTimeout", "1000");
System.setProperty("sun.net.client.defaultReadTimeout", "1000");

For a quick test, it might be easier to set the environment variable JAVA_OPTS or use the command line:

java -Dsun.net.client.defaultConnectTimeout="1000" ...
like image 183
Arjan Avatar answered Sep 19 '22 15:09

Arjan