org.apache.cxf.interceptor.Fault: Could not send Message.(CXF客户端调用出错)
weblogic+cxf环境下报错
由于项目需要要学webservice,一开始就遇到这个异常;org.apache.cxf.interceptor.Fault: Could not send Message.at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:171)at $Proxy11.sayHello(Unknown Source)at com.test.cxf.Client.main(Client.java:18)Caused by: java.net.HttpRetryException: cannot retry due to server authentication, in streaming modeat sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)at java.net.HttpURLConnection.getResponseCode(Unknown Source)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1900)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1828)at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:590)at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)... 7 more
?
?
?以下为客户端调用webservice的代码:
public String caculateYaocjh(){JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean ();factory.setServiceClass(IYaoHLJhService.class);factory.setAddress("http://localhost:8085/athena/services/yaocjhService");try{ IYaoHLJhService hs= (IYaoHLJhService) factory.create(); hs.createYaoHLJhMx(); } catch (Exception e) {throw new ActionException(e.getMessage()); } //消息Map<String, String> message = new HashMap<String, String>();message.put("message", "webService自动调度要车计算完成");setResult("result",message); return AJAX;}
?
?
网上有很多说法:
比如:
spring cxf 异常:
??? 有两个原因:
- 客户端的接口的包名(或者接口名)和服务端的包名(或者接口名)不一致 客户端的接口没有加上@Webservice注解
?
?
比如:
让sun的https handler优先加载;
为程序添加weblog.xml配置文件;
?
这些都没有解决我的问题,最后看到一篇好文章,解决了我的问题。
?
这一点要知道:
目前最新规范是 JAX-WS(区别与JAX-RPC),可以下载jaxws-ri(sun的参考实现)学习(samples/fromwsdl)。基本原理了解后,具体开发依赖于你选择的开发平台,Apache CXF、Apache? Axis2,weblogic,websphere都有相应的处理方法。其中Weblogic11g是基于jaxws-ri的,他们是一家的。
?
?
webservice与xfire实现的网上有很多,都是正确的。
这个讲得很全,见:http://atomti.iteye.com/blog/476408
?
webservice与CXF的这个讲得很全,见:http://blog.csdn.net/cyf_cyf/article/details/7187911
?
?
我的错误问题在这里:
?
?
factory.setAddress("http://localhost:8085/athena/services/yaocjhService");
?
将这一句代码改为下面的形式就可以正确执行了:
factory.setAddress("http://localhost:8085/athena/services/yaocjhService?wsdl");
?
?
?
?
?
?
?
?