Search code examples
androidodata4j

How to reduce the timeout of HTTP requests send by odata4j


I'm trying to use the odata4j library in a mobile Android app. Sometimes a HTTP request doesn't get a response because the device lost it's mobile connection just after sending the request. After a few attempts to reproduce it and timing it, I noticed it takes roughly 27 minutes for the library to throw a "java.net.SocketException: Connection timed out". Is there any way to reduce this timeout, so I can take care and handle the failure more quickly? Thanks.


Solution

  • Use the jersey consumer implementation (which is the default). Add a JerseyClientBehavior [1] when you construct your consumer. This allows you to modify the ClientConfig [2] - you can modify both the connect + read timeout.

    [1] http://code.google.com/p/odata4j/source/browse/odata4j-jersey/src/main/java/org/odata4j/jersey/consumer/behaviors/JerseyClientBehavior.java

    [2] http://jersey.java.net/nonav/apidocs/1.1.5.1/jersey/com/sun/jersey/api/client/config/ClientConfig.html