8 Replies Latest reply on Dec 23, 2010 2:25 AM by coke bloom

    Fuse Integration Designer - Groovy

    jcornell Newbie

      I am new to FID.  I have worked with Spagic in the past but like the flexibility of camel.  I am wondering if it is possible to integrate groovy scripts into the eip diagrams.  I have utilized groovy in the past to manipulate messages.  Anyone have an idea?  Also are there any sample eip diagrams out there to learn from?

        • 1. Re: Fuse Integration Designer - Groovy
          Oisin Hurley Novice

          Hi jcornell

          FID does allow you to enter groovy expressions as part of patterns that use such things - for example the choices of a Content-Based Router. 

           

          However, I think that you are after more than that, am I right? Do you want to write custom Camel processors in Groovy?

           

          One more thing - we should be having this discussion over on the Tools forum - http://fusesource.com/forums/forum.jspa?forumID=7

          • 2. Re: Fuse Integration Designer - Groovy
            jcornell Newbie

            You are correct.... I would like to use groovy to transform my message before and after it passes through my cxf service.  How is this performed in FID?  Thanks

            • 3. Re: Fuse Integration Designer - Groovy
              Oisin Hurley Novice

              I think that a Message Translator with a Groovy language expression might do the trick here.

               

              Here's an example - a trivial one, just to illustrate the approach. Consider the following Message Translator setup.

               

               

              In the properties view, click on the ... button to bring up the expression editor. Then, from the Language drop-down, choose groovy. Then, type in your Groovy transformation expression in the Expression Value text box.

               

               

              There's no language checking in that expression text, so we can't tell you if have made any errors at this stage.

               

              Of course, you will need the relevant Groovy jars on the classpath and in the classpath of the Run configuration.

              • 4. Re: Fuse Integration Designer - Groovy
                jcornell Newbie

                Oisin -

                 

                Thank you for that detailed and informative post.  Along with that thread... I have a groovy file which I have inserted into my spring-bean.xml  I have referenced the groovy file using the Camel Processor Bean component.  My groovy file simply changes the NormalizedMessage (outMessage) and should pass it to my file out component.  I know I have a valid groovy script because I can test it with my gunit test and run a sample message... it does the trick... Do I need to use one of the endpoints to reference the bean in the workflow to integrate this functionality I am seeking. 

                 

                Your last post was indeed informative but I would like to keep my groovy script file separate and not have it integrated into the IDE... I am not sure how I would go about unit testing my groovy methods if they are integrated into the IDE. 

                 

                Thanks

                • 5. Re: Fuse Integration Designer - Groovy
                  Oisin Hurley Novice

                   

                  I have referenced the groovy file using the Camel Processor Bean component. deleted Do I need to use one of the endpoints to reference the bean in the workflow to integrate this functionality I am seeking.

                   

                   

                  Ok, I'm not 100% clear exactly what you are up to, but here is a picture anyway

                   

                   

                  In this picture, I've put a Bean Processor on the canvas between two endpoints and then linked that processor to a Spring bean called MyBean. Basically, the route will just call the particular method on an instance of that bean. Is this the kind of thing that might be useful?

                   

                  I don't know if you can share any of your project, but it would be a cool example if you could!

                   

                   

                  Your last post was indeed informative but I would like to keep my groovy script file separate and not have it integrated into the IDE... I am not sure how I would go about unit testing my groovy methods if they are integrated into the IDE.

                   

                   

                  That's a good point - a nice improvement to the Expression Editor would be to somehow link a file that lives in the workspace, rather than having to copy it or type it in as the Expression Value. I added an improvement JIRA for that:

                   

                  http://fusesource.com/issues/browse/UI-1327

                  • 6. Re: Fuse Integration Designer - Groovy
                    jcornell Newbie

                    Current Work around is ...

                     

                    Solved issue in previous post...  I referenced my groovy script in my spring-bean.xml then droped the Camel Processor Bean on my eip_diagram.  Then reference the method in my groovy script.  Here is the sample code....

                     

                    spring-bean.xml

                    1.) needed to add

                    http://www.springframework.org/schema/lang

                    http://www.springframework.org/schema/lang/spring-lang-2.5.xsd to your xsi:scemaLocation

                     

                    2.)

                     

                    camel-context.xml

                    1.)

                     

                    Edited by: jcornell on Jul 1, 2009 3:51 PM

                    • 7. Re: Fuse Integration Designer - Groovy
                      coke bloom Newbie

                      hi!

                      my question is a bit irrelevant. but i need your help. i have some problems in my script in php...actually in AJAX. problem is almost same...how can i solve it

                      • 8. Re: Fuse Integration Designer - Groovy
                        coke bloom Newbie

                        FID does allow you to enter groovy expressions as part of patterns that use such things - for example the choices of a Content-Based Router. by the way which tool you are using? you may experience to change tool for solving your problem