3

I'm using ksoap2 2.5.4 (on Android 2.2) which supports timeout. I'm using Apache 2.2.16 to handle my requests. Everything works fine, but when I shutdown my Apache (or disconnect remote PC on which Apache is running) the call never times out. I'm using separate thread to call my WS and this thread stop working/responding/stalls for about 2 minutes in this case.

int MSG_TIMEOUT = 15000;
HttpTransportSE httpTransport;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
httpTransport = new HttpTransportSE(URL, MSG_TIMEOUT);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);//thread stops responding here

I even tried to use Timer to cancel that thread after predefined timeout, but it didn't work. Thread is still there and is waiting for 2 minutes.

TimerTask task;
Timer mTimer;
task = new TimerTask() {
  public void run() {               
    mThread.interrupt();
   }
 };
mTimer = new Timer();
mTimer.schedule(task, MSG_TIMEOUT);

I also get this warning that may have something to do with it (I don't know what to do with it):

Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

Is there any chance to make KSOAP working or to improve the timer to interrupt that thread after predefined timeout? Thank you for answer or any idea what to try!

Tuti
  • 105
  • 7
Warlock
  • 2,481
  • 4
  • 31
  • 45

4 Answers4

6

Use ksoap2 API version 2.5.2 or greater.

You can download that by clicking here

And use the following code while making object of HTTPTransport.

/**
 * Creates instance of HttpTransportSE with set url
 *
 * @param url
 *            the destination to POST SOAP data
 */
public HttpTransportSE(String url) {
    super(url);
}

/**
 * Creates instance of HttpTransportSE with set url
 *
 * @param url
 *            the destination to POST SOAP data
 * @param timeout
 *            timeout for connection and Read Timeouts (milliseconds)
 */
public HttpTransportSE(String url, int timeout) {
    super(url, timeout);
}
Anjum Shrimali
  • 346
  • 5
  • 15
0

Have you downloaded the source and then compiled it? Or did you use a finished JAR file? Will test this tonight or early in the morning tomorrow.

Andreas Mattisson
  • 1,051
  • 2
  • 19
  • 39
  • Even without httpTransport.debug = true the connection "never" timeouts. I downloaded the JAR file from official KSOAP2 website. I even checked the exact size of the JAR file and everything looks fine. – Warlock Apr 16 '11 at 09:54
  • And I guess that you also tried the one I had on my page? "ksoap2-android-assembly-2.5.2-jar-with-dependencies_timeout.jar". I haven't tested the official Jar after the merge was done from my branch to the main one. Only visualized the code. But I see that the exception thrown Is not correct. – Andreas Mattisson Apr 21 '11 at 09:23
  • IOException is thrown where the actuall TimeOutException also should be used. I tried with my compiled Jar, and if the server (Webservice) is down, the timeout will occur. If I try to stall the tread in the webservice (timer that waits 10 sec) the timeout will also occur. Did test timeout for 6sec. If the server is responding with some data and then goes down, the tread listening for data (in debug mode) will halt and wait infinite. This I guess must be fixed anyhow, but I cannot reproduce the errors you got. – Andreas Mattisson Apr 21 '11 at 09:24
  • Have you also recompiled with your jdk to fix the warnings if they actually can affect the timeout somehow? – Andreas Mattisson Apr 21 '11 at 09:24
  • Thank you for your answers. I'm now using my own solution for sending soap messages. So it's not so easy to test it again with jar on your webpage (or recompile official source code). But I hope that they will fix that Exception errors you mentioned in the next version. I always tried to shutdown the server (Stop command) or made server physically disconnected on LAN before the connection. But I saw some strange behaviour (connection sometimes never timeout) on "slow/cheap" phones even when the server was online. – Warlock Apr 23 '11 at 13:02
  • I will suggest a fix for the code in the main release, to change the exception. – Andreas Mattisson May 04 '11 at 13:47
0

I'm having the same problem running ksoap2-android-assembly-2.5.6-jar-with-dependencies. I would have assumed the ksoap timeout value that appears on HttpTransportSE would be equivalent to what you can accomplish using org.apache.http.client.HttpClient with connection timeout and socket timeout pamameters:

HttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);

I finally get a SocketException "the operation timed out" after ~3 minutes no matter what value I put in the timout parameter on HttpTransportSE. My server is running, its just not responding to the request.

John
  • 989
  • 2
  • 9
  • 11
0

This still seems to be an open issue with HttpTransportSE ignoring the timeout value in some situations. See related:

http://code.google.com/p/ksoap2-android/issues/detail?id=52

http://code.google.com/p/ksoap2-android/issues/detail?id=60&q=httpTransportse%20timeout

John
  • 989
  • 2
  • 9
  • 11