Web services CXF java.net.ConnectException:连接超时

Web services CXF java.net.ConnectException:连接超时,web-services,cxf,soap-client,connection-timeout,Web Services,Cxf,Soap Client,Connection Timeout,当我试图从WS-client调用已部署的CXF Web服务中的方法时,连接超时。两者都使用自定义拦截器,并且由于多次调用,服务过载 Caused by: java.net.ConnectException: ConnectException invoking http://xxx.xx.xx.xx:12005/myservice/repository?wsdl: Connection timed out at sun.reflect.NativeConstructorAccessorIm

当我试图从WS-client调用已部署的CXF Web服务中的方法时,连接超时。两者都使用自定义拦截器,并且由于多次调用,服务过载

Caused by: java.net.ConnectException: ConnectException invoking http://xxx.xx.xx.xx:12005/myservice/repository?wsdl: Connection timed out
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1338)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1322)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:622)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    ... 36 more
我尝试了多种解决方案来禁用超时或增加超时,但都失败了

首先,我尝试创建一个CXF配置文件,如下所示:


然后,我使用Java系统属性
-Dcxf.config.file=/home/test/resources/cxf.xml

在日志中,我可以看到配置已被读取,因此可能已应用

信息:已加载配置文件/home/test/resources/cxf.xml

不幸的是,连接超时仍然发生

我尝试的第二个解决方案包括使用以下代码以编程方式在所有客户端上设置策略:

公共静态无效setHTTPPolicy(客户端){
httpconductor http=(httpconductor)client.getconductor();
HTTPClientPolicy HTTPClientPolicy=新的HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(0);
httpClientPolicy.setReceiveTimeout(0);
httpClientPolicy.setAsyncExecuteTimeout(0);
http.setClient(httpClientPolicy);
}
但是再次出现连接超时


我错过什么了吗?是否有其他超时需要配置?欢迎提供任何帮助。

CXF允许您为您的webservice端点配置线程池。通过这种方式,您可以满足由于请求处理资源稀缺而导致的超时。下面是使用cxf中的
选项的配置示例:

<jaxws:endpoint id="serviceBean"  implementor="#referenceToServiceBeanDefinition" address="/MyEndpointAddress">
        <jaxws:executor>
             <bean id="threadPool" class="java.util.concurrent.ThreadPoolExecutor">  
                 <!-- Minimum number of waiting threads in the pool -->
                 <constructor-arg index="0" value="2"/>
                 <!-- Maximum number of working threads in the pool -->
                 <constructor-arg index="1" value="5"/>
                 <!-- Maximum wait time for a thread to complete execution -->
                 <constructor-arg index="2" value="400000"/>
                 <!-- Unit of wait time -->
                 <constructor-arg index="3" value="#{T(java.util.concurrent.TimeUnit).MILLISECONDS}"/>
                 <!-- Storage data structure for waiting thread tasks -->
                 <constructor-arg index="4" ref="taskQueue"/>
             </bean>
         </jaxws:executor>
    </jaxws:endpoint>

    <!-- Basic data structure to temporarily hold waiting tasks-->
    <bean id="taskQueue" class="java.util.concurrent.LinkedBlockingQueue"/>


连接超时通常是另一个问题的症状,而不是其本身的原因。你是说对于某些服务调用,连接没有超时吗?是的,有些调用工作正常。我的场景包括传输大附件,因此它解释了超时。我遇到的问题实际上是客户端和服务器端超时的配置。那么我建议使用线程池。请在下面找到我的答案。