使用CXF service 时容易出现的异常

 

问题一:Could not find destination factory for transport

 

需要加入cxf-rt-transports-http-jetty的jar包,以下是maven中的配置
<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>2.3.3</version>
</dependency>
 

 

问题二:No operation was found with the name {。。。} ,原因是在当前默认的命名空间中找不到请求的操作方法;

 

解决方法:如果报的是找不到接口,那么在实现类上配置
@WebService(endpointInterface = "com.cxf.hello.IHelloService",targetNamespace = "http://hello.cxf.com/" ) 
public class HelloServiceImpl implements IHelloService{
  ......
}
 其中targetNamespace中的路径为包名的逆序排列;如果报的是找不到相关的javabean类,那么在相关的类上配置
@XmlType(name = "Hello",namespace = "bean.cxf.com") 
public class Hello{
 ......
}
 该命名空间指向在客户端调用的时候的对应的bean所在包的逆序(用于将当前的命名空间指向接口,需要重新发布公共接口)
 
问题三:A cycle is detected in the object graph. This will cause infinitely deep XML,原因是在两个对象中又互相引用了彼此,比如:
public  class UserLogin{
   private int userId;
   private String userName;
   private String userPassword;
   private UserInfo info;
   .........
 }

public class UserInfo {
   private int userId;
   private String sex;
   private String address;
   private UserLogin login;
   .......
 }
 此时需要在类的一端调用中使用@XmlTransient注解(用于get方法上),该注解的作用是不将该属性解析成Xml文件中的元素
 
问题四: java.net.SocketTimeoutException: Read timed out 
在客户端的spring中的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://cxf.apache.org/transports/http/configuration
         http://cxf.apache.org/schemas/configuration/http-conf.xsd"
       default-autowire="byName">

    <http-conf:conduit name="{http://investigation.cxf.spiss.sh.org/}CxfInvestServiceImplService.http--conduit">
         <http-conf:client ConnectionTimeout="500000" ReceiveTimeout="600000"/>
    </http-conf:conduit>

</beans>
 然后在客户端 创建了client之后,接着键入如下代码:
            HTTPConduit http = (HTTPConduit) client.getConduit();
            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
            httpClientPolicy.setConnectionTimeout(600000);//连接超时时间
            httpClientPolicy.setAllowChunking(false);
            httpClientPolicy.setReceiveTimeout(600000);//接收超时时间
            http.setClient(httpClientPolicy);
 即可解决
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值