guohao14 2010-10-25 15:00
浏览 454
已采纳

java调用cxf时返回list类型,出错,请高手给个提示

首先看我的代码:
UserSerivceImpl.java
[code="java"]
@WebService
public class UserSerivceImpl implements UserService {

private UserDao userDao;

public void setUserDao(UserDao userDao){
    this.userDao = userDao;
}
public List<User> getAllUsers() {
    // TODO Auto-generated method stub
    return userDao.getAllUserList();
}

}
[/code]
UserDao.java
[code="java"]
public List getAllUserList() {

        List rows = jt.queryForList("select id as userid,username,email as useremail,profile as userage from tbl_user");
        List<User> list = new ArrayList<User>(); 
        if(rows == null){
            //rows = new ArrayList<User>();
            User user = new User();
            user.setUserage("21");
            user.setUseremail("jack@123.com");
            user.setUserid("23");
            user.setUsername("jack");
            list.add(user);
        }else{//rows !=null
            for(int i=0;i<rows.size();i++){
                User user1 = new User();
                Hashtable ht = (Hashtable)rows.get(i);
                user1.setUserage(ht.get("userage")!=null?(String)ht.get("userage"):"2");
                user1.setUseremail(ht.get("useremail")!=null?(String)ht.get("useremail"):"2");
                user1.setUserid(ht.get("userid")!=null?(String)ht.get("userid"):"2");
                user1.setUsername(ht.get("username")!=null?(String)ht.get("username"):"2");
                list.add(user1);
                System.out.println("username == "+user1.getUsername());
            }
        }
        return list;
    }

[/code]

客户端代码:
[code="java"]
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setAddress("http://localhost:8080/CxfSpring/service/UserManager");
factory.setServiceClass(UserService.class);

    UserService service = (UserService)factory.create();

    //User user = service.getUserByID("1");
    //System.out.println("username == "+user.getUsername());
    List<User> list = service.getAllUsers();
    System.out.println("list size == "+list);

[/code]

运行客户端 ,然后提示的错误是:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: org.springframework.util.LinkedCaseInsensitiveMap cannot be cast to java.util.Hashtable
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)
at $Proxy38.getAllUsers(Unknown Source)
at test.SoapExample.main(SoapExample.java:53)
Caused by: org.apache.cxf.binding.soap.SoapFault: org.springframework.util.LinkedCaseInsensitiveMap cannot be cast to java.util.Hashtable
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:247)
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:99)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:247)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:733)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2201)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2071)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1925)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:188)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:662)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:247)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
... 2 more

请问这是什么错误?怎么解决?

  • 写回答

3条回答 默认 最新

  • lizhiyezi 2010-10-25 15:19
    关注

    Hashtable ht = (Hashtable)rows.get(i);
    [code="java"] Map ht = (Map)rows.get(i);

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败