如何在驼峰配置中定义公共路径体?

时间:2015-06-10 10:57:37

标签: java web-services soap apache-camel cxf

我在camel配置中有两个route

ROUTE1

    <route>
        <from uri="cxf:bean:soapProxy1?dataFormat=PAYLOAD" />
        <setHeader headerName="CamelHttpMethod">
          <constant>POST</constant>
        </setHeader>
        <setHeader headerName="Contents-type">
          <constant>application/octet-stream</constant>
        </setHeader>
        <setHeader headerName="SOAPAction">
          <constant>vc</constant>
        </setHeader>
        <setHeader headerName="Accept">
          <constant>application/xml</constant>
        </setHeader>

        <to uri="bean:samlWsBean" />            

        <choice>
            <when>
                <simple>${in.header.isvalid} contains "true"</simple>
                <to uri="cxf:bean:backendService?dataFormat=PAYLOAD"/>
            </when>
            <otherwise>     
                <to uri="velocity:file:///path/samlerrorresponse.vm"/>
            </otherwise>
        </choice>
    </route>

路径2

    <route>
        <from uri="cxf:bean:soapProxy2?dataFormat=PAYLOAD" />
        <setHeader headerName="CamelHttpMethod">
          <constant>POST</constant>
        </setHeader>
        <setHeader headerName="Contents-type">
          <constant>application/octet-stream</constant>
        </setHeader>
        <setHeader headerName="SOAPAction">
          <constant>vc</constant>
        </setHeader>
        <setHeader headerName="Accept">
          <constant>application/xml</constant>
        </setHeader>

        <to uri="bean:samlWsBean" />            

        <choice>
            <when>
                <simple>${in.header.isvalid} contains "true"</simple>
                <to uri="cxf:bean:backendService?dataFormat=PAYLOAD"/>
            </when>
            <otherwise>     
                <to uri="velocity:file:///path/samlerrorresponse.vm"/>
            </otherwise>
        </choice>
    </route>

两条路线只有一条线差异。

一个人有这个

<from uri="cxf:bean:soapProxy1?dataFormat=PAYLOAD" />

另一个有这个

<from uri="cxf:bean:soapProxy2?dataFormat=PAYLOAD" />

我可以将普通的身体放在配置中的其他地方并在两条路线中引用吗?

1 个答案:

答案 0 :(得分:2)

当没有人回答我的问题时,我开始在网上再次搜索,我找到了这样的解决方案

<camel:route id="myCommonPartOfFlow">
  <camel:from uri="direct-vm:common-in"/>
  [common part]
</camel:route>

然后你可以像这样调用

<camel:to uri="direct-vm:common-in/>

要获得更多帮助,请参阅thisthis,希望这可以帮助其他人。