christhopherguerra / java-twitter

Automatically exported from code.google.com/p/java-twitter
Apache License 2.0
0 stars 0 forks source link

Should be able to set both Connection Timeout and Socket Timeout for the HTTPConnectionManager #12

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Since the Twitter DDoS attack, there have seemingly been some changes to 
Twitter's API 
Infrastructure. Search API requests will sometimes hang indefinitely now. This 
can be remedied 
by setting either a socket timeout on the Apache HTTPClient 
HTTPConnectionManager.

What is the expected output? What do you see instead?

Would expect that requests to the Search API would eventually timeout and not 
hang indefinitely. 
Don't know if this is mostly considered a container issue (running in  Tomcat), 
an OS level issue, 
or a java-twitter defect. IMO, no matter what the root cause, you should be 
able to set the 
connection and socket timeouts on a per request basis.

What version of the product are you using? On what operating system?

java-twitter-0.9-SNAPSHOT

Please provide any additional information below.

You should probably be able to set connection timeout and socket timeout on a 
per-request 
basis with java-twitter. I did not feel confident/familiar enough with the 
architecture of java-
twitter to expose the setting of these properties up to the request level, so 
instead, I just set 
them using java System properties inside of TwitterHttpManager like so:

public TwitterHttpManager(Builder builder) {
    authScope = builder.authScope != null ? builder.authScope : AuthScope.ANY;
    connectionManager = builder.httpConnectionManager != null
        ? builder.httpConnectionManager
        : new MultiThreadedHttpConnectionManager();
    int soTimeout = 30000;
    int connTimeout = 30000;
    if(System.getProperty("sun.net.client.defaultConnectTimeout")!=null) {
        connTimeout = 
Integer.parseInt(System.getProperty("sun.net.client.defaultConnectTimeout"));
    }
    if(System.getProperty("sun.net.client.defaultReadTimeout")!=null) {
        soTimeout = Integer.parseInt(System.getProperty("sun.net.client.defaultReadTimeout"));
    }

    connectionManager.getParams().setSoTimeout(soTimeout);
    connectionManager.getParams().setConnectionTimeout(connTimeout);
    credentials = builder.credentials;
  }

Original issue reported on code.google.com by twitcaps...@gmail.com on 15 Aug 2009 at 10:13

GoogleCodeExporter commented 8 years ago
As you can see in the code, I defaulted the timeouts to 30 seconds. But, like I 
mentioned, I wouldn't actually 
commit this as a solution, but would try to figure out how to expose the 
setting of these properties at the 
request level.

Original comment by twitcaps...@gmail.com on 15 Aug 2009 at 10:18