How to enable timeout in webservice call using ksoap 2?

I need to add a timeout to a J2ME application that uses ksoap 2 to connect to a web service.

I tried the method described as possible pseudo timeout at http://ksoap2.sourceforge.net/doc/api/org/ksoap2/transport/HttpTransport.html but it doesn't seem to work on this device.

I start the connection on another thread and kill it if the timer fires but there is no way to kill the thread before it finishes executing in J2ME at http://developers.sun.com/mobility/midp/articles/threading2/ (this is an embedded device so I can't just leave an indefinite number of thread locks in the background). I cannot use a logical poll as this is the only attempt to open a blocked connection.

The system timeout appears to be device modality dependent and too long for my purposes.

Does anyone have any thoughts on what might work?

+2


source to share


3 answers


I ended up using a Socket class that has a setSoTimeout () method.



+2


source


I may note that I made changes in KSoap2 v2.5.2 to support timeout for the HttpTransportSE class. It will throw a SocketTimeoutException when a timeout occurs.



He and jar and src are at this url http://www.lightsoft.se/?p=707

+2


source


Keep in mind that you are not dealing with fully functional computers. On some devices, you simply cannot interrupt network operations, especially a TCP connection.

This is what we do

  • Before making the connection, create another monitoring timer thread on a short frequency (say 2 seconds).
  • In a monitoring thread, you can send some message to the device pretending to make progress if the time limit is not reached.
  • If a certain deadline is reached, try interrupting another thread by sending Thread.interrupt (). This call is available in MIDP.
  • In the connection flow, just close if aborted.

This works fine on all emulators, but the connection thread doesn't get exceptions until 5 minutes later on some phones.

+1


source







All Articles