如何显式定义Apache Camel CXF Consumer和Producer

时间:2016-07-19 15:27:05

标签: apache-camel cxf

我遇到了Apache Camel和CXF的一个有趣的困境。

我尝试构建以下路线。

from("servlet://proxy?matchOnUriPrefix=true") .to("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE");

`from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE").to("file:/META-INF/data/test.xml");`

我的愿望实际上是接收Servlet组件的请求,做一些事情(处理器,转换等,但我出于简单原因排除在这里)将其重定向到我的WebService实现,文件组件返回文件的内容作为结果到了WebService。

问题是,如果我从端点'from("servlet://proxy?matchOnUriPrefix=true")'路由到端点'to("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")',Camel认为这应该是CXF Consumer,但我希望它是制作人。

所以我实际上我喜欢从from("servlet://proxy?matchOnUriPrefix=true")路由到'from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")',但我无法想出办法。

如果我配置为第一个配置,servlet组件接收请求,路由到CXF:consumer然后它启动对CXF的TCP调用:'from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")中定义的生产者它可以工作,但它很奇怪,我不希望启动TCP呼叫,我只是希望消息转到“from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")”。

有没有办法实现我想要的?我可以定义一个CXF消费者或提供者,然后使用'from','to'?

有趣的是,我做了类似于ServiceMix / Fuse的事情。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgiRouter="http://osgi.salgar.org/osgirouter"
    xmlns:http="http://servicemix.apache.org/http/1.0"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://servicemix.apache.org/http/1.0 http://servicemix.apache.org/http/1.0/servicemix-http.xsd">

    <http:consumer service="http:FindOrders" endpoint="httpEndpoint" locationURI="http://localhost:8088/MockB2BService"
        defaultMep="http://www.w3.org/2004/08/wsdl/in-out" targetService="osgiRouter:mediation"  />

    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" />
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:eip="http://servicemix.apache.org/eip/1.0"
    xmlns:osgiRouter="http://osgi.salgar.org/osgirouter"
    xmlns:orderProvider_v1="http://v1.salgar.org/B2BService"
    xmlns:orderProvider_v2="http://v2.salgar.org/B2BService"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://servicemix.apache.org/eip/1.0 http://servicemix.apache.org/eip/1.0/servicemix-eip.xsd">

    <eip:content-based-router endpoint="osgiRouterMediation"
        service="osgiRouter:mediation">
        <eip:rules>
            <eip:routing-rule>
                <eip:predicate>
                    <eip:xpath-predicate id="wsdl_version_predicate_v1"
                        xpath="(//namespace::*[.='http://v1.salgar.org/B2BService']) = 'http://v1.salgar.org/B2BService'" />
                </eip:predicate>
                <eip:target>
                    <eip:exchange-target service="orderProvider_v1:findOrders" />
                </eip:target>
            </eip:routing-rule>
            <eip:routing-rule>
                <eip:predicate>
                    <eip:xpath-predicate id="wsdl_version_predicate_v2"
                        xpath="(//namespace::*[.='http://v2.salgar.org/B2BService']) = 'http://v2.salgar.org/B2BService'" />
                </eip:predicate>
                <eip:target>
                    <eip:exchange-target service="orderProvider_v2:findOrders" />
                </eip:target>
            </eip:routing-rule>
        </eip:rules>
    </eip:content-based-router>

    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" />
</beans>




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"
    xmlns:orderProvider_v1="http://v1.salgar.org/B2BService"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://servicemix.apache.org/cxfbc/1.0 http://servicemix.apache.org/cxfbc/1.0/servicemix-cxf-bc.xsd">
    <cxfbc:provider endpoint="findOrdersProviderEndpoint"
        useJBIWrapper="false" wsdl="classpath:v1/B2BService.wsdl" service="orderProvider_v1:findOrders"
        locationURI="http://localhost:8989/MockB2BService" />

    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" />
</beans>

哪个按预期工作但我可以将端点明确定义为CXF提供者,我在这里有相同的可能性吗?

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,这将有效(并且是骆驼的理想解决方案)

路线A

from("servlet://proxy?matchOnUriPrefix=true")
.to("direct:webservice-business-logic")
.to("direct:process-to-file");

路线B

from("direct:webservice-business-logic")
.to("actual-processors-to-do-webservice-business-logic");

路线C

from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")
.to("direct:webservice-business-logic);

基本上,路由C只能由想要使用Web服务的外部各方使用。

路线B仅由路线A使用,因此路线B用于内部骆驼处理。因为调用web服务没有意义,web服务逻辑也位于camel路由中。

希望这有帮助!