使用 CXF 从 Camel 路由调用无参数 Web 服务操作
Calling no-params webservice operation from Camel route using CXF
ThingsService
是 jax-ws 生成的 web 服务接口(为了简洁起见去掉了注释)。有一种无参数方法:
public interface ThingsService {
AvailableThingsResponse getAvailableThings();
}
尝试像这样使用 CXF 从 Camel 路由调用无参数操作:
from("timer:start?fixedRate=true")
.setHeader(CxfConstants.OPERATION_NAME, constant("getAvailableThings")
.to("cxf:http://localhost:8080/services/things"
+ "?serviceClass=" + ThingsService.class.getName());
调用端点时导致 Camel 呕吐:
java.lang.IllegalArgumentException: Get the wrong
parameter size to invoke the out service, Expect size 0, Parameter
size 1. Please check if the message body matches the CXFEndpoint POJO
Dataformat request.
at org.apache.camel.component.cxf.CxfProducer.checkParameterSize(CxfProducer.java:283)
at org.apache.camel.component.cxf.CxfProducer.getParams(CxfProducer.java:321)
at org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:131)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192)
at org.apache.camel.component.timer.TimerConsumer.run(TimerConsumer.java:76)
at java.util.TimerThread.mainLoop(Timer.java:555)
at util.TimerThread.run(Timer.java:505)
CXF 端点处于 POJO 模式,发送到端点的交换主体为空。
使用 CXF 组件从 Camel 路由调用无参数 WS 操作的正确方法是什么?
事实证明,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());
ThingsService
是 jax-ws 生成的 web 服务接口(为了简洁起见去掉了注释)。有一种无参数方法:
public interface ThingsService {
AvailableThingsResponse getAvailableThings();
}
尝试像这样使用 CXF 从 Camel 路由调用无参数操作:
from("timer:start?fixedRate=true")
.setHeader(CxfConstants.OPERATION_NAME, constant("getAvailableThings")
.to("cxf:http://localhost:8080/services/things"
+ "?serviceClass=" + ThingsService.class.getName());
调用端点时导致 Camel 呕吐:
java.lang.IllegalArgumentException: Get the wrong parameter size to invoke the out service, Expect size 0, Parameter size 1. Please check if the message body matches the CXFEndpoint POJO Dataformat request. at org.apache.camel.component.cxf.CxfProducer.checkParameterSize(CxfProducer.java:283) at org.apache.camel.component.cxf.CxfProducer.getParams(CxfProducer.java:321) at org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:131) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) at org.apache.camel.processor.Pipeline.process(Pipeline.java:120) at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192) at org.apache.camel.component.timer.TimerConsumer.run(TimerConsumer.java:76) at java.util.TimerThread.mainLoop(Timer.java:555) at util.TimerThread.run(Timer.java:505)
CXF 端点处于 POJO 模式,发送到端点的交换主体为空。
使用 CXF 组件从 Camel 路由调用无参数 WS 操作的正确方法是什么?
事实证明,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());