A Sequence definition holds mediation logic to be performed on a message. A Sequence may be defined in-line within a proxy service definition as a sequence local to a service, or defined as a re-usable sequence specified with a name.
The UltraESB allows one to use multiple formats for specifying mediation steps within a sequence. The support ranges from Java code snippets specified as Java source code fragments, to any scripting language supported by JDK 6. All sequences specified as Java or scripting language source code is compiled and executed as byte code. This allows a user with extreme ease of use with his preferred language/s of choice, whilst allowing all code to run at compiled byte code speed with the full power of the JVM. It is also possible to only provide compiled sequences as Java classes, or even specify a Spring managed bean as a sequence. Although leaving mediation logic in configuration allows simpler management and version control, using compiled code may be preferred by certain other users concerned with security etc. and a hardened deployment model for configuration.
Java and script sequences are exposed the current message by a special variable 'msg'. The classes 'Message' and 'Mediation' in the UltraESB API package allows one to perform almost anything within a sequence. However, one should be careful to not spawn new threads from within a sequence, as the UltraESB manages the execution threads which invokes sequences.
A Sequence may be of one of the following types.
-
A Java code snippet
A Java code snippet is the most easy way to mediate messages, and usually makes use of the utility methods exposed by the helper class 'Mediation'. Optionally, a snippet could specify any packages used by the code for import.
<u:java import="java.io.*;"><![CDATA[
String[][] ns = {{"soap", "http://soap.services.samples/"}};
if (Mediation.filter(msg, "//soap:getQuote/request/symbol", ns, "ADRT")) {
Mediation.sendToEndpoint(msg, "stockquote");
} else {
Mediation.sendToEndpoint(msg, "stockquote-err");
}
]]></u:java> -
A Script snippet sequence
A Script sequence could be written using any scripting language supported by Java JDK 6. A good list of languages maybe found at [https://scripting.dev.java.net/]. The UltraESB does not ship with optional libraries required to support these scripting languages, and the user is responsible for making these available to the runtime if required. However, the JDK ships with support for Javascript, which is available out of the box with the UltraESB.
<u:script><![CDATA[
var val = message.getMessageProperty("QUERY_STRING");
val = val.replace('x', 'a');
val = val.replace('y', 'b');
val = val.replace('z', 'c');
message.addMessageProperty("QUERY_STRING", val);
]]></u:script> -
A Script file
A script file sequence is similar to a script snippet sequence and is defined as follows.
<u:scriptFile filename="test/resources/script_seq.js"/>
Where the file script_seq.js may contain the following
println("Message target : " + message.getDestinationURL());
if ("gold".equals(message.getFirstTransportHeader("ClientID"))) {
Mediation.sendToEndpoint(message, "test1");
} else {
Mediation.sendToEndpoint(message, "test2");
} -
Byte code sequence
A Class that implements the public API interface 'JavaClassSequence' maybe specified as a byte code sequence. A byte code sequence is stateful and may persist information between successive calls as shown in the following example
<u:class name="org.adroitlogic.ultraesb.core.SampleByteCodeSequence"/>
package org.adroitlogic.ultraesb.core;
import org.adroitlogic.ultraesb.api.JavaClassSequence;
import org.adroitlogic.ultraesb.api.Message;
public class SampleByteCodeSequence implements JavaClassSequence {
private long startTime;
private int count;
public void execute(Message msg) throws Exception {
System.out.println("Message target : " + msg.getDestinationURL());
if ("gold".equals(msg.getFirstTransportHeader("ClientID"))) {
org.adroitlogic.ultraesb.TestMediation.sendToEndpoint(msg, "test1", "responseSeqKey");
} else {
org.adroitlogic.ultraesb.TestMediation.sendToEndpoint(msg, "test2", "responseSeqKey");
}
count++;
}
public void init(Configuration config) {
startTime = System.currentTimeMillis();
}
public void destroy() {
System.out.println("Byte code sequence, Execution time : " + (System.currentTimeMillis() - startTime) +
"ms. Processed : " + count + " messages");
}
} -
Java source file
It is also possible to specify the source code of a Java class as shown above as a Java source sequence. The UltraESB would simply compile the sequence at each startup.
<u:javaFile filename="test/resources/java_seq.jav"/>
-
Spring bean sequence
A Spring bean which implements the 'JavaClassSequence' interface maybe specified as a Spring bean sequence. For such a sequence one may use the Spring configuration to wire its dependencies, and simply inject this instance for mediation as shown in the example below.
<u:sequence id="myseq7">
<u:bean name="mybean"/>
</u:sequence>
...
<bean name="mybean" class="org.adroitlogic.ultraesb.core.SampleByteCodeSequence"/> -
Support for other options and languages
The support for script based sequences effectively allows one to define a new language for configuration. Thus if required one can invent a new configuration language as a Java 6 scripting language, and it could even be an XML configuration language - for example.
| < Prev | Next > |
|---|


