Log out?

Using OGNL

eiConsole v.22R1
Tutorial & Interface

eiConsole Tutorial Basic

Using OGNL

Overview

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.

This tutorial covers using a standard Java class to create a “UUID.” In addition, 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

Download the INTERFACE file and save it to your local disk.

icon_downloadInterface Download

Open the eiConsole, click on the File drop-down menu and select Import Working Directory/Route/Format. Highlight the name of the file to import and press the Import Selected button. The imported Interface will appear in your current Working Directory.

Next, follow the tutorial and walk through it step-by-step. Finally, 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, the 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, and 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 use 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 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 executes now, 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 the 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. 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 the tutorial. Next, move on to Configuration Using Transaction Attributes.

This is a unique website which will require a more modern browser to work! Please upgrade today!