首页 文章

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

提问于
浏览
0

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

我尝试 Build 以下路线 .

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 .

问题是,如果我使用Endpoint' from("servlet://proxy?matchOnUriPrefix=true") ' routing to Endpoint ' 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") ' it works but it is weird, I don'中定义的 生产环境 者想要启动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>

哪个工作正常,但我可以明确地将 endpoints 定义为CXF提供商,我在这里有相同的可能吗?

1 回答

  • 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路由中 .

    希望这可以帮助 !

相关问题