Apache Camel: RouteBuilder with CxfEndpoint

你。 提交于 2019-12-21 05:17:17

问题


Hello!

I'm trying to implement a Camel route with Java DSL and RouteBuilder. I want to send from a timer endpoint to a cxf endpoint.

Code:

public class MyRoute extends RouteBuilder {

    @Override
    public void configure() {

        CamelContext camelContext = getContext();

        CxfEndpoint cxfEndpoint = new CxfEndpoint();
        cxfEndpoint.setAddress("http://localhost:8088/interface");
        cxfEndpoint.setWsdlURL("wsdl/contract.wsdl");
        cxfEndpoint.setCamelContext(camelContext);
        cxfEndpoint.setDataFormat(DataFormat.PAYLOAD);

        try {
            camelContext.addEndpoint("myEndpoint", cxfEndpoint);
        } catch (Exception e) {
            e.printStackTrace();
        }


        from("timer://my-timer?fixedRate=true&period=500")
                .transform(constant("DummyBody"))
                .to("cxf://myEndpoint");        
    }

}

This route gets inserted into a camel context defined using Spring XML (where I have some other routes).

Problem:

I'm getting the following error:

karaf@root> Exception in thread "SpringOsgiExtenderThread-78" org.apache.camel.FailedToCreateProducerException: Failed to create Producer fo
r endpoint: Endpoint[cxf://myEndpoint]. Reason: java.lang.IllegalArgumentException: serviceClass must be specified
        at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:395)
        at org.apache.camel.impl.ProducerCache.acquireProducer(ProducerCache.java:114)
        at org.apache.camel.impl.ProducerCache.startProducer(ProducerCache.java:145)
        at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:175)
        at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
        at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
        at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
        at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
        at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
        at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
        at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
        ....

Now the error is pretty straight forward, but here says:

This option is only required by POJO mode. If the wsdlURL option is provided, serviceClass is not required for PAYLOAD and MESSAGE mode.

Questions:

If I'm using PAYLOAD mode, why I still need a service class? Am I missing something when creating the cxf endpoint?

Thanks!


回答1:


You already setup a CxfEndpoint to use, so your route should be just like this

from("timer://my-timer?fixedRate=true&period=500")
                .transform(constant("DummyBody"))
                .to(myEndpoint);


来源:https://stackoverflow.com/questions/22478905/apache-camel-routebuilder-with-cxfendpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!