11 Replies Latest reply on Apr 21, 2013 11:01 AM by Tim Marks

    service orchestration + REST

    Tim Marks Newbie

      I have been tasked to use Switchyard to perform service orchestration of REST services.

       

      I see there are many options within Switchyard (ODE(BPEL), jBPM, Drools, Camel, etc). Can someone recommend one of these technologies for orchestrating REST services?

       

      I started with BPEL, but I quickly determined it is primarily used for orchestration of SOAP services. If BPEL can be used to invoke REST services, I would appreciate some insight.

       

      Thanks in advance.

        • 1. Re: service orchestration + REST
          Keith Babo Master

          Can you provide some detail on what type of things you might be doing in this composition service?  If there's routing or EIP type of stuff (e.g. CBR, filtering, splitting/aggregating, etc.), then Camel would be a good start.  If the composition is long-lived, might involve persistence or human task integration, then I would go with BPM.  If it's simple call A, call B, call C kind of deal, CDI/Bean-based services would be quickest.  All of them will get the job done.

          • 2. Re: service orchestration + REST
            Tim Marks Newbie

            I should have mentioned I am new to Switchyard and service orchestrations.

             

            The initial orchestration will be simple (no CBR, filtering, etc) The REST services are called in sequence. There will be a business rule that triggers an email (based upon the REST response data).

             

            I have a switchyard project that will invoke an external REST services from BPEL. Not sure how to do it. (If there is a better technology than BPEL, I would be happy to switch.)

             

            Thanks

            • 3. Re: service orchestration + REST
              Tim Marks Newbie

              Staus update : I have had no luck invoking a REST service from BPEL.

               

              I then learned that Camel allows REST to be invoked using the http and cxfrs components.

               

              I wrote a new switchyard application that contained a camel route that referenced these components. Both failed (errors "No component found with scheme: http" and "No component found with scheme: cxfrs")

               

              I looked in the JBoss Switchyard maven repository and saw that neither component was available in switchyard.

               

              Does anyone know a work-around?

               

               

               

              • 4. Re: service orchestration + REST
                Keith Babo Master

                Camel seems like a good fit based on your initial requirements.  BPEL would work as well, but if you're new to BPEL I don't think there's any reason to use that specifically in this case.

                 

                You can invoke any type of service binding supported in SY from a Camel route (in fact, this holds true of any service implementation including BPEL).  So you can invoke services over SOAP/HTTP, REST/HTTP, FTP, JMS, etc, etc.  For Camel routes in SY, we believe in separating the endpoint details from the route itself.  This means your camel route will have logical "switchyard://" endpoints and those will map to references in your application.  Those references can be wired to local services (offered by other implementations in your application) or to remote services through reference bindings.  Your Camel route would look something like this:

                 

                <route xmlns="http://camel.apache.org/schema/spring">
                    <from uri="switchyard://MyService"/>
                    <to uri="switchyard://ServiceA"/>
                    <to uri="switchyard://ServiceB"/>
                </route>
                

                 

                Where ServiceA is the service that you are providing with the Camel route.  ServiceA and ServiceB are services invoked from your route.  If these are remote services available over REST, you would have a reference binding that looks like this:

                 

                <reference multiplicity="1..1" name="ServiceB" promote="MyServiceRoute/ServiceB">
                   <rest:binding.rest>
                      <rest:interfaces>example.SomeResource</rest:interfaces>
                      <rest:address>http://servicea.example.com/foo</rest:address>
                   </rest:binding.rest>
                <reference>
                

                 

                This quickstart demonstrates a basic proxying scenario using Camel in SY:

                https://github.com/jboss-switchyard/quickstarts/tree/master/camel-soap-proxy

                 

                hth,

                keith

                • 5. Re: service orchestration + REST
                  Tim Marks Newbie

                  Thanks for the help Keith.

                   

                  As you suggested, I added a line to my camel route

                  <to uri="switchyard://OgpSvc?namesspace=(remote namespace) />

                   

                  I then see this in the logs

                   

                   

                  => org.switchyard.exception.SwitchYardException Could find the service reference for 'OgpSvc' which is referenced...

                   

                  After re-deploying my swichyard application that contains the REST interface, I noticed this line in the logs

                  =>Route: direct:{urn:<myurn>}OgpSvc started and consuming from: Endpoint[direct://%7Burn:<myurn>%7DOgpSvc]

                   

                  So I changed my camel route from switchyard://OgpSvc to direct://OgpSvc

                  Now I am seeing this message in the logs

                  =>No consumers available on endpoint: Endpoint[direct://OgpSvc] to process: Exchange[Message: ]

                   

                  Any suggestions?  Since my REST service contains multiple operations, how do I specify which operation to invoke?

                   

                   

                   

                   

                   

                   

                   

                  • 6. Re: service orchestration + REST
                    Keith Babo Master

                    Can you attach your application?  You definitely want to use switchyard:// and not direct in this scenario. You should not provide the namespace parameter in your switchyard:// endpoint as the camel component will automatically set that for you based on the application's targetNamespace.  This might explain why you got the service reference not found error.

                     

                    Invoking a service with multiple operations is supported via the operationName parameter on switchyard:// endpoints, e.g.

                     

                    <to uri="switchyard://OgpSvc?operationName=foo" />

                    • 7. Re: service orchestration + REST
                      Tim Marks Newbie

                      Attached are my two switchyard applications.

                       

                      swithcyard-ogpsvc exposes 2 simple REST operations

                      ping() <No input parameters, returns static string 'pong'>

                      sayHello <typical 'hello world' operation>

                       

                      http://127.0.0.1:8080/rest/ogpsvc/ping

                      http://127.0.0.1:8080/rest/ogpsvc/sayhello/world

                       

                      switchyard-ogp-camel is the application that I want to call switchyard-ogpsvc

                      it runs when you place a file named 'wasabi' in directory /tmp/fbind/

                      The route then attempts to execute the REST call...and then it blows up.

                       

                      Thanks for looking at it.

                      • 8. Re: service orchestration + REST
                        Keith Babo Master

                        Fixed application attached.  I didn't keep a detailed list of what changed, but these are the broad strokes:

                         

                        1) The composite service interface in your ogp-camel app took a void input and returned a value.  For a file binding you would want the opposite - accept content in through a file and nothing is returned.

                        2) There was a mix of interface.esb and interface.java in the application which I think might have been confusing matters.  I just switched everything to interface.java for now because you already had the interfaces in there.

                        3) Your ogp-camel route had a composite reference defined but no binding.  In order to invoke the opgsvc REST endpoint in the other application you need a binding.rest on the composite reference in your ogp-camel route. 

                        4) The bean service in your ogpsvc app had a dangling reference (reference to no service), which I deleted.

                        1 of 1 people found this helpful
                        • 9. Re: service orchestration + REST
                          Tim Marks Newbie

                          Keith - Thanks for making it work. I certainly owe you a beer !

                           

                          The second operation of my REST service expects an input parameter

                          <Here is the contract of the second operation> String sayHello(String name)

                           

                          I added these lines to the end of camel route

                           

                           

                           

                           

                          <log message="Before sayHello REST call ${body}" />

                           

                           

                          <to uri="switchyard://OgpSvc?operationName=sayHello" />

                           

                           

                          <log message="After sayHello REST call ${body}" />

                           

                           

                           

                           

                           

                          As the following log output shows,   the ping operation is invoked (rather of the sayHello operation)

                          08:29:48,001 INFO [route7] (Camel (camel-11) thread #24 - file:///tmp/fbind) Before sayHello REST call

                          08:29:48,007 INFO [stdout] (http--0.0.0.0-8080-1) OgpSvc : ping

                          08:29:48,010 INFO [route7] (Camel (camel-11) thread #24 - file:///tmp/fbind) After sayHello REST call

                           

                          Obviously I am not specifying the input parameter to the operation...any suggestions on how to invoke this second operation?

                           

                           

                           

                           

                          • 10. Re: service orchestration + REST
                            Keith Babo Master

                            This one is a bit of a mixed bag.  Going off the version of your application that I attached above, the service interfaces in the ogp-camel app required an update to include the additional operation.  After that, you're going to hit this:

                            https://issues.jboss.org/browse/SWITCHYARD-1355

                             

                            It's fixed in 1.0, but as a workaround in 0.8 you'll need to add the following line to your camel route:

                            <removeHeaders pattern="org.switchyard.operationSelector" />

                             

                            Worked fine for me after that.  Updated app attached as I'm hoping to double my beer count.

                            • 11. Re: service orchestration + REST
                              Tim Marks Newbie

                              Keith- It works and I owe you that second beer.

                               

                              I am looking forward to Switchyard 1.0....and the first Switchyard book !

                               

                              Thanks again