Java 与主机获取 ConnectionTimeoutException 未在超时内接受连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2586307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 09:32:19  来源:igfitidea点击:

Getting ConnectionTimeoutException with the host did not accept the connection within timeout

javaspring-remoting

提问by Sanjana

Can Some one Help me, how we can solve the following problem.

有人可以帮助我,我们如何解决以下问题。

nested
exception is org.apache.commons.httpclient.ConnectTimeoutException: The host did
not accept the connection within timeout of 10000 ms
        at
org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:211)
        at
org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:144)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy19.isEmployeeToken(Unknown Source)
        at
com.clickandbuy.webapps.surfer.commons.ContextUtils.isEmployeeToken(ContextUtils.java:375)
        at
com.clickandbuy.webapps.surfer.commons.ContextUtils.validateLogin(ContextUtils.java:248)
        at sun.reflect.GeneratedMethodAccessor1364.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:274)
        at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
        at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
        at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at
org.springframework.binding.expression.el.BindingValueExpression.getValue(BindingValueExpression.java:54)
        at
org.springframework.binding.expression.el.ELExpression.getValue(ELExpression.java:54)
        at
org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:77)
        at
org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
        at
org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145)
        at
org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
        at
org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:101)
        at org.springframework.webflow.engine.State.enter(State.java:194)
        at org.springframework.webflow.engine.Flow.start(Flow.java:535)
        at
org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:364)
        at
org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:222)
        at
org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:140)
        at
org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:193)
        at
org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:174)
        at
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
        at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
        at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
        at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
com.clickandbuy.webapps.surfer.commons.filter.LogUserIPFilter.doFilter(LogUserIPFilter.java:61)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
com.clickandbuy.webapps.surfer.commons.filter.AddHeaderFilter.doFilter(AddHeaderFilter.java:54)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
com.clickandbuy.webapps.commons.filter.SessionSizeFilter.doFilter(SessionSizeFilter.java:76)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.commons.httpclient.ConnectTimeoutException: The host did
not accept the connection within timeout of 10000 ms
        at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:155)
        at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
        at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
        at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
        at
org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.executePostMethod(CommonsHttpInvokerRequestExecutor.java:195)
        at
org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.doExecuteRequest(CommonsHttpInvokerRequestExecutor.java:129)
        at
org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:136)
        at
org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:191)
        at
org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:173)
        at
org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:141)
        ... 57 more
Caused by: java.net.SocketTimeoutException: connect timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at sun.reflect.GeneratedMethodAccessor284.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
        ... 70 more

My confiugration is as follows....

我的配置如下......

<bean id="loginManagerHttpInvoker" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
        <property name="serviceUrl" value="service url" />
        <property name="serviceInterface" value="service interface" />
        <property name="httpInvokerRequestExecutor">
            <bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor">
                <property name="httpClient">
                    <bean class="org.apache.commons.httpclient.HttpClient">
                        <property name="httpConnectionManager">
                            <bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager">
                                <property name="params">
                                    <bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams">
                                        <property name="connectionTimeout"><value>10000</value></property>
                                        <property name="defaultMaxConnectionsPerHost"><value>150</value></property>
                                        <property name="maxTotalConnections"><value>150</value></property>
                                        <property name="staleCheckingEnabled" value="true" />
                                        <property name="linger" value="-1" />
                                        <property name="soTimeout"><value>60000</value></property>
                                    </bean>
                                </property>
                            </bean>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

After the server restart everything is working fine. And I could able to connect to server. What could be the problem, It happend only one time, I have never seen this before... Same configuration nothing changed....

服务器重启后一切正常。我可以连接到服务器。可能是什么问题,它只发生过一次,我以前从未见过...相同的配置没有改变....

Thanks In Advance

提前致谢

Sanjana

桑佳娜

回答by Kevin Brock

Your program will get a ConnectionTimeoutExceptionwhenever the server side does not "exist". A timeout of 10 seconds (10000 ms) is sufficient to work in most cases to connect between any processes even when located far apart (high latency).

ConnectionTimeoutException只要服务器端“不存在”,您的程序就会得到一个。在大多数情况下,10 秒(10000 毫秒)的超时足以在任何进程之间进行连接,即使它们相距很远(高延迟)。

There are many reasons why the client cannot get a connection:

客户端无法获得连接的原因有很多:

  • The server process is not running.
  • The server process is not accepting connections.
  • The address or port that the client process used to connect is not correct.
  • Route to the server is not valid
  • 服务器进程没有运行。
  • 服务器进程不接受连接。
  • 客户端进程用于连接的地址或端口不正确。
  • 到服务器的路由无效

Typically, though these result in quick failure responses because the server operating system or some router is able to respond with a failure. Here are some more that may apply directly to your situation:

通常,尽管这些会导致快速的故障响应,因为服务器操作系统或某些路由器能够响应故障。以下是一些可能直接适用于您的情况的更多信息:

  • Server physically off
  • Server or server process hung
  • Server physically disconnected from the network
  • Invalid destination address and the address does not exist on the network
  • Firewall rules blocking the outgoing route from the client
  • Firewall rules blocking the incoming route to the server
  • 服务器物理关闭
  • 服务器或服务器进程挂起
  • 服务器与网络物理断开
  • 目标地址无效且该地址在网络上不存在
  • 防火墙规则阻止来自客户端的传出路由
  • 防火墙规则阻止到服务器的传入路由

These kinds of problems usually result in the time out exception because there is no return message (the client operating system just has to give up and that is the reasons for having a timeout).

这类问题通常会导致超时异常,因为没有返回消息(客户端操作系统只需要放弃,这就是超时的原因)。

This list may not be complete but may help you in troubleshooting your problem. If you can provide additional information about your configuration and network and what you specifically would like help resolving, someone here should be able to give you more specific assistance.

此列表可能不完整,但可以帮助您解决问题。如果您可以提供有关您的配置和网络的其他信息以及您特别希望帮助解决的问题,这里的某个人应该能够为您提供更具体的帮助。