How to define common route body in camel configuration?

695 views Asked by At

I have two route in camel configuration

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>

route2

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

there is only one line difference in both two routes.

one have this

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

another have this

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

so can i put common body in some where else in configuration and refer in both routes?

1

There are 1 answers

2
Muhammad Suleman On BEST ANSWER

When no one respond on my question i was start searching again online and I have found solution like this

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

and then you can invoke like this

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

for more help see this and this, hope this will may help someone else.