Using OGNL

eiConsole Tutorial Basic

Using OGNL

This interface and related tutorials demonstrate and explain the use of OGNL expressions in eiConsole module configuration items, which allow for dynamically evaluated, programmatic statements.

In the tutorial, we cover using a standard Java class to create a “UUID.” We cover using OGNL expressions in configuration item values to allow for runtime evaluation of programmatic instructions. This tutorial expands on concepts covered in “Expressions Using Environment Properties,” so users are expected to be familiar with that content.

How to Use This Example

Click the links below for the files you will need for this tutorial, then download the INTERFACE to get started. (Once logged into the eiConsole it immediately shows up in your “PIE” inbox for use.)

Interface Download

Note: if you are not logged in to the eiConsole, or have arrived at this page via a browser, you will be prompted to login before the interface downloads into your eiConsole “PIE” inbox. Or if you have not downloaded and installed a FREE eiConsole Trial you will have the opportunity to register after you click the Interface Download link. Once you are logged in the interface will automatically download into your “PIE” inbox. First, you’ll see a screen pop up indicating that a new product is ready for download. Select the Download Now button. Once you’ve downloaded the Interface you can drag it into your current Working Directory and begin.

Next, follow the tutorial and walk through it step-by-step. You may check your work against the provided Route (Sample Data).

Using OGNL Expressions

In a previous tutorial, “Expressions Using Environment Properties”, we walked through the use of Environment Properties in configuration items, which allowed us to externalize the values. There are other expression types available to eiConsole users, most notable of which is “OGNL.”

OGNL (“Object Graph Navigation Language”) can be roughly summarized as “scripted Java.” OGNL expressions evaluate within a Java Virtual Machine against some context, and syntactically are very similar to Java statements. Within the eiConsole, OGNL expressions have access to the current transaction, its attributes, as well as any classes used by the eiConsole or its libraries.

You can find a reference guide for OGNL, as well as more information, at the Apache Commons site.

Defining a Directory / File Transport

We’ll start our example by defining a Directory / File Transport:

Suppose we need a unique ID for our created file’s name. Because OGNL has access to the Java classes and libraries that the eiConsole uses we can make use of standard Java classes, such as “UUID.” The “UUID” class is the package “java.util,” so its fully qualified name is “java.util.UUID.”

The UUID class has a static method called “randomUUID(),” which, as the name implies, generates a new “UUID” with a semi-random, unique value. We’ll use this method to create our file name. We indicate that our value is an OGNL expression by prefixing it with “{ognl:” and suffixing it with “}”:

{ognl:expression}

We’ll be using a static method, so we don’t need to instantiate a new UUID instance. We can statically reference a class by prefixing it with “@.” OGNL needs the fully qualified name of a class, so we’ll add that as well:

{ognl:@java.util.UUID}

Next, we’ll be accessing a static method, so once again we’ll use the “@” character to indicate that, then just provide the method name and parameters:

{ognl:@java.util.UUID@randomUUID()}

That’s the entirety of our expression. Placed into the Directory / File Transport configuration, it looks like this:

Whenever this Transport now executes, we’ll get randomly named files, such as “264a5d08-55fe-44a9-9f7f-6121bee1fa50.txt”

One other concept we’ll briefly note is the OGNL context. The default context used by the eiConsole is the “TransactionAttributes” class, giving you access to transaction attributes. You can use this by specifying “#method” to access some method for the current transaction’s attributes. To fetch the attribute “com.pilotfish.FileName”, which is created by the Directory / File Listener when files are picked up, we would provide:

{ognl:#getAttribute(“com.pilotfish.FileName”)}

To help make using OGNL as easy as possible, the eiConsole also includes a special OGNL tool pre-loaded with commonly used OGNL expressions. To start using this tool, first click on the Use Enhanced Properties button to the right of the text field, as shown below.

You’ll now see some new buttons on the screen. The middle one, with the concentric circles that almost looks like an eye, will open our OGNL tool. Click on it to open the dialog.

The OGNL Expression Constructor is automatically populated with the most commonly used Transaction Attributes you might want to access via OGNL expressions when building your Route. Simply select the “Insert” option next to one of them to add it to your expression.

In addition to adding these attributes, the text field at the bottom is also handy for building your OGNL expression, as you don’t need to worry about the full syntax. Any text put into the text field, including the Transaction Attributes above, will automatically be formatted to be {ognl:YOUR_TEXT_HERE}. This is a handy feature when you’re frequently working with OGNL, as it makes it easier to build complex expressions for your Route.

This concludes this tutorial. Next move on to Configuration Using Transaction Attributes.

Discover Products

About us

PilotFish Inc. was founded in 2001 and provides comprehensive middleware software and services to enable the integration of systems using industry and XML standards. PilotFish serves the insurance, financial, human resources, government and travel industries.