Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

android - KSOAP never timeout

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...