You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Eugene Dvorkin <Eu...@ARTstor.org> on 2012/05/07 20:42:16 UTC

HTTPClient stops working and produce java.net.ConnectException: Connection timed out exception

I have a client application that makes http calls to another servers 
using http client library (httpclient-4.1.3.jar) . Application was 
deployed to 5 servers and it was working for a while. All those 5 
servers are behind load balancer and firewall in data center. This 
application is a web application using Spring framework.  The end point, 
to where the application is making http requests, are deployed on Amazon 
EC2 instances behind amazon load balancer.
Today I start experience problems:

12/05/07 10:03:48 java.net.ConnectException: Connection timed out
12/05/07 10:03:48       at java.net.PlainSocketImpl.socketConnect(Native 
Method)
12/05/07 10:03:48       at 
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
12/05/07 10:03:48       at 
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
12/05/07 10:03:48       at 
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
12/05/07 10:03:48       at 
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:507)
12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:457)
12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:365)
12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:238)
12/05/07 10:03:48       at 
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
:79)
12/05/07 10:03:48       at 
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
:121)
12/05/07 10:03:48       at 
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
12/05/07 10:03:48       at 
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
12/05/07 10:03:48       at 
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
12/05/07 10:03:48       at 
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
12/05/07 10:03:48       at 
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
12/05/07 10:03:48       at 
org.artstor.security.acegi.ui.SamlAuthenticationProcessingFilter.makeHttpsRequest(SamlAuthenticationProcessingFilt
er.java:377)

On receiving end, I don't see any log in Apache access logs.
If I do curl to the same URL, It works fine. Nobody changed any 
configuration or anything like that.
How can I drill down and debug the issue? It makes more complicated 
because it is on production server but this functionality is not 
released yet.
Any ideas?
httpclient-4.1.3.jar
httpclient-cache-4.1.3.jar
httpcore-4.1.4.jar
httpmime-4.1.3.jar


Our code:
public byte[] makeHttpsRequest(String url) {
         byte[] responseBody = null;


         HttpClient httpClient=new HttpClient();

         HttpMethod method = new GetMethod(url);

         HttpMethodRetryHandler myretryhandler = new 
HttpMethodRetryHandler() {
             public boolean retryMethod(
                 final HttpMethod method,
                 final IOException exception,
                 int executionCount) {
                 if (executionCount >= 3) {
                     // Do not retry if over max retry count
                     return false;
                 }
                 if (exception instanceof NoHttpResponseException) {
                     // Retry if the server dropped connection on us
                     return true;
                 }
                 if (exception instanceof IOException) {
                                     // Retry if read timeout happens
                      return true;
                                 }
                 if (!method.isRequestSent()) {
                     // Retry if the request has not been sent fully or
                     // if it's OK to retry methods that have been sent
                     return true;
                 }
                 // otherwise do not retry
                 return false;
             }
         };




         // Provide custom retry handler is necessary
         
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,myretryhandler);

             try {
                 HttpClientParams param=new HttpClientParams();
                 param.setSoTimeout(3000);
                 httpClient.setParams(param);
                 method.addRequestHeader("Accept", 
"text/html,application/xhtml+xml,application/xml,application/json");
                 // Provide custom retry handler is necessary
                 
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                         new DefaultHttpMethodRetryHandler(3, false));

                 int statusCode = httpClient.executeMethod(method);
                 if (statusCode != HttpStatus.SC_OK) {
                     System.err.println("Method failed: " + 
method.getStatusLine());
                   }



                     responseBody = method.getResponseBody();

             } catch (SocketTimeoutException e) {

                 System.err.println("can't connect to shibboleth server: "
                                     + e.getMessage());
                             e.printStackTrace();
             } catch (IOException e) {

                 System.err.println("can't connect to shibboleth server: "
                         + e.getMessage());
                 e.printStackTrace();



             } finally {
                 // When HttpClient instance is no longer needed,
                 // shut down the connection manager to ensure
                 // immediate deallocation of all system resources

                 method.releaseConnection();
             }


         return responseBody;
     }













---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: HTTPClient stops working and produce java.net.ConnectException: Connection timed out exception

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2012-05-07 at 18:42 +0000, Eugene Dvorkin wrote:
> I have a client application that makes http calls to another servers 
> using http client library (httpclient-4.1.3.jar) 

Just for the record, please note you are not using HttpClient 4.1.3.
Judging by the stack trace and the code sample you are using an older,
deprecated version (Commons HttpClient 3.x) 

Oleg

> . Application was 
> deployed to 5 servers and it was working for a while. All those 5 
> servers are behind load balancer and firewall in data center. This 
> application is a web application using Spring framework.  The end point, 
> to where the application is making http requests, are deployed on Amazon 
> EC2 instances behind amazon load balancer.
> Today I start experience problems:
> 
> 12/05/07 10:03:48 java.net.ConnectException: Connection timed out
> 12/05/07 10:03:48       at java.net.PlainSocketImpl.socketConnect(Native 
> Method)
> 12/05/07 10:03:48       at 
> java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> 12/05/07 10:03:48       at 
> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> 12/05/07 10:03:48       at 
> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> 12/05/07 10:03:48       at 
> java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:507)
> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:457)
> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:365)
> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:238)
> 12/05/07 10:03:48       at 
> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
> :79)
> 12/05/07 10:03:48       at 
> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
> :121)
> 12/05/07 10:03:48       at 
> org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
> 12/05/07 10:03:48       at 
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
> 12/05/07 10:03:48       at 
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
> 12/05/07 10:03:48       at 
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
> 12/05/07 10:03:48       at 
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> 12/05/07 10:03:48       at 
> org.artstor.security.acegi.ui.SamlAuthenticationProcessingFilter.makeHttpsRequest(SamlAuthenticationProcessingFilt
> er.java:377)
> 
> On receiving end, I don't see any log in Apache access logs.
> If I do curl to the same URL, It works fine. Nobody changed any 
> configuration or anything like that.
> How can I drill down and debug the issue? It makes more complicated 
> because it is on production server but this functionality is not 
> released yet.
> Any ideas?
> httpclient-4.1.3.jar
> httpclient-cache-4.1.3.jar
> httpcore-4.1.4.jar
> httpmime-4.1.3.jar
> 
> 
> Our code:
> public byte[] makeHttpsRequest(String url) {
>          byte[] responseBody = null;
> 
> 
>          HttpClient httpClient=new HttpClient();
> 
>          HttpMethod method = new GetMethod(url);
> 
>          HttpMethodRetryHandler myretryhandler = new 
> HttpMethodRetryHandler() {
>              public boolean retryMethod(
>                  final HttpMethod method,
>                  final IOException exception,
>                  int executionCount) {
>                  if (executionCount >= 3) {
>                      // Do not retry if over max retry count
>                      return false;
>                  }
>                  if (exception instanceof NoHttpResponseException) {
>                      // Retry if the server dropped connection on us
>                      return true;
>                  }
>                  if (exception instanceof IOException) {
>                                      // Retry if read timeout happens
>                       return true;
>                                  }
>                  if (!method.isRequestSent()) {
>                      // Retry if the request has not been sent fully or
>                      // if it's OK to retry methods that have been sent
>                      return true;
>                  }
>                  // otherwise do not retry
>                  return false;
>              }
>          };
> 
> 
> 
> 
>          // Provide custom retry handler is necessary
>          
> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,myretryhandler);
> 
>              try {
>                  HttpClientParams param=new HttpClientParams();
>                  param.setSoTimeout(3000);
>                  httpClient.setParams(param);
>                  method.addRequestHeader("Accept", 
> "text/html,application/xhtml+xml,application/xml,application/json");
>                  // Provide custom retry handler is necessary
>                  
> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>                          new DefaultHttpMethodRetryHandler(3, false));
> 
>                  int statusCode = httpClient.executeMethod(method);
>                  if (statusCode != HttpStatus.SC_OK) {
>                      System.err.println("Method failed: " + 
> method.getStatusLine());
>                    }
> 
> 
> 
>                      responseBody = method.getResponseBody();
> 
>              } catch (SocketTimeoutException e) {
> 
>                  System.err.println("can't connect to shibboleth server: "
>                                      + e.getMessage());
>                              e.printStackTrace();
>              } catch (IOException e) {
> 
>                  System.err.println("can't connect to shibboleth server: "
>                          + e.getMessage());
>                  e.printStackTrace();
> 
> 
> 
>              } finally {
>                  // When HttpClient instance is no longer needed,
>                  // shut down the connection manager to ensure
>                  // immediate deallocation of all system resources
> 
>                  method.releaseConnection();
>              }
> 
> 
>          return responseBody;
>      }
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: [Junk released by Allowed List] Re: HTTPClient stops working and produce java.net.ConnectException: Connection timed out exception

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2012-05-07 at 20:39 +0000, Eugene Dvorkin wrote:
> Hi Oleg,
> thanks. I will investigate.
> But is it matter in this particular case?
> 
> 

Ii might or it might not. The simple truth is I _personally_ have no
bandwidth for looking into problems with deprecated versions of
HttpClient.

Oleg


> On 05/07/2012 03:01 PM, Sam Crawford wrote:
> > I would suggest enabling wire-level debugging to get a clearer picture
> > of what is taking place (see
> > http://hc.apache.org/httpcomponents-client-ga/logging.html)
> >
> > That said, the symptoms lead me to think that you're running into
> > Java's DNS caching behaviour. Amazon elastic load balancers frequently
> > change IP address, and have a low TTL in DNS accordingly. Depending on
> > your Java version and configuration, you may be caching DNS records
> > indefinitely. If this was the case, then your JVM may have cached an
> > old IP address for your Amazon ELB and HttpClient is dutifully trying
> > to connect to this old IP address that is no longer running your
> > remote service.
> >
> > You could verify this on your production server (in a non-invasive
> > way) by running tcpdump to look at what IP address your application is
> > trying to connect to.
> >
> > Java 6 DNS options are detailed at
> > http://docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html
> > (networkaddress.cache.ttl is the property in particular I'm referring
> > to).
> >
> > Hope this helps,
> >
> > Sam
> >
> >
> > On 7 May 2012 19:42, Eugene Dvorkin<Eu...@artstor.org>  wrote:
> >> I have a client application that makes http calls to another servers
> >> using http client library (httpclient-4.1.3.jar) . Application was
> >> deployed to 5 servers and it was working for a while. All those 5
> >> servers are behind load balancer and firewall in data center. This
> >> application is a web application using Spring framework.  The end point,
> >> to where the application is making http requests, are deployed on Amazon
> >> EC2 instances behind amazon load balancer.
> >> Today I start experience problems:
> >>
> >> 12/05/07 10:03:48 java.net.ConnectException: Connection timed out
> >> 12/05/07 10:03:48       at java.net.PlainSocketImpl.socketConnect(Native
> >> Method)
> >> 12/05/07 10:03:48       at
> >> java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> >> 12/05/07 10:03:48       at
> >> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> >> 12/05/07 10:03:48       at
> >> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> >> 12/05/07 10:03:48       at
> >> java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
> >> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:507)
> >> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:457)
> >> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:365)
> >> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:238)
> >> 12/05/07 10:03:48       at
> >> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
> >> :79)
> >> 12/05/07 10:03:48       at
> >> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
> >> :121)
> >> 12/05/07 10:03:48       at
> >> org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
> >> 12/05/07 10:03:48       at
> >> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
> >> 12/05/07 10:03:48       at
> >> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
> >> 12/05/07 10:03:48       at
> >> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
> >> 12/05/07 10:03:48       at
> >> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> >> 12/05/07 10:03:48       at
> >> org.artstor.security.acegi.ui.SamlAuthenticationProcessingFilter.makeHttpsRequest(SamlAuthenticationProcessingFilt
> >> er.java:377)
> >>
> >> On receiving end, I don't see any log in Apache access logs.
> >> If I do curl to the same URL, It works fine. Nobody changed any
> >> configuration or anything like that.
> >> How can I drill down and debug the issue? It makes more complicated
> >> because it is on production server but this functionality is not
> >> released yet.
> >> Any ideas?
> >> httpclient-4.1.3.jar
> >> httpclient-cache-4.1.3.jar
> >> httpcore-4.1.4.jar
> >> httpmime-4.1.3.jar
> >>
> >>
> >> Our code:
> >> public byte[] makeHttpsRequest(String url) {
> >>          byte[] responseBody = null;
> >>
> >>
> >>          HttpClient httpClient=new HttpClient();
> >>
> >>          HttpMethod method = new GetMethod(url);
> >>
> >>          HttpMethodRetryHandler myretryhandler = new
> >> HttpMethodRetryHandler() {
> >>              public boolean retryMethod(
> >>                  final HttpMethod method,
> >>                  final IOException exception,
> >>                  int executionCount) {
> >>                  if (executionCount>= 3) {
> >>                      // Do not retry if over max retry count
> >>                      return false;
> >>                  }
> >>                  if (exception instanceof NoHttpResponseException) {
> >>                      // Retry if the server dropped connection on us
> >>                      return true;
> >>                  }
> >>                  if (exception instanceof IOException) {
> >>                                      // Retry if read timeout happens
> >>                       return true;
> >>                                  }
> >>                  if (!method.isRequestSent()) {
> >>                      // Retry if the request has not been sent fully or
> >>                      // if it's OK to retry methods that have been sent
> >>                      return true;
> >>                  }
> >>                  // otherwise do not retry
> >>                  return false;
> >>              }
> >>          };
> >>
> >>
> >>
> >>
> >>          // Provide custom retry handler is necessary
> >>
> >> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,myretryhandler);
> >>
> >>              try {
> >>                  HttpClientParams param=new HttpClientParams();
> >>                  param.setSoTimeout(3000);
> >>                  httpClient.setParams(param);
> >>                  method.addRequestHeader("Accept",
> >> "text/html,application/xhtml+xml,application/xml,application/json");
> >>                  // Provide custom retry handler is necessary
> >>
> >> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
> >>                          new DefaultHttpMethodRetryHandler(3, false));
> >>
> >>                  int statusCode = httpClient.executeMethod(method);
> >>                  if (statusCode != HttpStatus.SC_OK) {
> >>                      System.err.println("Method failed: " +
> >> method.getStatusLine());
> >>                    }
> >>
> >>
> >>
> >>                      responseBody = method.getResponseBody();
> >>
> >>              } catch (SocketTimeoutException e) {
> >>
> >>                  System.err.println("can't connect to shibboleth server: "
> >>                                      + e.getMessage());
> >>                              e.printStackTrace();
> >>              } catch (IOException e) {
> >>
> >>                  System.err.println("can't connect to shibboleth server: "
> >>                          + e.getMessage());
> >>                  e.printStackTrace();
> >>
> >>
> >>
> >>              } finally {
> >>                  // When HttpClient instance is no longer needed,
> >>                  // shut down the connection manager to ensure
> >>                  // immediate deallocation of all system resources
> >>
> >>                  method.releaseConnection();
> >>              }
> >>
> >>
> >>          return responseBody;
> >>      }
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: [Junk released by Allowed List] Re: HTTPClient stops working and produce java.net.ConnectException: Connection timed out exception

Posted by Eugene Dvorkin <Eu...@ARTstor.org>.
Hi Oleg,
thanks. I will investigate.
But is it matter in this particular case?


On 05/07/2012 03:01 PM, Sam Crawford wrote:
> I would suggest enabling wire-level debugging to get a clearer picture
> of what is taking place (see
> http://hc.apache.org/httpcomponents-client-ga/logging.html)
>
> That said, the symptoms lead me to think that you're running into
> Java's DNS caching behaviour. Amazon elastic load balancers frequently
> change IP address, and have a low TTL in DNS accordingly. Depending on
> your Java version and configuration, you may be caching DNS records
> indefinitely. If this was the case, then your JVM may have cached an
> old IP address for your Amazon ELB and HttpClient is dutifully trying
> to connect to this old IP address that is no longer running your
> remote service.
>
> You could verify this on your production server (in a non-invasive
> way) by running tcpdump to look at what IP address your application is
> trying to connect to.
>
> Java 6 DNS options are detailed at
> http://docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html
> (networkaddress.cache.ttl is the property in particular I'm referring
> to).
>
> Hope this helps,
>
> Sam
>
>
> On 7 May 2012 19:42, Eugene Dvorkin<Eu...@artstor.org>  wrote:
>> I have a client application that makes http calls to another servers
>> using http client library (httpclient-4.1.3.jar) . Application was
>> deployed to 5 servers and it was working for a while. All those 5
>> servers are behind load balancer and firewall in data center. This
>> application is a web application using Spring framework.  The end point,
>> to where the application is making http requests, are deployed on Amazon
>> EC2 instances behind amazon load balancer.
>> Today I start experience problems:
>>
>> 12/05/07 10:03:48 java.net.ConnectException: Connection timed out
>> 12/05/07 10:03:48       at java.net.PlainSocketImpl.socketConnect(Native
>> Method)
>> 12/05/07 10:03:48       at
>> java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
>> 12/05/07 10:03:48       at
>> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
>> 12/05/07 10:03:48       at
>> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
>> 12/05/07 10:03:48       at
>> java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
>> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:507)
>> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:457)
>> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:365)
>> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:238)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
>> :79)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
>> :121)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
>> 12/05/07 10:03:48       at
>> org.artstor.security.acegi.ui.SamlAuthenticationProcessingFilter.makeHttpsRequest(SamlAuthenticationProcessingFilt
>> er.java:377)
>>
>> On receiving end, I don't see any log in Apache access logs.
>> If I do curl to the same URL, It works fine. Nobody changed any
>> configuration or anything like that.
>> How can I drill down and debug the issue? It makes more complicated
>> because it is on production server but this functionality is not
>> released yet.
>> Any ideas?
>> httpclient-4.1.3.jar
>> httpclient-cache-4.1.3.jar
>> httpcore-4.1.4.jar
>> httpmime-4.1.3.jar
>>
>>
>> Our code:
>> public byte[] makeHttpsRequest(String url) {
>>          byte[] responseBody = null;
>>
>>
>>          HttpClient httpClient=new HttpClient();
>>
>>          HttpMethod method = new GetMethod(url);
>>
>>          HttpMethodRetryHandler myretryhandler = new
>> HttpMethodRetryHandler() {
>>              public boolean retryMethod(
>>                  final HttpMethod method,
>>                  final IOException exception,
>>                  int executionCount) {
>>                  if (executionCount>= 3) {
>>                      // Do not retry if over max retry count
>>                      return false;
>>                  }
>>                  if (exception instanceof NoHttpResponseException) {
>>                      // Retry if the server dropped connection on us
>>                      return true;
>>                  }
>>                  if (exception instanceof IOException) {
>>                                      // Retry if read timeout happens
>>                       return true;
>>                                  }
>>                  if (!method.isRequestSent()) {
>>                      // Retry if the request has not been sent fully or
>>                      // if it's OK to retry methods that have been sent
>>                      return true;
>>                  }
>>                  // otherwise do not retry
>>                  return false;
>>              }
>>          };
>>
>>
>>
>>
>>          // Provide custom retry handler is necessary
>>
>> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,myretryhandler);
>>
>>              try {
>>                  HttpClientParams param=new HttpClientParams();
>>                  param.setSoTimeout(3000);
>>                  httpClient.setParams(param);
>>                  method.addRequestHeader("Accept",
>> "text/html,application/xhtml+xml,application/xml,application/json");
>>                  // Provide custom retry handler is necessary
>>
>> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>>                          new DefaultHttpMethodRetryHandler(3, false));
>>
>>                  int statusCode = httpClient.executeMethod(method);
>>                  if (statusCode != HttpStatus.SC_OK) {
>>                      System.err.println("Method failed: " +
>> method.getStatusLine());
>>                    }
>>
>>
>>
>>                      responseBody = method.getResponseBody();
>>
>>              } catch (SocketTimeoutException e) {
>>
>>                  System.err.println("can't connect to shibboleth server: "
>>                                      + e.getMessage());
>>                              e.printStackTrace();
>>              } catch (IOException e) {
>>
>>                  System.err.println("can't connect to shibboleth server: "
>>                          + e.getMessage());
>>                  e.printStackTrace();
>>
>>
>>
>>              } finally {
>>                  // When HttpClient instance is no longer needed,
>>                  // shut down the connection manager to ensure
>>                  // immediate deallocation of all system resources
>>
>>                  method.releaseConnection();
>>              }
>>
>>
>>          return responseBody;
>>      }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: [Junk released by Allowed List] Re: HTTPClient stops working and produce java.net.ConnectException: Connection timed out exception

Posted by Eugene Dvorkin <Eu...@ARTstor.org>.
I was trying to use snoop instead of tcpdumb because it is solaris 
platform.
The problem is, I don't capture any communication at all! I see 
communications for wget and curl, but not this one.
I checked usage of snoop and pretty sure I use it correctly.
Is it possible with httpclient?


On 05/07/2012 03:01 PM, Sam Crawford wrote:
> I would suggest enabling wire-level debugging to get a clearer picture
> of what is taking place (see
> http://hc.apache.org/httpcomponents-client-ga/logging.html)
>
> That said, the symptoms lead me to think that you're running into
> Java's DNS caching behaviour. Amazon elastic load balancers frequently
> change IP address, and have a low TTL in DNS accordingly. Depending on
> your Java version and configuration, you may be caching DNS records
> indefinitely. If this was the case, then your JVM may have cached an
> old IP address for your Amazon ELB and HttpClient is dutifully trying
> to connect to this old IP address that is no longer running your
> remote service.
>
> You could verify this on your production server (in a non-invasive
> way) by running tcpdump to look at what IP address your application is
> trying to connect to.
>
> Java 6 DNS options are detailed at
> http://docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html
> (networkaddress.cache.ttl is the property in particular I'm referring
> to).
>
> Hope this helps,
>
> Sam
>
>
> On 7 May 2012 19:42, Eugene Dvorkin<Eu...@artstor.org>  wrote:
>> I have a client application that makes http calls to another servers
>> using http client library (httpclient-4.1.3.jar) . Application was
>> deployed to 5 servers and it was working for a while. All those 5
>> servers are behind load balancer and firewall in data center. This
>> application is a web application using Spring framework.  The end point,
>> to where the application is making http requests, are deployed on Amazon
>> EC2 instances behind amazon load balancer.
>> Today I start experience problems:
>>
>> 12/05/07 10:03:48 java.net.ConnectException: Connection timed out
>> 12/05/07 10:03:48       at java.net.PlainSocketImpl.socketConnect(Native
>> Method)
>> 12/05/07 10:03:48       at
>> java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
>> 12/05/07 10:03:48       at
>> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
>> 12/05/07 10:03:48       at
>> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
>> 12/05/07 10:03:48       at
>> java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
>> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:507)
>> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:457)
>> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:365)
>> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:238)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
>> :79)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
>> :121)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
>> 12/05/07 10:03:48       at
>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
>> 12/05/07 10:03:48       at
>> org.artstor.security.acegi.ui.SamlAuthenticationProcessingFilter.makeHttpsRequest(SamlAuthenticationProcessingFilt
>> er.java:377)
>>
>> On receiving end, I don't see any log in Apache access logs.
>> If I do curl to the same URL, It works fine. Nobody changed any
>> configuration or anything like that.
>> How can I drill down and debug the issue? It makes more complicated
>> because it is on production server but this functionality is not
>> released yet.
>> Any ideas?
>> httpclient-4.1.3.jar
>> httpclient-cache-4.1.3.jar
>> httpcore-4.1.4.jar
>> httpmime-4.1.3.jar
>>
>>
>> Our code:
>> public byte[] makeHttpsRequest(String url) {
>>          byte[] responseBody = null;
>>
>>
>>          HttpClient httpClient=new HttpClient();
>>
>>          HttpMethod method = new GetMethod(url);
>>
>>          HttpMethodRetryHandler myretryhandler = new
>> HttpMethodRetryHandler() {
>>              public boolean retryMethod(
>>                  final HttpMethod method,
>>                  final IOException exception,
>>                  int executionCount) {
>>                  if (executionCount>= 3) {
>>                      // Do not retry if over max retry count
>>                      return false;
>>                  }
>>                  if (exception instanceof NoHttpResponseException) {
>>                      // Retry if the server dropped connection on us
>>                      return true;
>>                  }
>>                  if (exception instanceof IOException) {
>>                                      // Retry if read timeout happens
>>                       return true;
>>                                  }
>>                  if (!method.isRequestSent()) {
>>                      // Retry if the request has not been sent fully or
>>                      // if it's OK to retry methods that have been sent
>>                      return true;
>>                  }
>>                  // otherwise do not retry
>>                  return false;
>>              }
>>          };
>>
>>
>>
>>
>>          // Provide custom retry handler is necessary
>>
>> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,myretryhandler);
>>
>>              try {
>>                  HttpClientParams param=new HttpClientParams();
>>                  param.setSoTimeout(3000);
>>                  httpClient.setParams(param);
>>                  method.addRequestHeader("Accept",
>> "text/html,application/xhtml+xml,application/xml,application/json");
>>                  // Provide custom retry handler is necessary
>>
>> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>>                          new DefaultHttpMethodRetryHandler(3, false));
>>
>>                  int statusCode = httpClient.executeMethod(method);
>>                  if (statusCode != HttpStatus.SC_OK) {
>>                      System.err.println("Method failed: " +
>> method.getStatusLine());
>>                    }
>>
>>
>>
>>                      responseBody = method.getResponseBody();
>>
>>              } catch (SocketTimeoutException e) {
>>
>>                  System.err.println("can't connect to shibboleth server: "
>>                                      + e.getMessage());
>>                              e.printStackTrace();
>>              } catch (IOException e) {
>>
>>                  System.err.println("can't connect to shibboleth server: "
>>                          + e.getMessage());
>>                  e.printStackTrace();
>>
>>
>>
>>              } finally {
>>                  // When HttpClient instance is no longer needed,
>>                  // shut down the connection manager to ensure
>>                  // immediate deallocation of all system resources
>>
>>                  method.releaseConnection();
>>              }
>>
>>
>>          return responseBody;
>>      }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: HTTPClient stops working and produce java.net.ConnectException: Connection timed out exception

Posted by Sam Crawford <sa...@gmail.com>.
I would suggest enabling wire-level debugging to get a clearer picture
of what is taking place (see
http://hc.apache.org/httpcomponents-client-ga/logging.html)

That said, the symptoms lead me to think that you're running into
Java's DNS caching behaviour. Amazon elastic load balancers frequently
change IP address, and have a low TTL in DNS accordingly. Depending on
your Java version and configuration, you may be caching DNS records
indefinitely. If this was the case, then your JVM may have cached an
old IP address for your Amazon ELB and HttpClient is dutifully trying
to connect to this old IP address that is no longer running your
remote service.

You could verify this on your production server (in a non-invasive
way) by running tcpdump to look at what IP address your application is
trying to connect to.

Java 6 DNS options are detailed at
http://docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html
(networkaddress.cache.ttl is the property in particular I'm referring
to).

Hope this helps,

Sam


On 7 May 2012 19:42, Eugene Dvorkin <Eu...@artstor.org> wrote:
> I have a client application that makes http calls to another servers
> using http client library (httpclient-4.1.3.jar) . Application was
> deployed to 5 servers and it was working for a while. All those 5
> servers are behind load balancer and firewall in data center. This
> application is a web application using Spring framework.  The end point,
> to where the application is making http requests, are deployed on Amazon
> EC2 instances behind amazon load balancer.
> Today I start experience problems:
>
> 12/05/07 10:03:48 java.net.ConnectException: Connection timed out
> 12/05/07 10:03:48       at java.net.PlainSocketImpl.socketConnect(Native
> Method)
> 12/05/07 10:03:48       at
> java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> 12/05/07 10:03:48       at
> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> 12/05/07 10:03:48       at
> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> 12/05/07 10:03:48       at
> java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:507)
> 12/05/07 10:03:48       at java.net.Socket.connect(Socket.java:457)
> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:365)
> 12/05/07 10:03:48       at java.net.Socket.<init>(Socket.java:238)
> 12/05/07 10:03:48       at
> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
> :79)
> 12/05/07 10:03:48       at
> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java
> :121)
> 12/05/07 10:03:48       at
> org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
> 12/05/07 10:03:48       at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
> 12/05/07 10:03:48       at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
> 12/05/07 10:03:48       at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
> 12/05/07 10:03:48       at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> 12/05/07 10:03:48       at
> org.artstor.security.acegi.ui.SamlAuthenticationProcessingFilter.makeHttpsRequest(SamlAuthenticationProcessingFilt
> er.java:377)
>
> On receiving end, I don't see any log in Apache access logs.
> If I do curl to the same URL, It works fine. Nobody changed any
> configuration or anything like that.
> How can I drill down and debug the issue? It makes more complicated
> because it is on production server but this functionality is not
> released yet.
> Any ideas?
> httpclient-4.1.3.jar
> httpclient-cache-4.1.3.jar
> httpcore-4.1.4.jar
> httpmime-4.1.3.jar
>
>
> Our code:
> public byte[] makeHttpsRequest(String url) {
>         byte[] responseBody = null;
>
>
>         HttpClient httpClient=new HttpClient();
>
>         HttpMethod method = new GetMethod(url);
>
>         HttpMethodRetryHandler myretryhandler = new
> HttpMethodRetryHandler() {
>             public boolean retryMethod(
>                 final HttpMethod method,
>                 final IOException exception,
>                 int executionCount) {
>                 if (executionCount >= 3) {
>                     // Do not retry if over max retry count
>                     return false;
>                 }
>                 if (exception instanceof NoHttpResponseException) {
>                     // Retry if the server dropped connection on us
>                     return true;
>                 }
>                 if (exception instanceof IOException) {
>                                     // Retry if read timeout happens
>                      return true;
>                                 }
>                 if (!method.isRequestSent()) {
>                     // Retry if the request has not been sent fully or
>                     // if it's OK to retry methods that have been sent
>                     return true;
>                 }
>                 // otherwise do not retry
>                 return false;
>             }
>         };
>
>
>
>
>         // Provide custom retry handler is necessary
>
> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,myretryhandler);
>
>             try {
>                 HttpClientParams param=new HttpClientParams();
>                 param.setSoTimeout(3000);
>                 httpClient.setParams(param);
>                 method.addRequestHeader("Accept",
> "text/html,application/xhtml+xml,application/xml,application/json");
>                 // Provide custom retry handler is necessary
>
> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>                         new DefaultHttpMethodRetryHandler(3, false));
>
>                 int statusCode = httpClient.executeMethod(method);
>                 if (statusCode != HttpStatus.SC_OK) {
>                     System.err.println("Method failed: " +
> method.getStatusLine());
>                   }
>
>
>
>                     responseBody = method.getResponseBody();
>
>             } catch (SocketTimeoutException e) {
>
>                 System.err.println("can't connect to shibboleth server: "
>                                     + e.getMessage());
>                             e.printStackTrace();
>             } catch (IOException e) {
>
>                 System.err.println("can't connect to shibboleth server: "
>                         + e.getMessage());
>                 e.printStackTrace();
>
>
>
>             } finally {
>                 // When HttpClient instance is no longer needed,
>                 // shut down the connection manager to ensure
>                 // immediate deallocation of all system resources
>
>                 method.releaseConnection();
>             }
>
>
>         return responseBody;
>     }
>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org