6 Replies Latest reply on Aug 14, 2012 3:59 PM by futuredan

    Error using custom language in filter

    futuredan

      The underlying issue that I am attempting to resolve is to be able to dynamically provide an xpath in a predicate as shown below:

       

       

       

       

      However, I get the following error:

       

       

      Exception java.lang.IllegalArgumentException: No script engine could be created for: myxpath

       

      I've created a class that extends Language and created a file named myxpath in META-INF/service/org/apache/camel/language.

       

      What else do I need to do to implement a custom language?

       

      Edited by: futuredan on Jul 27, 2012 10:23 AM

        • 1. Re: Error using custom language in filter
          njiang

          How did you deploy your camel route?

          BTW, did you have change to write a simple unit test to verify your language.

           

          You should find some example in the unit tests of camel-core.

           

          Willem

          • 2. Re: Error using custom language in filter
            futuredan

            I am using a bundle whose only contents is a camel-context.xml in META-INF/spring to deploy the context.

             

            I tried creating a test case, but I'm using Fuse 4.3.1 which uses Camel 2.6 and that source isn't available anymore.

            I tried coming up with something based on the Camel 2.8 source, but I'm not sure I pulled it off.

             

            My classes are quite small.  Here they are in their entirety.

            I assume I am missing something necessary to create a language.

            Do you know what it could be?

             

            public class MyXpathLanguage extends XPathLanguage

            {

             

                 public MyXpathLanguage()

                 {

                 }

             

                 public Predicate createPredicate( String expression )

                 {

                      MyXpathBuilder builder = MyXpathBuilder.xpath( expression );

                      super.configureBuilder( builder );

                      return builder;

                 }

                  

            }

             

            public class MyXpathBuilder extends XPathBuilder

            {

                 private static final Log LOG = LogFactory.getLog( MyXpathBuilder.class );

             

                 public MyXpathBuilder( String text )

                 {

                      super( text );

                      // TODO Auto-generated constructor stub

                 }

             

                 public static MyXpathBuilder xpath( String text )

                 {

                      LOG.info( "Building XPath with :" + text + ":" );

                      return new MyXpathBuilder( text );

                 }

             

                 public boolean matches( Exchange exchange )

                 {

                      LOG.info( "Matching :" + exchange.getIn().getBody().toString() + ":" );

                      return( super.matches( exchange ) );

                 }

            }

            • 3. Re: Error using custom language in filter
              njiang

              It is more complicate if you want to add Spring support of the MyXpathLanguage yourself.

              You need to update the camel-core to add the MyXpathLanguage into the module of language.

               

              Willem

              • 4. Re: Error using custom language in filter
                davsclaus

                Yeah would be nice with a dynamic xpath/xquery for predicates out of the box. I logged a JIRA ticket some time back.

                 

                So possible in the future its out of the box. But the caveat is that the dynamism may requires a change in the DSL, and thus not so easy to introduce as fast.

                • 5. Re: Error using custom language in filter
                  futuredan

                  So in the directive:

                   

                   

                  I can't use a value for the language attribute that isn't built into camel-core?

                   

                  I had assumed languages were dynamic like components with META-INF/services/org/apache/camel/component

                   

                  Thank you for the information.

                  • 6. Re: Error using custom language in filter
                    futuredan

                    I see the ticket at https://issues.apache.org/jira/browse/CAMEL-3697

                     

                    Thanks for the information.  I'll keep an eye on that ticket.