CXF请求webService超时区分
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
CXF请求超时区分
设置超时代码
JaxWsDynamicClientFactory clientFactory=JaxWsDynamicClientFactory .newInstance();
String url="http://192.168.1.56:7001/test?WSDL";
Client clientTemp=clientFactory.createClient(url);
HTTPConduit http=(HTTPConduit)clientTemp.getConduit();
HTTPClientPolicy httpClientPolicy=new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(10);//连接超时
httpClientPolicy.setAllowChunking(false);//取消块编码
httpClientPolicy.setReceiveTimeout(1000);//响应超时
http.setClient(httpClientPolicy);
Object[]arg;
String result="";
try{
arg=clientTemp.invoke("testMothd","8698053");
result=(String)arg[0];
}catch(Exception e){
e.printStackTrace();
}
这部分代码大家在网络上随便搜索都能得到,这个就是CXF设置连接的超时与响应时间的方法。当然小编主要讲的不是这个,主要来说下到底如何区分连接超时,还是响应超时。
分析请求错误(5大种)
创建Client类时,URL无效
Exception in thread"main"org.apache.cxf.service.factory.ServiceConstructionException:Could not resolve URL"/e?WSDL".
at
poseUrl(DynamicClientFactory.java:5 66)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:2 53)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:1 98)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:1 91)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:1 46)
at ClientTest.soap(ClientTest.java:141)
at ClientTest.main(ClientTest.java:167)
Caused by:java.io.FileNotFoundException:/e?WSDL
at
.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1241) at org.apache.cxf.resource.URIResolver.tryFileSystem(URIResolver.java:167)
at org.apache.cxf.resource.URIResolver.
at
poseUrl(DynamicClientFactory.java:5 58)
...6more
创建Client类时,URL有效,连接超时
Exception in thread"main"org.apache.cxf.service.factory.ServiceConstructionException:Could not resolve URL"http://192.168.1.56:7001/test?WSDL".
at
poseUrl(DynamicClientFactory.java:5 66)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:2 53)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:1 98)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:1 91)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:1 46)
at ClientTest.soap(ClientTest.java:143)
at ClientTest.main(ClientTest.java:176)
Caused by:.ConnectException:Connection timed out:connect
at .PlainSocketImpl.socketConnect(Native Method)