6 Replies Latest reply on Apr 24, 2013 11:51 AM by Rajat Nair

    Reading from a Properties file Switchyard

    Rajat Nair Newbie

      Good Morning,

                           I am a newbie when it comes to using switchyard and has been dabbling in it.I have a small application that i created using the switchyard tooling on top of Jboss developer Studio.It basically polls a ftp server, picks up the file, uses camel routing and writes it to a folder on the local disk.The following are the two questions i have

       

      1) I currently have the ftp server, username etc hard coded in the xml file, how to i go about reading the values from a .properties file on the local disk ?I tried finding some samples but was not successful.The following is my switchyard.xml

       

       

       

       

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:camel="urn:switchyard-component-camel:config:1.0" xmlns:file="urn:switchyard-component-camel-file:config:1.0" xmlns:ftp="urn:switchyard-component-camel-ftp:config:1.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="switchyard-myFtp" targetNamespace="urn:com.example.switchyard:switchyard-myFtp:1.0">
        <sca:composite name="switchyard-myFtp" targetNamespace="urn:com.example.switchyard:switchyard-myFtp:1.0">
          <sca:component name="CamelServiceRoute">
            <camel:implementation.camel>
             <camel:java class="com.example.switchyard.switchyard_myFtp.CamelServiceRoute"/>
            </camel:implementation.camel>
            <sca:service name="CamelService">
              <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.CamelService"/>
            </sca:service>
            <sca:reference name="FileWriter">
              <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.FileWriter"/>
            </sca:reference>
          </sca:component>
          <sca:service name="CamelService" promote="CamelServiceRoute/CamelService">
            <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.CamelService"/>
            <ftp:binding.ftp>
              <operationSelector operationName="acceptMessage"/>
              <ftp:contextMapper/>
              <ftp:directory>in</ftp:directory>
              <ftp:host>FTPHost</ftp:host>
              <ftp:username>{{userName}}</ftp:username>
              <ftp:password>pwd</ftp:password>
              <ftp:consume>
                <ftp:delete>true</ftp:delete>
                <ftp:recursive>true</ftp:recursive>
              </ftp:consume>
            </ftp:binding.ftp>
          </sca:service>
          <sca:reference name="FileWriter" multiplicity="0..1" promote="CamelServiceRoute/FileWriter">
            <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.FileWriter"/>
            <file:binding.file>
              <file:contextMapper/>
              <file:directory>D:/Temp/out</file:directory>
              <file:produce/>
            </file:binding.file>
          </sca:reference>
          <sca:property name="props" value="D:/Temp/route-parameters.properties"/>
        </sca:composite>
      </switchyard>
      
      

       

       

       

       

      I tried the above approach but it errors out and does not work, not sure how to go about this.

       

      2) While using Fuse/servicemix ESB i was able to use processors in routes to transform messages to the format we wanted, the traditional transformation class implemented a "Processor" interface n so forth, not sure how i go about this with switchyard.Do i create a simple bean that does the transformation/translation and expose it as a service and route the message through it ? or is there a better way ?

       

      Thanks in advance

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

        • 1. Re: Reading from a Properties file Switchyard
          David Ward Master

          Hi Rajat,

           

          I can answer your 1st question..

           

          First, please read about properties support in SwitchYard in the documentation: Properties

           

          You can see that system properties can be used, and then SwitchYard auto-replaces them with the ${propertyName:defaultValue} syntax.  However, the documentation only provides examples of setting individual properties on the command line of JBoss AS using -D arguments.

           

          If you want to use a properties file, you can use --properties=<file>.  So, something like this:

              ./standalone.sh --properties=my.properties

           

          Then, all loaded properties become system properties and available for SwitchYard to replace with.

           

          Granted, this is system-wide, ie: every app in that running instance will share the same properties.  I do not believe we have a way to "scope" properties loading to a particular, individiual SwitchYard deployment.  If you ned that, please file a jira feature request.

           

          Thanks!

          David

          • 2. Re: Reading from a Properties file Switchyard
            Rajat Nair Newbie

            I was able to figure out point number 2 mentioned above by simply adding a processor to the route.It looks like the following in java dsl

             

            from("switchyard://CamelService").log(

                                                    "Received message for 'CamelService' : ${body}")

                                                    .process(new TranslationProcessor())

                                                    .to("switchyard://FileWriter");

             

            I read the properties document about was not able to understand how to use the Implementation properties wired with camel  part of the documentation.I will try running it with standalone command on command line and exposing it as system properties, though less ideal it will help with the learning process.Once they are exposed as system properties do i just do a ${propname} to access them ? also everytime i start a server i would have to load the file i am guessing

            • 3. Re: Reading from a Properties file Switchyard
              David Ward Master

              Yes, you can use that syntax in any xml element value or attribute value. However, be aware that there is a jira (see the associated forum link) about escaping that syntax when you need SwitchYard to leave it alone.  And again, if you want localized (to a switchyard app) properties loading, please file a new feature request.

              • 4. Re: Reading from a Properties file Switchyard
                Rajat Nair Newbie

                Works like a Charm using it as system properties.I will do a bit more research on my end on what the end goal is as far as reading properties file is concerned before i raise a ticket for it.Thank you so much, i have one additional question as well

                 

                1)Implementation properties mentioned in the properties document for switchyard, what are they ? how can they be "

                wired into Camel properties component and accessible in a Camel route using Camel's own varName property notation" i tried a lot to find samples pertaining to this but was unable to find any and was hoping to get some guidance on learning about this(code/sample snippets would be awesome).

                 

                Thank you

                • 5. Re: Reading from a Properties file Switchyard
                  David Ward Master

                  Properties can be set in more ways than just from system properties.

                  Note that there is a difference in the notation.  When using SwitchYard's ${propName} notation (borrowed from JBossAS), SwitchYard's configuration layer does the property replacement.  When using Camel's {{propName}} notation, Camel does the property replacement, although it delegates to the same SwitchYard "PropertyResolver" functionality.

                  • 6. Re: Reading from a Properties file Switchyard
                    Rajat Nair Newbie

                    Thank you for helping out with the answers