1

I have this odd error: I even had put a limitless timeout trying to solve it. I say this is odd because it used to work just fine, but now, it does not work and I dont know the reason. The error:

09-05 22:40:04.930: W/IInputConnectionWrapper(820): showStatusIcon on inactive InputConnection
09-05 22:43:26.901: E/ServicioRest(881): Error en listar!
09-05 22:43:26.901: E/ServicioRest(881): java.net.SocketException: The operation timed out
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
09-05 22:43:26.901: E/ServicioRest(881):    at java.net.Socket.connect(Socket.java:1055)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-05 22:43:26.901: E/ServicioRest(881):    at com.example.interviewhelpers.ClientDetailActivity.onCreateView(ClientDetailActivity.java:72)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.Activity.performStart(Activity.java:3781)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-05 22:43:26.901: E/ServicioRest(881):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 22:43:26.901: E/ServicioRest(881):    at android.os.Looper.loop(Looper.java:123)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.main(ActivityThread.java:4627)
09-05 22:43:26.901: E/ServicioRest(881):    at java.lang.reflect.Method.invokeNative(Native Method)
09-05 22:43:26.901: E/ServicioRest(881):    at java.lang.reflect.Method.invoke(Method.java:521)
09-05 22:43:26.901: E/ServicioRest(881):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-05 22:43:26.901: E/ServicioRest(881):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-05 22:43:26.901: E/ServicioRest(881):    at dalvik.system.NativeStart.main(Native Method)

This is the method calling the web service: The last line is where eclipse tell me the problem occur.

public static final String ruta = "http://10.0.0.2:2731/Api/Usuario";

        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 0);
        HttpConnectionParams.setSoTimeout(httpParameters, 0);
        HttpConnectionParams.setTcpNoDelay(httpParameters, true);

        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpGet del = new HttpGet(ruta + "s");
        del.setHeader("content-type", "application/json");

        try {
            HttpResponse resp = httpClient.execute(del);
Sterling Diaz
  • 3,789
  • 2
  • 31
  • 35
  • 1
    Does the url 'http://10.0.0.2:2731/Api/Usuario' show any response at all when you try to browse it through a web browser ? Also, 'HttpGet del = new HttpGet(ruta + "s");' appears to concatenate a 's' to the end of the url string. So, the statement results in 'HttpGet del = new HttpGet("http://10.0.0.2:2731/Api/Usuarios");' Is that what you mean it to be ? And, are you sure that you want to set the content-type to 'application/json', especially as your request is a 'GET' request ? – sandyiscool Sep 06 '12 at 04:26
  • It's yes to all the questions. THe first one: that url in the browser does not work, but that is for the emulator. With localhost and the 's' concatenated, I can see the content. And because what the service gives me it's a json, that is why I use that content-type – Sterling Diaz Sep 06 '12 at 04:29
  • 1
    When you say 'the url in the browser does not work', do you mean that it times out too ? Or does it show any error message ? Secondly, the content-type of the data that the server returns to you is set in the response's 'content-type' header. You are most probably not sending json data in the request. So, you typically do not set that. – sandyiscool Sep 06 '12 at 04:41
  • No, I mean it does not work wrote in this way: '10.0.0.2:2731/Api/Usuarios' but in the emulador, it should work. In the browser work in this way: 'localhost:2731/Api/Usuarios'. Ok. Thanks for the information about the content type. – Sterling Diaz Sep 06 '12 at 04:47

1 Answers1

1

You had given the timeout value as 0 in your code. Instead of 0 you use the value greater than 5000(milliseconds). Ie HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 5000);

SSS
  • 683
  • 1
  • 6
  • 16
  • 1
    A value of 0 indicates infinite timeout. – sandyiscool Sep 06 '12 at 04:25
  • Now it gave me a different error.09-05 23:47:39.550: E/ServicioRest(274): org.apache.http.conn.ConnectTimeoutException: Connect to /10.0.0.2:2731 timed out – Sterling Diaz Sep 06 '12 at 04:26
  • 1
    have a look at this question http://stackoverflow.com/questions/6705170/httpclient-execute-keeps-giving-connecttimeoutexception – SSS Sep 06 '12 at 04:30
  • That's right sandyiscool. I used it for the timeout to never expire, in order to it does not give me the timeout error. – Sterling Diaz Sep 06 '12 at 04:30
  • 1
    @user1228807 : I do understand that you intend to set the timeout to never expire. I was just emphasizing that. – sandyiscool Sep 06 '12 at 04:33
  • That post I did not read Uma, even though I read a lot of similar threads. Thanks, let me try it. – Sterling Diaz Sep 06 '12 at 04:34
  • For discover if the timeout error was by lack of time to load the data. With 0 I can know that the problem it's another thing. And that why I am here right now. – Sterling Diaz Sep 06 '12 at 04:36