Apache Camel:带有 CxfEndpoint 的 RouteBuilder

编程入门 行业动态 更新时间:2024-10-23 05:49:07
本文介绍了Apache Camel:带有 CxfEndpoint 的 RouteBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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.

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 定义的骆驼上下文中(我还有一些其他路由).

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

我收到以下错误:

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:

只有POJO模式需要这个选项.如果 wsdlURL 选项是PAYLOAD 和 MESSAGE 模式不需要 serviceClass.

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 端点时是否遗漏了什么?

Questions:

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

推荐答案

你已经设置了一个 CxfEndpoint 使用,所以你的路由应该是这样的

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

这篇关于Apache Camel:带有 CxfEndpoint 的 RouteBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-19 22:37:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/971378.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Camel   Apache   RouteBuilder   CxfEndpoint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!