Apache Camel:带有CxfEndpoint的RouteBuilder

时间:2014-03-18 12:06:50

标签: java spring cxf apache-camel

你好!

我尝试使用Java DSL和RouteBuilder实现Camel路由。我想从计时器端点发送到cxf端点。

代码:

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");        
    }

}

此路由被插入到使用Spring XML定义的camel上下文中(我有一些其他路由)。

问题:

我收到以下错误:

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)
        ....

现在错误非常简单,但here说:

  

此选项仅在POJO模式下需要。如果是wsdlURL选项   提供,PAYLOAD和MESSAGE模式不需要serviceClass。

问题:

如果我使用PAYLOAD模式,为什么还需要服务类?我在创建cxf端点时遗漏了什么?

谢谢!

1 个答案:

答案 0 :(得分:1)

您已经设置了要使用的CxfEndpoint,因此您的路线应该就像这样

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