4 Replies Latest reply on Dec 11, 2013 5:14 PM by staffsgull

    camel, routing by operation

    staffsgull

      Hi all,

       

      I have a wsdl with 5 operations, create, update, find, get and delete.

       

      I am implementing a camel route ( I am new to Camel ) to route to the correct endpoints to process this.  I am trying to route by operation but cannot access the operation name.

       

      I have a promoted service based on a WSDL with a SOAP binding (unwrapped payload and SOAP Header Type of VALUE. This wires to a Camel Component which looks like

       

      <?xml version="1.0" encoding="ASCII"?>

      <routes xmlns="http://camel.apache.org/schema/spring">

          <route>

              <from uri="switchyard://ExecutePortType"/>

              <to uri="log:before?showHeaders=true"/>

              <log message="ExecutePortType - message received:${in.header.org.switchyard.soap.messageName}"/>

          </route>

      </routes>

       

      ${in.header.org.switchyard.soap.messageName} gives me the message type name, but obviously not the Operation name which is what I want to route by.

      I have tried similar to the following but cannot set dataFormat=PAYLOAD on switchyard://ExecutePortType and am not sure where to go here .

       

      <from uri="cxf:bean:customer-ws?dataFormat=PAYLOAD"/>

        <choice>

        <when>

        <simple>${in.header.operationName} == 'updateCustomer'</simple>

        ...

        </when>

       

      I am sure I am missing something fundamental here as routing by operation should be common for SOAP to Camel.  Any help would be appreciated.

       

      So in summary how do I route by Operation Type from a WSDL with SOAP bindings :-)

       

      Rod

        • 1. Re: camel, routing by operation
          synclpz

          May be use OperationSelector in service binding and provide different routes for different operations?

          1 of 1 people found this helpful
          • 2. Re: camel, routing by operation
            staffsgull

            Thanks for the reply Viktor.  I could use that, or a BPEL with an Operation split, but I was hoping to be able to split in Camel to keep this down to one component.

             

            I have seen ?dataFormat=PAYLOAD for beans but not for Web Service.  the dataFormat=PAYLOAD allows the route to see operationName as a value in the header.

            • 3. Re: Re: camel, routing by operation
              kcbabo

              Rod,


              Can you file a SwitchYard JIRA requesting that operation name is set as a Camel message header automatically?  I'm going to describe how you can do it on your own below, but we really should just do this OOTB.

               

              The way to get this done today is to introduce code which maps the operation name from a SwitchYard exchange into a context property. This context property is subsequently mapped into the Camel exchange in your route.  There are two ways to introduce this code: (1) ExchangeInterceptor or (2) MessageComposer.  I would prefer the ExchangeInterceptor route since it's easy to implement and it will set the operation name as a context property for every exchange in your application.  If this turns out to be undesirable for some reason, you can introduce filtering logic in your interceptor or go the MessageComposer route.  The ExchangeInterceptor code would look something like this:

               

               

              @Named("OperationName")
              public class OperationNameInterceptor implements ExchangeInterceptor {
                  public void before(String target, Exchange exchange) throws HandlerException {
                      exchange.getContext().setProperty(
                         "operationName",
                          exchange.getContract().getConsumerOperation().getName());
                  }
              
                  public void after(String target, Exchange exchange) throws HandlerException {
                  }
              
                  public List<String> getTargets() {
                    return Arrays.asList(PROVIDER);
                  }
              }
              
              

               

               

              You could then access the operation name as a message property like this:

               

              from("switchyard://MyService")
                .log("operation name is ${header.operationName}")
              
              

               

              hth,

              keith

              • 4. Re: camel, routing by operation
                staffsgull

                Thanks for that Keith,

                 

                I will try that in the next couple of days, it is a solution, but as you say, I think Camel should present this as a header value as this i one of the most common routing rules I use.  See it's all me,me,me :-)

                 

                I will post a JIRA request as well.

                 

                IDH

                 

                Rod