iteye_9831 2013-04-11 17:05 采纳率: 100%
浏览 481
已采纳

camel中发布webservice的问题

camel自带的例子:camel-example-cxf-tomcat

运行OK。

但是把WebService接口方法的返回值由对象改为List,
当然,实现中也调整为返回List。

但执行错误:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: org.apache.camel.example.cxf.incident.OutputReportIncident cannot be cast to java.util.List

同样的,含有List返回值的WebService,如果使用CXF发布和实现,执行正常。
<jaxws:endpoint id="foo" implementorClass="my.FooImpl" address="/foo" />

但是调整为camel发布的方式:
<bean id="fooImpl" class="my.FooImpl"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="cxf:/foo?serviceClass=my.IFoo"/>
    <to uri="bean:fooImpl"/>
  </route>
</camelContext>

就会出现cannot be cast to java.util.List的错误。
如果把List返回方式改为普通对象,就执行正常。

有人帮看一下吗?
多谢!
  • 写回答

3条回答 默认 最新

  • Dead_Knight 2013-04-15 13:13
    关注

    我试了下,你这个错误不是camel,也不是cxf的,而是jaxb的错误。jaxb解析的时候,是需要被解析对象添加了jaxb的注解:(@XmlRootElement)
    如果你想返回List,可以把list的值放到对象中,然后通过对象获取list列表。
    这是我的测试代码,如下:
    [code="java"]
    OutputReportIncident output = new OutputReportIncident();
    output.setCode("OK;");
    List result = new ArrayList();
    result.add(output);

        JAXBContext context;
        try {
            context = JAXBContext.newInstance(ArrayList.class);
            Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_ENCODING, "GBK");
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
            marshaller.marshal(result, new File("d:/test.xml"));
        } catch (JAXBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    

    [/code]
    这样的代码运行错误信息为:
    unable to marshal type "java.util.ArrayList" as an element because it is missing an @XmlRootElement annotation]

    而cxf是封装了这样的错误

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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记