6 Replies Latest reply on Apr 17, 2013 6:22 AM by Put Time

    In the quickstart "camel-service", how do I call another (external) service?

    Put Time Newbie

      In the quickstart "camel-service" sample, an existing service within the project, is invoked, by doing this:

      .to(

      "switchyard://XMLService?operationName=acceptMessage" 

      );

       

      Now, if I have another bean service running, which was created from another project, called "MyService" and that service interface looks like this:

       

      public interface MyServiceInterface {

          public void acceptMessage(String input);

      }

       

               @Service (MyServiceInterface.class)

       

           public class MyServiceBean implements MyServiceInterface { 

            

                          @Override

                          void acceptMessage(String input) { 

                                     System.out.println("ServiceBean-My Input = " + input);

                           }

            };

       

       

      How do I invoke MyServiceBean from the "camel-service" sample?

      Can I do something like,

      .to(

      "switchyard://MyServiceInterface?operationName=acceptMessage" 

      );

        • 1. Re: In the quickstart "camel-service", how do I call another (external) service?
          Łukasz Dywicki Novice

          If you have MyServiceInterface defined in one place in all places where you try to reffer it you need "sca:reference" element. Your switchyard.xml where you have camel implementation defined you need something like this:

           

          <sca:reference name="MyServiceInterface">
              <sca:interface.java interface="com.acme.MyServiceInterface"/>
          </sca:reference>
          
          • 2. Re: In the quickstart "camel-service", how do I call another (external) service?
            Put Time Newbie

            I tried it, added the following three lines to switchyard.xml, like this::

             

            <sca:reference name="MyServiceInterface">

            <sca:interface.java interface="com.my.whatever.somename.MyServiceInterface" />

            </sca:reference>

             

             

            But I get this error: The prefix "sca" for element "sca:reference" is not bound. switchyard.xml

             

             

            If I do this,

             

             

            <interface.java interface="com.my.whatever.somename.MyServiceInterface" />

             

            </reference>

             

             

            then I get this error:

             

            <reference name="MyServiceInterface">

            Unresolved Reference: The component reference "MyServiceInterface" cannot be resolved to a service. switchyard.xml

            • 3. Re: In the quickstart "camel-service", how do I call another (external) service?
              Łukasz Dywicki Novice

              It depends what's the default namespace for your configuration - you may not need sca: prefix if xmlns for your composite element points to http://docs.oasis-open.org/ns/opencsa/sca/200912:

               


              <composite .... xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912">
                  <!-- skip unecessary part -->
                  <component>
                      <reference name="MyServiceInterface">
                          <interface.java interface="com.my.whatever.somename.MyServiceInterface" />
                      </reference>
                  </component>
              </sca:composite>
              

               

              Feel free to post your configuration for review if you will still have problems.

              • 4. Re: In the quickstart "camel-service", how do I call another (external) service?
                Put Time Newbie

                ok, here is the content of switchyard.xml from camel-service.

                Note that I have added the "MyServiceInterface" in here.

                 

                 

                <?xml version="1.0" encoding="UTF-8"?>
                <switchyard xmlns="urn:switchyard-config:switchyard:1.0"
                    xmlns:file="urn:switchyard-component-camel-file:config:1.0"
                    xmlns:swyd="urn:switchyard-config:switchyard:1.0">
                
                    <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="camel-service"
                        targetNamespace="urn:switchyard-quickstart:camel-service:0.1.0">
                  
                  <service name="JavaDSL" promote="JavaDSLBuilder/JavaDSL">
                            <file:binding.file>
                                <file:directory>data/</file:directory>
                            </file:binding.file>
                        </service>
                        <component name="JavaDSLBuilder">
                            <implementation.camel xmlns="urn:switchyard-component-camel:config:1.0">
                                <java class="org.switchyard.quickstarts.camel.service.JavaDSLBuilder"/>
                            </implementation.camel>
                            <service name="JavaDSL">
                                <interface.java interface="org.switchyard.quickstarts.camel.service.JavaDSL"/>
                            </service>
                            <reference name="XMLService">
                                <swyd:interface.esb xmlns:swyd="urn:switchyard-config:switchyard:1.0" inputType="java:java.lang.String"/>
                            </reference>
                            <reference name="MyServiceInterface">
                                   <interface.java interface="com.my.whatever.somename.MyServiceInterface"/>
                             </reference>
                  
                        </component>
                        <component name="XMLComponent">
                            <implementation.camel xmlns="urn:switchyard-component-camel:config:1.0">
                                <xml path="META-INF/route.xml"/>
                            </implementation.camel>
                            <service name="XMLService">
                                <swyd:interface.esb xmlns:swyd="urn:switchyard-config:switchyard:1.0" inputType="java:java.lang.String"/>
                            </service>
                        </component>
                    </composite>
                </switchyard>
                
                • 5. Re: In the quickstart "camel-service", how do I call another (external) service?
                  Łukasz Dywicki Novice

                  You don't have sca: prefix so you don't need prefix reference elements too. You are good to go as long as you have service with MyServiceInterface deployed.

                  • 6. Re: In the quickstart "camel-service", how do I call another (external) service?
                    Put Time Newbie

                    then I get this error:

                     

                     

                     

                    Unresolved Reference: The component reference "MyServiceInterface" cannot be resolved to a service. switchyard.xml

                     

                     

                     

                    If I still go ahead and deploy the application on the server, then I get this error on the server::

                     

                     

                    15:42:51,826 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 1) JBAS014774: Service status report

                    JBAS014777: Services which failed to start: service jboss.deployment.unit."switchyard-quickstart-camel-service.jar".SwitchYardService:

                    org.jboss.msc.service.StartException in service jboss.deployment.unit."switchyard-quickstart-camel-service.jar".SwitchYardService: org.switchyard.exception.SwitchYardException

                    : Failed to load Service interface class 'com.my.whatever.somename.MyServiceInterface'.