java - Apache Camel : RouteBuilder with CxfEndpoint

标签 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说:

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

问题:

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

谢谢!

最佳答案

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

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

关于java - Apache Camel : RouteBuilder with CxfEndpoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22478905/

相关文章:

java - 按键触发 TextEdit 更新 Android

java - Spring validator 自定义 HTTP 状态

java - CXF BusException 命名空间 http ://cxf. 没有 DestinationFactory apache.org/transports/http

java - 使用出站拦截器修改 Apache cxf JAX RS 响应

java - "Unexpected token: Void"for循环导致IDE处理错误,无论位置如何?

java - 在android中的listview中加载本地xml数据

java - Tomcat 部署中与 Spring 持久性相关的错误

cxf - "org.apache.cxf.jaxrs.bus.providers"不工作

java - Java Class文件的命名

java - 抽象类和子类的构造函数注入(inject)