CXF请求超时区分
设置超时代码
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory
.newInstance();
String url = "192.168.1.56:7001/test?WSDL";
Client clientTemp = ateClient(url);
HTTPConduit http = (HTTPConduit) Conduit();
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" f.service.factory.ServiceConstructionException: Could not resolve URL "www.qq/e?WSDL".
at
f.endpoint.dynamic.DynamicClientFactoryposeUrl(DynamicClientFactory.java:5 66)
at
f.endpoint.ateClient(DynamicClientFactory.java:2 53)
at
f.endpoint.ateClient(DynamicClientFactory.java:1 98)
at
f.endpoint.ateClient(DynamicClientFactory.java:1 91)
at
f.endpoint.ateClient(DynamicClientFactory.java:1 46)
at ClientTest.soap(ClientTest.java:141)
at ClientTest.main(ClientTest.java:167)
Caused by: java.io.FileNotFoundException: www.qq/e?WSDL
at
sun.www.protocol.InputStream(HttpURLConnection.java:1241) at f.FileSystem(URIResolver.java:167)
at f.resource.URIResolver.<init>(URIResolver.java:90)
at
f.endpoint.dynamic.DynamicClientFactoryposeUrl(DynamicClientFactory.java:5 58)
... 6 more
创建Client类时,URL有效,连接超时
Exception in thread "main" f.service.factory.ServiceConstructionException: Could not resolve URL "192.168.1.56:7001/test?WSDL".
at
f.endpoint.dynamic.DynamicClientFactoryposeUrl(DynamicClientFactory.java:5 66)
at
f.endpoint.ateClient(DynamicClientFactory.java:2 53)
at
f.endpoint.ateClient(DynamicClientFactory.java:1 98)
service faultat
f.endpoint.ateClient(DynamicClientFactory.java:1 91)
at
f.endpoint.ateClient(DynamicClientFactory.java:1 46)
at ClientTest.soap(ClientTest.java:143)
at ClientTest.main(ClientTest.java:176)
Caused by: java.ConnectException: Connection timed out: connect
at java.PlainSocketImpl.socketConnect(Native Method)
at java.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at tToAddress(PlainSocketImpl.java:195)
at t(PlainSocketImpl.java:182)
at t(SocksSocketImpl.java:366)
at t(Socket.java:519)
at sun.NetworkClient.doConnect(NetworkClient.java:158)
at sun.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.www.http.HttpClient.New(HttpClient.java:306)
at sun.www.http.HttpClient.New(HttpClient.java:323)
at
sun.www.protocol.NewHttpClient(HttpURLConnection.java:790)
at
sun.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:731) at sun.www.protocol.t(HttpURLConnection.java:656)
at
sun.www.protocol.InputStream(HttpURLConnection.java:979) at f.FileSystem(URIResolver.java:167)
at f.resource.URIResolver.<init>(URIResolver.java:90)
at
f.endpoint.dynamic.DynamicClientFactoryposeUrl(DynamicClientFactory.java:5 58)
... 6 more
创建Client类成功,调用方法时,URL无效
2012-6-30 9:38:34 f.jaxb.JAXBUtils logGeneratedClassNames
信息: Created classes: d.Dispatche, d.DispatcheResponse, d.ObjectFactory
2012-6-30 9:38:51 f.phase.PhaseInterceptorChain doDefaultLogging
警告: Interceptor for {d.eai}dispatche#{d.eai}dispatche has thrown exception, unwinding now
f.interceptor.Fault: Could not send Message.
at
f.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handle Message(MessageSenderInterceptor.java:64)
at
f.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
at f.endpoint.ClientImpl.invoke(ClientImpl.java:516)
at f.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at f.endpoint.ClientImpl.invoke(ClientImpl.java:265)
at f.endpoint.ClientImpl.invoke(ClientImpl.java:285)
at f.endpoint.ClientImpl.invoke(ClientImpl.java:271)
at ClientTest.soap(ClientTest.java:154)
at ClientTest.main(ClientTest.java:176)
Caused by: f.transport.http.HTTPException: HTTP response '404: Not Found' when communicating with 192.168.1.56:7001/test
at
f.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTT PConduit.java:2255)
at
f.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPCondu it.java:2193)
at
f.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:2037 )
at f.transport.AbstractConduit.close(AbstractConduit.java:56)
at f.transport.http.HTTPConduit.close(HTTPConduit.java:697)
at
f.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handle Message(MessageSenderInterceptor.java:62)
.
.. 8 more
f.interceptor.Fault: Could not send Message.
at
f.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handle Message(MessageSenderInterceptor.java:64)
at
f.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255) at f.endpoint.ClientImpl.invoke(ClientImpl.java:516)
at f.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at f.endpoint.ClientImpl.invoke(ClientImpl.java:265)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论