Camel:到 CXF 端点的 Bean 代理 [英] Camel: Bean Proxy to CXF Endpoint

查看:30
本文介绍了Camel:到 CXF 端点的 Bean 代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试熟悉 Servicemix、Camel、CXF 等,并且与四年前有人在这里提出的问题基本相同:怎么做我将骆驼中的 BeanInvocation 对象转换为消息正文和标题?不幸的是,那里的答案对我没有多大帮助.正如其中一个答案所提到的:Camel 网站上的所有示例都与从 CXF 发送一些的 bean 相关.

I'm currently trying to get familiar with Servicemix, Camel, CXF, etc. and have basically the same question as somebody had four years ago here: How do I convert my BeanInvocation object in camel to a message body and headers? Unfortunately, the answer there don't help me much. As one of the answers mentions: all examples on the Camel website concern themselves with sending something to a bean from CXF.

我有一个在 POJO 中使用的 bean 代理端点,通过

I have a bean proxy endpoint that I'm using in a POJO, injected via

@Produce(uri ="direct:start")
MyService producer; //public interface example.MyService { void myMethod(MyObject o);}

当我在另一端使用另一个 bean 端点时,为该接口实现一个使用者,这一切正常.我现在想做的是使用camel-cxf 来使用实现该接口的Web 服务.我通过以下方式创建了一个 cxfEndpoint:

When I use another bean endpoint at the other end, implementing a consumer for that interface, this all works fine. What I now would like to do is to use camel-cxf to consume a web service implementing that interface instead. I created a cxfEndpoint via:

<cxf:cxfEndpoint id="cxfEndpoint"
    address="http://localhost:8080/MyService/services/MyService"
    wsdlURL="http://localhost:8080/MyService/services/MyService?wsdl"
    serviceName="s:MyService"
    serviceClass="example.MyService"
    endpointName="s:MyService"
    xmlns:s="http://example" />

我现在基本上要做的是,在 RouteBuilder 中:

What I'm now basically trying to do is, in a RouteBuilder:

 from( "direct:start" ).to( "cxf:bean:cxfEndpoint" );

但是在尝试调用代理对象上的某些内容时出现异常:

but get an Exception, when trying invoke something on the proxy object:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Part      
{http://example}o should be of type example.MyObject, not 
org.apache.camel.component.bean.BeanInvocation

据我所知,Spring 代理对象生成一个 BeanInvocation 对象,该对象可以被另一个 bean 端点使用,我必须将其转换为 cxf 可以从中生成 SOAP 请求的方式(或者是否有一些自动转换?).

From what I understand, the Spring proxy object generates a BeanInvocation object that can be consumed by another bean endpoint, and I have to transform this into a way the cxf can generate a SOAP request out of it (or is there some automatic conversion?).

但我有点坚持这样做:我尝试了 http://camel.apache.org/soap.html 中所述的肥皂编组或者编写我自己的处理器,但我什至不确定我是否失败了,或者这不是它应该如何工作.我也尝试将 cxfEndpoint 设置为不同的消息模式,但没有成功.

But I'm kind of stuck doing that: I tried soap marshalling as described at http://camel.apache.org/soap.html or writing my own Processor, but I'm not even sure if I just failed, or if that's not how it's supposed to work. I also tried to set the cxfEndpoint into the different message modes without success.

任何我应该做的事情的指示将不胜感激!

Any pointers what I should be generally doing would be greatly appreciated!

推荐答案

所以经过一周的反复试验,我发现答案很简单.如果 cxfEndpoint 设置为 POJO 模式(默认),解决方案是获取调用参数并将它们填充到消息正文中:

So after a week of trial and error, I found that the answer is quite simple. If the cxfEndpoint is set to POJO mode (the default), the solution is to just grab the invocation parameters and stuff them into the message body instead:

from( "direct:start" ).process( new Processor() {
        @Override
        public void process( Exchange e) throws Exception {
            final BeanInvocation bi = e.getIn().getBody( BeanInvocation.class );
            e.getIn().setBody( bi.getArgs() );
        }
    } ).to( "cxf:bean:cxfEndpoint" )

我想这可以以某种方式更优雅地完成.

I guess this could be done more elegantly somehow though.

这篇关于Camel:到 CXF 端点的 Bean 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆