7 Replies Latest reply on Apr 11, 2013 7:53 AM by mkoenig

    Switchyard Property replacement in camel route to uri

    mkoenig

      Hello,

       

      I‘ve just started using switchyard 0.8 because we are migration from jboss6 to jboss7 and therefore we also want to migrate from jboss esb to switchyard.

      Now I have just a simple service which should write the message into a file. The filename should be passed as a property.

       

      The problem is that I cannot get switchyard to replace the property within the to-uri  route: <to uri="file:/c:/temp?fileName={{FILENAME}}" />

      If I leave the to-uri route away and deploy the route only with the log-route the property is replaced as expected so this works: <log message="EXPJUPDATA: ${body} {{FILENAME}}" />

       

      Am I doing something wrong or is it a bug in switchyard?

       

      Thx in advance.

      Marcel

       

      Detail information:

      Switchyard version = 0.8.0.Final

       

      My service:

      <?xml version="1.0" encoding="UTF-8"?>
      <switchyard xmlns="urn:switchyard-config:switchyard:1.0"
      xmlns:swyd="urn:switchyard-config:switchyard:1.0"
      xmlns:bean="urn:switchyard-component-bean:config:1.0"
      xmlns:camel="urn:switchyard-component-camel:config:1.0"
      xmlns:file="urn:switchyard-component-camel-file:config:1.0"
      xmlns:sca="
      docs.oasis-open.org/ns/opencsa/sca/200912">
      <sca:composite name="test-esb" targetNamespace="urn:web4db-esb:core:0.1.0">
      <sca:component name="EXPJUPDATA">
      <camel:implementation.camel>
      <route xmlns="
      camel.apache.org/schema/spring">
      <from uri="switchyard://EXPJUPDATA" />
      <log message="EXPJUPDATA: ${body} {{FILENAME}}" />
      <to uri="file:/c:/temp?fileName={{FILENAME}}" />
      </route>
      </camel:implementation.camel>
      <sca:service name="EXPJUPDATA">
      <interface.esb inputType="java:java.lang.String" />
      </sca:service>
      <sca:property name="FILENAME" value="test.tmp.txt"/>
      </sca:component>
      </sca:composite>
      </switchyard>

       

      Test:

      @RunWith(SwitchYardRunner.class)
      @SwitchYardTestCaseConfig(config = "/switchyard/testExpJupDataResult.xml", mixins = { CDIMixIn.class, PropertyMixIn.class })
      public class ExpJupDataServiceTest {

      private org.switchyard.test.SwitchYardTestKit _testKit;
      private PropertyMixIn propMixIn;

      @BeforeDeploy
      public void setTestProperties() {
      // propMixIn.set("FILENAME", "test.tmp.txt");
      // System.setProperty("FILENAME", "test.tmp.txt");
      }

      @Test
      public void testTransformation() throws Exception {
         _testKit.newInvoker("EXPJUPDATA").sendInOnly("Test");
      }
      }

       

      Exception:

      ava.lang.Exception: org.switchyard.exception.SwitchYardException
      at
      org.switchyard.test.SwitchYardRunner.createTest(SwitchYardRunner.java:69)
      at
      org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:258)
      at
      org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at
      org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:255)
      at
      org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
      at
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
      at
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.switchyard.test.SwitchYardRunner.run(SwitchYardRunner.java:90)
      at
      org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at
      org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at
      org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at
      org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at
      org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at
      org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Caused by: org.switchyard.exception.SwitchYardException
      at
      org.switchyard.component.camel.deploy.CamelActivator.handleImplementation(CamelActivator.java:102)
      at
      org.switchyard.component.camel.deploy.CamelActivator.activateService(CamelActivator.java:80)
      at
      org.switchyard.deploy.internal.Deployment.deployImplementations(Deployment.java:460)
      at org.switchyard.deploy.internal.Deployment.start(Deployment.java:140)
      at
      org.switchyard.test.SwitchYardTestKit.deploy(SwitchYardTestKit.java:277)
      at
      org.switchyard.test.SwitchYardTestKit.start(SwitchYardTestKit.java:180)
      at
      org.switchyard.test.SwitchYardRunner.createTest(SwitchYardRunner.java:65)
      ... 19 more
      Caused by: java.lang.IllegalArgumentException
      at java.net.URI.create(Unknown Source)
      at
      org.switchyard.component.camel.deploy.CamelActivator.checkSwitchYardReferencedServiceExist(CamelActivator.java:114)
      at
      org.switchyard.component.camel.deploy.CamelActivator.handleImplementation(CamelActivator.java:94)
      ... 25 more
      Caused by: java.net.URISyntaxException: Illegal character in query at
      index 23: file:/c:/temp?fileName={{FILENAME}}
      at java.net.URI$Parser.fail(Unknown Source)
      at java.net.URI$Parser.checkChars(Unknown Source)
      at java.net.URI$Parser.parseHierarchical(Unknown Source)
      at java.net.URI$Parser.parse(Unknown Source)
      at java.net.URI.<init>(Unknown Source)
      ...
      28 more

        • 1. Re: Switchyard Property replacement in camel route to uri
          splatch

          Can you try replace { and } to %7B and %7D? It's proper encoded URI version. If it will work I'll raise JIRA to put in 1.0 support for that.

          • 2. Re: Switchyard Property replacement in camel route to uri
            mkoenig

            When I use <to uri="file:/c:/temp?fileName==%7B%7BFILENAME%7D%7D" /> the exception disappears and a file named {{FILENAME}} is created.

            So the property is still not replaced.

            • 3. Re: Switchyard Property replacement in camel route to uri
              splatch

              You have to define FILENAME property in your switchyard.xml, then it will be populated.

              • 4. Re: Switchyard Property replacement in camel route to uri
                mkoenig

                I did that, please have a look at my switchyard.xml under My service above: <sca:property name="FILENAME" value="test.tmp.txt"/>

                The replacement is working for <log message="EXPJUPDATA: ${body} {{FILENAME}}" /> but not for <to uri="file:/c:/temp?fileName==%7B%7BFILENAME%7D%7D" />.

                 

                Here some DEBUG infos of my test:

                DEBUG RouteService - Shutting down child service on route: route1 -> Pipeline[[Channel[Log(route1)[EXPJUPDATA: ${body} test.tmp.txt]], Channel[sendTo(Endpoint[file:///c:/temp?fileName=%7B%7BFILENAME%7D%7D])]]]
                DEBUG RouteService - Shutting down child service on route: route1 -> Channel[Log(route1)[EXPJUPDATA: ${body} test.tmp.txt]]
                DEBUG RouteService - Shutting down child service on route: route1 -> Log(route1)[EXPJUPDATA: ${body} test.tmp.txt]
                DEBUG RouteService - Shutting down child service on route: route1 -> Channel[sendTo(Endpoint[file:///c:/temp?fileName=%7B%7BFILENAME%7D%7D])]
                DEBUG RouteService - Shutting down child service on route: route1 -> sendTo(Endpoint[file:///c:/temp?fileName=%7B%7BFILENAME%7D%7D])

                • 5. Re: Switchyard Property replacement in camel route to uri
                  kcbabo

                  Marcel,


                  Welcome to the project!  There are a few things to keep in mind here as you are getting started:

                   

                  1) Including the Camel route directly in your switchyard.xml will no longer be supported in SwitchYard 1.0.  The route definition should reside external to switchyard.xml (e.g. myRoute.xml) and that file is then referenced from the implementation definition in your switchyard.xml.

                  2) I would strongly recommend against including endpoint URIs for Camel components in your route definition.  If you are going to invoke a service with a file endpoint, you can use a switchyard:// endpoint in your route definition and then add a composite reference binding to map that to a file endpoint.

                  3) If you are not using the SY tooling, I would strongly recommend giving it a try.  It will help you do all of the above as a natural part of the development workflow and it eliminates messing around with the XML in our descriptor directly.

                   

                  Here's an example of a Camel route which invokes a service using a switchyard:// endpoint:

                  https://github.com/jboss-switchyard/quickstarts/blob/master/camel-soap-proxy/src/main/resources/META-INF/route.xml

                   

                  You'll notice that ReverseService is promoted and a SOAP binding is attached here:

                  https://github.com/jboss-switchyard/quickstarts/blob/master/camel-soap-proxy/src/main/resources/META-INF/switchyard.xml

                   

                  You would have a camel:binding.file in your switchyard.xml instead of binding.soap.

                   

                  hth,

                  keith

                  1 of 1 people found this helpful
                  • 6. Re: Switchyard Property replacement in camel route to uri
                    kcbabo

                    Forgot to mention that property substitution will work as advertised following the above approach. 

                    • 7. Re: Switchyard Property replacement in camel route to uri
                      mkoenig

                      Hi Keith,

                       

                      thank you very much, things getting clearer to me.

                      I got it working by changing my service as you suggested see the result below.

                       

                      Best Regards,

                      Marcel

                       

                      switchyard.xml

                      <?xml version="1.0" encoding="UTF-8"?>
                      <switchyard xmlns="urn:switchyard-config:switchyard:1.0"
                      xmlns:swyd="urn:switchyard-config:switchyard:1.0"
                      xmlns:bean="urn:switchyard-component-bean:config:1.0"
                      xmlns:camel="urn:switchyard-component-camel:config:1.0"
                      xmlns:file="urn:switchyard-component-camel-file:config:1.0"
                      xmlns:sca="docs.oasis-open.org/ns/opencsa/sca/200912">
                           <sca:composite name="test-esb" targetNamespace="urn:web4db-esb:core:0.1.0">
                                <sca:component name="EXPJUPDATA">
                                     <camel:implementation.camel>
                                          <camel:xml path="/switchyard/expJupDataRoute.xml"/>
                                     </camel:implementation.camel>
                                     <sca:service name="EXPJUPDATA">
                                          <interface.esb inputType="java:java.lang.String" />
                                     </sca:service>
                                     <sca:reference name="EXPJUPDATAFileService">
                                          <interface.esb inputType="java:java.lang.String" />
                                     </sca:reference>

                                </sca:component>
                                <sca:reference multiplicity="0..1" name="PromotedEXPJUPDATAFileService" promote="EXPJUPDATA/EXPJUPDATAFileService">
                                     <file:binding.file>
                                          <file:directory>C:/Temp</file:directory>
                                          <file:fileName>${FILENAME}</file:fileName>
                                     </file:binding.file>
                                </sca:reference>
                                <sca:property name="FILENAME" value="test.tmp.txt" />
                           </sca:composite>
                      </switchyard>

                       

                       

                      and my expJupDataRoute.xml
                      <route xmlns="camel.apache.org/schema/spring">
                           <from uri="switchyard://EXPJUPDATA" />
                           <log message="EXPJUPDATA: ${body} {{FILENAME}}" />
                           <to uri="switchyard://EXPJUPDATAFileService" />
                      </route>