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:
com.sun.xml.rpc.client.StubBase
and implements javax.xml.rpc.Stub
and com.sun.xml.rpc.spi.runtime.StubBase
.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?
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.
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.
JAX-RPC and JAX-WS both support SOAP 1.1. JAX-WS also supports SOAP 1.2.
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.
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" ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With