使用CXF

时间:2016-12-15 12:38:07

标签: apache-camel cxf

ThingsService是由jax-ws生成的web服务接口(为简洁起见,删除了注释)。有一个无参数的方法:

public interface ThingsService {
    AvailableThingsResponse getAvailableThings();
}

尝试使用CXF从Camel路由调用no-parameters操作,如下所示:

from("timer:start?fixedRate=true")
        .setHeader(CxfConstants.OPERATION_NAME, constant("getAvailableThings")
        .to("cxf:http://localhost:8080/services/things"
            + "?serviceClass=" + ThingsService.class.getName());

在调用端点时导致Camel变为barf:

  

java.lang.IllegalArgumentException:搞错了   调用out服务的参数大小,Expect size 0,Parameter   大小1.请检查消息正文是否与CXFEndpoint POJO匹配   数据格式请求。   at org.apache.camel.component.cxf.CxfProducer.checkParameterSize(CxfProducer.java:283)   at org.apache.camel.component.cxf.CxfProducer.getParams(CxfProducer.java:321)   在org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:131)   在org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)   在org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)   at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)   在org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)   在org.apache.camel.processor.Pipeline.process(Pipeline.java:120)   在org.apache.camel.processor.Pipeline.process(Pipeline.java:83)   在org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)   在org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192)   在org.apache.camel.component.timer.TimerConsumer $ 1.run(TimerConsumer.java:76)   在java.util.TimerThread.mainLoop(Timer.java:555)   在util.TimerThread.run(Timer.java:505)

CXF端点处于POJO模式,发送到端点的交换体为空。

使用CXF组件从Camel路由调用no-params WS操作的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

结果是使用空数组表示no-params:

from("timer:start?fixedRate=true")
        .setHeader(CxfConstants.OPERATION_NAME, constant("getAvailableThings")
        .transform().body(o -> new Object[0])
        .to("cxf:http://localhost:8080/services/things"
            + "?serviceClass=" + ThingsService.class.getName());