cancel
Showing results for 
Search instead for 
Did you mean: 

JSR-223 scripting languages for expressions

falko_menge
Champ in-the-making
Champ in-the-making
Are there any plans to allow the usage of JSR-223 scripting languages, e.g., Groovy, for expressions?
9 REPLIES 9

tombaeyens
Champ in-the-making
Champ in-the-making
that is already implemented.  @see ScriptingEngines

jbarrez
Star Contributor
Star Contributor
The BPMN scriptTask is capable of using any JSR-223 compliant scripting engine.

ruediger_hain
Champ in-the-making
Champ in-the-making
a little off-topic but related to ScriptTaskActivity:
for performance reasons it may be better to pass a javax.script.CompiledScript to the ScriptTaskActivity and the ScriptCondition.
The compilation would have to be done by the BPMNParse. The ScriptTaskActivity would simply call eval(Binding) on the precompiled script instance. This restricts the usuable ScriptEngines to those that implement Compilable, though.
There is a similar JIRA ticket for UserTaskActivity (ACT-84).
What do you think?
Rüdiger

tombaeyens
Champ in-the-making
Champ in-the-making
created http://jira.codehaus.org/browse/ACT-93 for the compiled script

chrisadam12
Champ in-the-making
Champ in-the-making
amel supports a number of scripting languages which can be used to create an Expression or Predicate via the standard JSR 223 which is a standard part of Java 6.
The following scripting languages are integrated into the DSL:
BeanShell
JavaScript
Groovy
Python
PHP
Ruby
However any JSR 223 scripting language can be used using the generic DSL methods.
ScriptContext
The JSR-223 scripting languages ScriptContext is pre configured with the following attributes all set at ENGINE_SCOPE:
Attribute  Type  Value
context org.apache.camel.CamelContext  The Camel Context
exchange org.apache.camel.Exchange  The current Exchange
request org.apache.camel.Message  The IN message
response org.apache.camel.Message  The OUT message
Attributes
You can add your own attributes with the attribute(name, value) DSL method, such as:
In the sample below we add an attribute user that is an object we already have instantiated as myUser. This object has a getFirstName() method that we want to set as header on the message. We use the groovy language to concat the first and last name into a single string that is returned.
from("direct:in").setHeader("name").groovy("'$user.firstName $user.lastName'").attribute("user", myUser).to("seda:users");
Any scripting language
Camel can run any JSR-223 scripting languages using the script DSL method such as:
from("direct:in").setHeader("firstName").script("jaskel", "user.firstName").attribute("user", myUser).to("seda:users");
This is a bit different using the Spring DSL where you use the expression element that doesn't support setting attributes (yet):
    <from uri="direct:in"/>
    <setHeader headerName="firstName">
        <expression language="jaskel">user.firstName</expression>
    </setHeader>
    <to uri="seda:users"/>
Dependencies
To use scripting languages in your camel routes you need to add the a dependency on camel-script which integrates the JSR-223 scripting engine.
If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-script</artifactId>
  <version>1.4.0</version>
</dependency>




_________________________________________




Want to get-on Google's first page and loads of traffic to your website? Hire a SEO specialist from Ocean Groups seo specialist

falko_menge
Champ in-the-making
Champ in-the-making
My question wasn't about the Script Task, but about expressions used in, e.g., condition expressions, resource assignment expressions, or data associations. If I remember correctly, jUEL is the only option there and the question was raised, why that cannot be Groovy as well.

jbarrez
Star Contributor
Star Contributor
@Falko: now I understand your question. Currently, it is indeed only EE6 UEL that is supported (which is implemented by Juel).

I believe it is in the codebase (ScriptCondition), but not yet used in the parser. Would it then be a matter of changing the language attribute ?

falko_menge
Champ in-the-making
Champ in-the-making
Yes, the attribute expressionLanguage defines the language to be used. The value must be a URI (CName) and defaults to "http://www.w3.org/1999/XPath".
I'd suggest to identify UEL by "http://java.sun.com/products/jsp/" or "http://www.jcp.org/en/jsr/detail?id=245" as those have been used by examples in OMG documents and books.
This might be helpful for other languages: http://stackoverflow.com/questions/904379/urn-for-mime-type
I guess, here is room for improvement in the spec Smiley Wink

tombaeyens
Champ in-the-making
Champ in-the-making
on a related note, i might consider removing groovy from the default dependencies and turn it into an optional dependency.  see also http://forums.activiti.org/en/viewtopic.php?f=4&t=252
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.