java - Camel : Bean Proxy to CXF Endpoint

标签 java spring web-services cxf apache-camel

我目前正在尝试熟悉 Servicemix、Camel、CXF 等,并且与四年前有人提出的问题基本上相同: How do I convert my BeanInvocation object in camel to a message body and headers? 不幸的是,那里的答案对我没有多大帮助。正如其中一个答案提到的:Camel 网站上的所有示例都涉及从 CXF 向 Bean 发送一些内容。

我有一个在 POJO 中使用的 Bean 代理端点,通过注入(inject)

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

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

<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 中:

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

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

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 代理对象生成一个可由另一个 bean 端点使用的 BeanInitation 对象,我必须将其转换为 cxf 可以从中生成 SOAP 请求的方式(或者是否有一些自动的方法)转换?)。

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

任何我应该做什么的指示将不胜感激!

最佳答案

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

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

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

关于java - Camel : Bean Proxy to CXF Endpoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26019938/

相关文章:

java - 为什么 Spring Data REST 搜索返回没有页面信息的页面?

java - scala 中的 Hello World 有什么问题?

java - 如何保护 REST Web 服务?

spring - 尝试通过 websocket 转换和发送时出现空指针异常

c# - 如何使用 HTTP POST 从 C# 调用 Web 服务

java - 在同步块(synchronized block)内执行新线程

java - 使用java查找多个文本文件的共同元素的最佳方法是什么?

java - 在 ServletContextListener 上获取 Spring 应用程序上下文

java - CXF:为数组元素设置 minOccurs=0

php - 创建一个Web服务来发送数据库日报的电子邮件