This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I wrote a SOAP client and I am using the SoapConnection object to make a call to the web service. I need this client to timeout in 15 minutes if I dont get a SOAP response. There is nothing in the API that will allow me to do this. So here are the things I have done so far to work around this problem
1. I tried to write a URLStreamHandler and I constructed a URL object with the handler as a parameter hoping that I can set the timeout in the URLConnection. That didnt work because only the toString() method is invoked on the URL object by the SOAP API.
2. I downcasted the SoapConnection object to a SoapConnectionImpl object. The SoapConnectionImpl object is provided by the axis API. I used the timeout method on this object and that works fine.
Even though option 2 works I feel awkward to downcast the implementation class and then use a timeout method on that class. It just does not feel right. Does anyone know a method that will handle timeouts more gracefully ? I am against starting new threads and then interrupting them if the thread is still alive after X minutes. That is not graceful either and that adds more code complexity.
I have implemented a basic soap client (javax.xml.soap.*).
The input message is JBossEsb message, which I convert to soap message and then send it using SOAPConnection, which works fine.
The problem with SOAPConnection class is that it does not provide setTimeout(..) method. I read some where that there is another class SOAPConnectionImpl (by axis), which extends SOAPConnection and has this setTimeout method.
I have tried to convert my existing implementation to SOAPConnectionImpl but i always get a classcast exceptions.
Could somebody help me in suggesting a solution to this problem? My main concern is to include timeout feature that is my WS consumer/client should timeout after a certain period if the server does not reply.
Any other soap message sending implementation with timeout feature are also good.
I am using SAAJ for sending a SOAP Message. I need to set a timeout on the client if there is no reply within certain time.
After going through some references, it seems downcasting to SoapConnectionImpl works? How would this be accomplised . Got the AXIS jars and cast - but gives a ClassCastException? Also is this safe to do - any known issues?
Anywho, the SoapConnection object was indeed downcasted to a SoapConnectionImpl when I used AXIS. But it appears that this solution does not work for the others in the thread. This could be because of the following reasons
1. The SOAP provider does not have the SoapConnectionImpl set as the default implementation
2. Since this is not a method to be honored in an interface it is no longer available (if you can downcast it successfully that is)
An alternate solution suggested was to tinker with the HTTP timeout that the SOAP messages will be transported over. There was another method where you do not need a work around at all. The interface had a timeout method. I cannot remember where I found this client code. I will update this thread if I find the solution. I will experiment with it tonight
The implementation class is now com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection. The point I am making is, you cannot depend on the implementation class specific details to set the timeout, like I mentioned in my original post a few months back. To find out which implementation you have, simple do an 'inspect element' on the SOAPConnection on your favorite IDE. That will / should tell you the type of the underlying class. If it supports timeout thats great.
I ll try to hunt down the other method which can handle timeouts gracefully. You should be using that instead
An alternate solution:
Axis supposedly supports timeouts by passing these system properties. Source
Joined: Jul 03, 2003
Thanks Deepak. The webservice call is done within another application that uses only JDK 1.4. I cannot use higher versions. So, this is another restriction.
hmmm well you cannot depend on the method offered by an implementation class.
How about starting a new thread and then stopping it after X seconds if there is no response ? It is extremely ugly but will work. I still cannot remember the alternate call that allowed one to set the timeout.
It's an old thread, but I just finished coding this and wanted to let users of SAAJ and SOAPConnection, not Axis, not Axis2, just what is built in to Java, know they can indeed use URLStreamConnection to set timeouts.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com