I built an app for Android KitKat (4.4) that uses the following Apache classes:
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
I read in Android's docs that they removed compatibility with Apache HTTP Client but I would like to know what that means for apps made for previous versions. So what happens if I run my app in an Android Marshmallow (6.0) device? What issues may I face?
As a side note, I already installed my app in a device with Android 6.0 and I am facing issues regarding HTTP requests made to my server, but since I am not sure what compatibility issues may arise, I can only assume (but not be sure) that it could be related.
The issue is the following:
- When I turn on the device and my app is started by BOOT_COMPLETED broadcast, the HTTP requests made by my app to my server are successful.
- After what in my opinion can only be a random time, all the requests return the following error:
11-29 10:11:50.690 22608 22770 W System.err: org.apache.http.conn.ConnectTimeoutException: Connect to /10.56.12.131:80 timed out
11-29 10:11:50.691 22608 22770 W System.err: at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:126)
11-29 10:11:50.691 22608 22770 W System.err: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:149)
11-29 10:11:50.691 22608 22770 W System.err: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
11-29 10:11:50.692 22608 22770 W System.err: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
11-29 10:11:50.692 22608 22770 W System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366)
11-29 10:11:50.692 22608 22770 W System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
11-29 10:11:50.692 22608 22770 W System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
11-29 10:11:50.692 22608 22770 W System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
11-29 10:11:50.693 22608 22770 W System.err: at com.colaboracionvirtual.provisioningmanager.services.SynchronizationService$ServiceCall.doInBackground(SynchronizationService.java:221)
11-29 10:11:50.693 22608 22770 W System.err: at com.colaboracionvirtual.provisioningmanager.services.SynchronizationService$ServiceCall.doInBackground(SynchronizationService.java:1)
11-29 10:11:50.693 22608 22770 W System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
11-29 10:11:50.693 22608 22770 W System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-29 10:11:50.693 22608 22770 W System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
11-29 10:11:50.693 22608 22770 W System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
11-29 10:11:50.693 22608 22770 W System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
11-29 10:11:50.693 22608 22770 W System.err: at java.lang.Thread.run(Thread.java:818)
Note: 10.56.12.131:80 is the IP address and port of my Web server
Even after stopping my app with am force-stop my.app and then restarting it with am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n my.app/.receivers.BootReceiver, all HTTP requests to my server keep throwing that timeout error.
To debug the issue I played arround with netstat command and the results were the following:
- When the HTTP requests are working properly, I get the following output from netstat:
nobody@rk312x:/ # netstat -tn | grep 10.56.12.131:80
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 1 ::ffff:192.168.89.2:48752 ::ffff:10.56.12.131:80 SYN_SENT
- When the HTTP requests are throwing timeout error, I get the following output from netstat:
nobody@rk312x:/ # netstat -tn | grep :80
tcp 1 0 192.168.89.2:53676 10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:37081 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 0 0 ::ffff:192.168.89.2:38081 ::ffff:10.56.12.131:80 ESTABLISHED
tcp 1 0 ::ffff:192.168.89.2:40148 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:35892 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:45924 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:42781 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:37544 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:58794 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:56087 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:40208 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:58789 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:44985 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:50971 ::ffff:10.56.12.131:80 CLOSE_WAIT
tcp 1 0 ::ffff:192.168.89.2:49985 ::ffff:10.56.12.131:80 CLOSE_WAIT
The most strange thing is that via ADB I make a request to the server using busybox wget http://10.56.12.131/api/service/ and the result is gotten without any issues.
FYI: my app uses the libraries httpcore-4.3.2.jar, httpmime-4.3.1.jar and commons-io-2.4.jar.
from Running an APK made for Android Kitkat with HTTP Apache client in an Android Marshmallow device
No comments:
Post a Comment