What causes an HttpHostConnectException?

I have an Auto Complete / type ahead function to search my site. I see that for some time their exclusion is connected with him. We use a proxy server.

org.apache.http.conn.HttpHostConnectException: Connection to http://proxy.xyz.com:60 refused at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:159) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554) at com.xxx.dd.sone.integration.SearchDAO.getJSONData(SearchDAO.java:60) at com.xxx.dd.sone.integration.SearchDAO.searchAutoCompleteResults(SearchDAO.java:560) at com.xxx.dd.sone.presentation.util.SearchAutoCompleteUtil.doGet(SearchAutoCompleteUtil.java:26) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at javax.servlet.http.HttpServlet.service(HttpServlet.java:845) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:352) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:236) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254) at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1512) at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255) at weblogic.work.ExecuteRequestAdapter.execute(ExecuteRequestAdapter.java:22) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:147) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:119) 

Called: java.net.ConnectException: connection rejected

This is how I encoded

 public HashMap<String, Object> getJSONData(String url)throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); try { HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSoTimeout(params, 10000); } catch (Exception e) { e.printStackTrace(); throw e; } HttpHost proxy = new HttpHost(proxy.xyz.com, 60); ConnRouteParams.setDefaultProxy(params, proxy); URI uri; InputStream data = null; uri = new URI(url); HttpGet method = new HttpGet(uri); HttpResponse response=null; try { response = httpClient.execute(method); }catch(Exception e) { e.printStackTrace(); throw e; } data = response.getEntity().getContent(); Reader r = new InputStreamReader(data); HashMap<String, Object> jsonObj = (HashMap<String, Object>) GenericJSONUtil.fromJson(r); return jsonObj; } 

Can someone tell me why I get this exception only for a while? Is it possible that this exception is caused by the fact that the search query is made from Android applications, since our site does not support the query coming from Android applications.

+10
java exception
source share
2 answers

The "connection refused" error when you try to open a TCP connection with an IP address / port where there is currently no listening on the connections. If it does not listen, the server-side OS "refuses" the connection.

If this happens intermittently, the most likely explanations are (IMO):

  • the server you are talking about ("proxy.xyz.com" / port 60) goes up and down OR
  • there is something 1 between your client and the proxy server that periodically sends requests to the idle host or something like that.

Is it possible that this exception is caused by the fact that the search query is made from Android applications, since our site does not support the query coming from Android applications.

This seems unlikely. You said that the β€œrefused” exception message says that it is a proxy server that refuses the connection, not your server. In addition, if the server will not process certain types of requests, it should still accept a TCP connection to find out what the request is ... before it can reject it.


1 - For example, it may be DNS, which cyclically resolves the DNS name for different IP addresses. Or it could be IP-based load balancing.

+24
source

In my case, the problem was missing from the HTTP url. Error: "HttpHostConnectException: connect to someendpoint.com:80 [someendpoint.com/127.0.0.1] failed: connection refused" The endpoint and IP have been explicitly changed to protect the network.

0
source

All Articles