1
votes

ThingsService is a webservice interface generated by jax-ws (stripped of annotations for the sake of brevity). There is one parameter-less method:

public interface ThingsService {
    AvailableThingsResponse getAvailableThings();
}

Trying to call the no-parameters operation from a Camel route using CXF like this:

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

causes Camel to barf when calling the endpoint:

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$1.run(TimerConsumer.java:76) at java.util.TimerThread.mainLoop(Timer.java:555) at util.TimerThread.run(Timer.java:505)

The CXF endpoint is in POJO mode, exchange body being sent to the endpoint is null.

What's the proper way of calling a no-params WS operation from Camel route using CXF component?

1

1 Answers

1
votes

Turns out that no-params is represented using an empty array:

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());