什么原因导致HttpHostConnectException? [英] What causes HttpHostConnectException?

查看:3274
本文介绍了什么原因导致HttpHostConnectException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索我的网站时,我有一个自动完成/前进的功能。我看到有一段时间他们是与之相关的例外。我们正在使用代理服务器。

I have a Auto Complete/type ahead feature on Search for my website. I see that some time their is an exception associated with it. We are using 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)

导致:java.net.ConnectException:连接拒绝

Caused by: java.net.ConnectException: Connection refused

这是我如何编码

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;
}

任何人都可以告诉我为什么我得到这个例外一些时间?这可能是因为我们的网站不支持来自Android应用程序的请求而从Android应用程序进行搜索请求时引起此异常。

Can any one tell me why i am getting this exception some time only? is this possible that this exception is caused when a search request is made from Android applications as our website don't support a request is being made from android applications

推荐答案

当您尝试打开TCP连接到没有任何正在侦听连接的IP地址/端口时,会发生连接被拒绝错误。如果没有听到,服务器端的操作系统拒绝连接。

A "connection refused" error happens when you attempt to open a TCP connection to an IP address / port where there is nothing currently listening for connections. If nothing is listening, the OS on the server side "refuses" the connection.

如果间歇性发生,那么最有可能的解释是(IMO):

If this is happening intermittently, then the most likely explanations are (IMO):


  • 您正在说话的服务器(proxy.xyz.com/ port 60)正在上下移动,或

  • 您的客户端和代理商之间有间断地将请求发送到不正常的主机或某些东西。


这是因为当Android应用程序进行搜索请求时引起此异常,因为我们的网站不支持从Android应用程序进行请求。

Is this possible that this exception is caused when a search request is made from Android applications as our website don't support a request is being made from android applications.

似乎不太可能。你说连接被拒绝的异常消息表示拒绝连接的代理,而不是您的服务器。此外,如果服务器不会处理某些类型的请求,它仍然必须接受TCP连接才能找到请求是什么...在它可以拒绝之前。

It seems unlikely. You said that the "connection refused" exception message says that it is the proxy that is refusing the connection, not your server. Besides if a server was going to not handle certain kinds of request, it still has to accept the TCP connection to find out what the request is ... before it can reject it.

这篇关于什么原因导致HttpHostConnectException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆