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条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。