How to prevent dangerous KSOAP2 connection time in Android

I tried to prevent KSOAP2 from timeout when requesting data from my Axis2 web service via Android, but was unable to.

Web service background.

My web service runs on an Apache Tomcat server and is used to transmit real-time information to stations. When I try to use the browser, it works as expected, and on the website it also works as expected.

Problem

However, when I try to use the same method in my Android application, sometimes I get the following stack tracking error. In other cases, the request will be successful. From time to time, the request will time out immediately, and in other cases, it will wait about a minute before the time expires.

Devices

I tried it through Samsung Galaxy SII (platform 2.3.3) and on Samsung Galaxy SI (platform 2.2.2), using Wi-Fi and using 3G with the same results. However, when using the emulator (platform 2.2), it never expires.

My code

String NAMESPACE = "http://service.domain.ie";
String URL = "http://www.myhost.com/axis2/services/RealTime?wsdl";
String METHOD_NAME = "getStationData";
String SOAP_ACTION = "RealTime";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("stationType", getStationType());
request.addProperty("stationApiCode", getApiCode());

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport;

SoapObject response = null;

try {
        androidHttpTransport = new HttpTransportSE(URL,60000); // Tried Setting the Timeout to 1 Minute
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION,envelope);
        response = (SoapObject)envelope.bodyIn;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }

Stack trace error

04-13 13:07:18.015: W/System.err(9249): java.net.SocketTimeoutException
04-13 13:07:18.015: W/System.err(9249):     at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:461)
04-13 13:07:18.015: W/System.err(9249):     at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:85)
04-13 13:07:18.015: W/System.err(9249):     at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:65)
04-13 13:07:18.015: W/System.err(9249):     at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:140)
04-13 13:07:18.015: W/System.err(9249):     at java.io.BufferedInputStream.read(BufferedInputStream.java:225)
04-13 13:07:18.020: W/System.err(9249):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readLine(HttpURLConnectionImpl.java:660)
04-13 13:07:18.020: W/System.err(9249):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readResponseHeaders(HttpURLConnectionImpl.java:690)
04-13 13:07:18.020: W/System.err(9249):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1040)
04-13 13:07:18.020: W/System.err(9249):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)
04-13 13:07:18.020: W/System.err(9249):     at org.ksoap2.transport.ServiceConnectionSE.openInputStream(ServiceConnectionSE.java:113)
04-13 13:07:18.020: W/System.err(9249):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:160)
04-13 13:07:18.050: W/System.err(9249):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
04-13 13:07:18.050: W/System.err(9249):     at ie.smartcommuter.models.Station.getRealTimeData(Station.java:123)
04-13 13:07:18.050: W/System.err(9249):     at ie.smartcommuter.controllers.tabcontents.StationRealtimeActivity$1.run(StationRealtimeActivity.java:95)
04-13 13:07:18.050: W/System.err(9249):     at java.lang.Thread.run(Thread.java:1019)

I upgraded KSOAP2 from 2.4 to 2.5.7 and tried to set a timeout limit, but so far I have not been successful. Therefore, to answer my question:

Someone else had this problem, and if so, how did they solve it?

+3
source share
1 answer

when the timeout pin will raise a SocketTimeoutException.

you have to catch it in your try-catch and handle the timeout as you like

0
source

All Articles