Forum Home » General » General Questions

Thread: Fuse Integration Designer - Groovy

 
This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 8 - Last Post: Dec 23, 2010 7:25 AM Last Post By: cokebloom
jcornell

Posts: 22
Registered: 06/05/09
Fuse Integration Designer - Groovy
Posted: Jun 5, 2009 5:20 PM
 
  Click to reply to this thread Reply
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?
oisin

Posts: 136
Registered: 08/05/07
Re: Fuse Integration Designer - Groovy
Posted: Jun 6, 2009 9:18 AM   in response to: jcornell in response to: jcornell
 
  Click to reply to this thread Reply
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
jcornell

Posts: 22
Registered: 06/05/09
Re: Fuse Integration Designer - Groovy
Posted: Jun 29, 2009 2:42 PM   in response to: oisin in response to: oisin
 
  Click to reply to this thread Reply
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
oisin

Posts: 136
Registered: 08/05/07
Re: Fuse Integration Designer - Groovy
Posted: Jun 30, 2009 9:10 AM   in response to: jcornell in response to: jcornell
 
  Click to reply to this thread Reply
Attachment simpleXform.png (46.6 KB)
Attachment groovyExpr.png (32.1 KB)
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.
jcornell

Posts: 22
Registered: 06/05/09
Re: Fuse Integration Designer - Groovy
Posted: Jul 1, 2009 1:08 PM   in response to: oisin in response to: oisin
 
  Click to reply to this thread Reply
Attachment flow.JPG (6.0 KB)
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 :)
oisin

Posts: 136
Registered: 08/05/07
Re: Fuse Integration Designer - Groovy
Posted: Jul 1, 2009 3:09 PM   in response to: jcornell in response to: jcornell
 
  Click to reply to this thread Reply
Attachment groovybean.png (25.6 KB)
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
jcornell

Posts: 22
Registered: 06/05/09
Re: Fuse Integration Designer - Groovy
Posted: Jul 1, 2009 3:50 PM   in response to: jcornell in response to: jcornell
 
  Click to reply to this thread Reply
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.) <lang:groovy id="inbound" script-source="classpath:<path to groovy script>"</lang:groovy>

camel-context.xml
1.) <bean method="<method reference groovy script>" ref="<>" </bean>

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

Posts: 2
Registered: 12/23/10
Re: Fuse Integration Designer - Groovy
Posted: Dec 23, 2010 7:23 AM   in response to: jcornell in response to: jcornell
 
  Click to reply to this thread Reply
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
cokebloom

Posts: 2
Registered: 12/23/10
Re: Fuse Integration Designer - Groovy
Posted: Dec 23, 2010 7:25 AM   in response to: jcornell in response to: jcornell
 
  Click to reply to this thread Reply
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