LAB-6264_ Implementing Enterprise Integration Patterns with ...

bravesnailsΛογισμικό & κατασκευή λογ/κού

7 Ιουν 2012 (πριν από 5 χρόνια και 3 μήνες)

517 εμφανίσεις

JavaOne Hands-On Lab
Implementing Enterprise Integration Patterns
with GlassFish v3 and OpenESB v3
LAB-6264
Copyright 2009 Sun Microsystems
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
1 of 41

LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
2 of 41
Expected Duration (Overall):
120 minutes
Contacts:

Louis Polycarpou

Mike Somekh
Last Updated: June 1, 2009
Introduction to Open ESB v3

Open ESB v3 or 'Project Fuji' represents Sun's next generation open source integration runtime, focus
ed on providing a lightweight, developer-
friendly, and extensible platform for composite application development. At the core of

Project

Fuji

is a lightweight micro-kernel based on JBI
(JSR 208) and OSGi. Packaged as an OSGi bundle, the micro-kernel can be installed in any OSGi-complia
nt runtime, such as that available
with GlassFish v3 or Apache Felix. JSR 208 support allows all of your existing JBI components to run
in

Fuji

and also introduces a robust,
message-based service bus to the OSGi environment.
Developer experience is a primary focal point in

Fuji

as evidenced by the level of flexibility and accessibility offered in the platform. Starting with
a rapid, top-down development language, IFL (Integration Flow Language), developers can quickly and e
asily generate an integration application
using a domain-specific grammar geared toward the implementation of common Enterprise Integration Pat
terns (EIPs). The service
development model favors convention and configuration over boilerplate code and framework APIs, allow
ing integration developers to focus on
the code that matters.
Copyright
Copyright 2009 Sun Microsystems, Inc. All rights reserved. Sun, Sun Microsystems,
the Sun logo, Solaris, Java, the Java Coffee Cup logo, JavaOne, the JavaOne logo,
and all Solaris-based and Java-based marks and logos are trademarks or registered
trademarks of Sun Microsystems, Inc. in the United States and other countries.

Goals

The Enterprise Integration Patterns (EIP) catalog provides a set of blueprints for solving the most c
ommon integration problems in your
enterprise. While the blueprints are great, you still have to come up with an implementation, and th
is is where most developers look for help. Do
you need to implement the patterns along with your business logic? What can your application infrast
ructure do to help and how do EIP
concepts map to your existing architecture (SOA, MOM, ESB)?
This lab provides a hands-on approach to selecting and implementing the right EIPs to solve a variety
of scenarios posed by a real world
integration problem. Attendees will use the first-class EIP support available in Open ESB v3 to defi
ne, configure, and deploy pattern-based
applications to their GlassFish runtime. The lab will also cover the relationship of EIP to existing
SOA and Web Services standards and
technologies. Expect to come away with a new level of understanding on how you can leverage EIPs in
your enterprise.
By the end of this hands-on lab, attendees should be able to:
Describe the use of some basic Enterprise Integration Patterns and when to apply them.
Use Integration Flow Language (IFL) to define a top-down services and routing model as a basis for EI
P implementation and service artifact
generation.
Build solutions for common real-world classic integration problems using Open ESB v3, NetBeans & OSGi
in GlassFish v3.
You may need to refer to the accompanying presentation
6264_openesbpatterns_presentation.pdf
during the lab.
Prerequisites

This hands-on lab assumes you have some basic knowledge of, or programming experience in, the followi
ng technologies:
Basic familiarity with enterprise integration patterns.
Familiarity with SOA and/or EAI principles desirable.
System Requirements

Supported OS: Solaris™M 8/9/10 Operating System (OS), OpenSolaris™ Operating System (OS), Linux, Wind
ows 2000/XP/VISTA, Mac
LAB-6264: Implementing Enterprise Integration
Patterns with GlassFish v3 and OpenESB v3
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
3 of 41
OS X 10.4+
Memory requirement: 1024MB
Disk space requirement: 1024MB
Software Needed For This Lab

Please install and configure all the software denoted in
Exercise 0: Install and Configure Lab Environment

prior
to attending the lab. If you have
any questions on installation, please feel free to send questions to the lab forum mentioned below.
Notations Used in This Documentation

<lab_root>
- directory into which lab zip file is unzipped
This document uses
<lab_root>
to denote the directory under which you have unzipped the lab zip file of this hands-on lab. The
name of the lab zip file of this hands-on lab is
66226644__ooppeenneessbbppaatttteerrnnss..zziipp
.
Once you unzipped the lab zip file under
<lab_root>
, it will create a subdirectory called
openesbpatterns
. For example, under
Solaris, if you have unzipped the lab zip file in the
/home/louis
directory, it will create a directory called
/home/louis
/openesbpatterns
.
Lab Exercises

Exercise 0: Install and configure the lab environment
Exercise 1: File to file; the Hello World of EIPs
Exercise 2: Splitting messages using the Split EIP
Exercise 3: Filtering messages using Pipes and Filters
Exercise 4: Enriching messages using JRuby services
Exercise 5: Routing messages based on content
Exercise 6: Aggregating multiple messages into a single output message
Exercise 7: Archiving messages using the wire tap
Exercise 8: Using the Web GUI
Where To Go For Help

You can send technical questions via email to the authors of this Hands-on lab (and experts on the su
bject) or you can send general
questions relating to OpenESB v3 (Fuji) or GlassFish ESB to the public users alias:
users@open-esb.dev.java.net

LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
4 of 41
Exercise 0: Install and Configure Lab Environment

In addition to the contents of this lab's zip file you will need to obtain and install the following
before you may begin the exercises:
Prerequisities
Sun JDK: version 1.5.0_14 or later for JDK 5, or version 1.6.0_03 or later for JDK 6. You can obtain
JDK 1.6.0_13 for your desired platform
on the accompanying DVD at
/software/jdk1.6.13/
NetBeans 6.5.1 IDE
Download
or obtain the full version for your required platform from the DVD at
/software/netbeans6.5.1
Apache Maven 2.0.9
Download
apache-maven-2.0.9-bin.zip
Apache Maven plugin for NetBeans IDE - available through the NetBeans update center
OpenESB v3 (Fuji) Milestone 6 with Apache Felix OSGi runtime -
Download
fujifelix-1.0-M6-SNAPSHOT.jar
Fuji NetBeans modules zipfile
Download
nb-plugins-1.0-M6-bin.zip
containing:
Fuji NetBeans IFL Support Plugin
org-netbeans-modules-jbi-fuji-support.nbm
Fuji NetBeans Server Plugin
org-netbeans-modules-jbi-fuji-server-plugin.nbm
Fuji Maven Repository (pre-built) - available on the DVD
Note (1):
The required files above can also be obtained from the accompanying DVD.
Note (2):
If
java
is not in your default execution path, you will need to set
JAVA_HOME
to point to the root of its installation on your system.
Note (3):
At the root of your lab installation is a directory called
artifacts
. In this directory you will find all the required test files that are
required for this lab.
Installation Steps
1. NetBeans IDE
If you do not already have NetBeans 6.5.1 installed, run the NetBeans installer and install it using
default settings throughout.
Note: If you are using an existing installation of NetBeans 6.5.1, please shutdown the IDE and rename
the
.netbeans
directory in your home
directory before proceeding further. This will ensure that other NetBeans plugins do not clash with t
he required plugins for Maven and
OpenESB v3.
2. Apache Maven
Unzip
apache-maven-2.0.9-bin.zip
to a directory of your choice e.g.
c:\hol6264\apache-maven-2.0.9
Set the environment variable
MAVEN_HOME
to point to the above directory
For this hands-on lab, we will be using a pre-built local Maven repository to minimise the need for d
ownloading artifacts from a remote
Maven repository. A zipfile
fuji-repository.zip
is provided on the DVD under the
resources/software
directory. Unpack this
zipfile to a directory of your choice e.g.
c:\hol6264\fuji-repository
. You will need to enter this directory when configuring the Maven
Plugin for NetBeans in a later step.
3. Plugins for NetBeans IDE
Start the NetBeans IDE while connected to the Network.
From the NetBeans IDE menu bar, navigate to
Tools

Plugins
and select
Available Plugins
from the Tab menu. Locate
Maven
from the
list of available plugins, check it and click
Install
to download and install it, as indicated below.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
5 of 41
Note (1):
The version number of the Maven plugin should be at least 4.0.5.
Note (2):
If you are not connected to the network, you may obtain the Maven plugin for NetBeans in the
resources/plugins
directory on
the DVD.
Unpack the
nb-plugins-1.0-M6-bin.zip
file to a temporary location; this will unpack the two .nbm files detailed above for IFL support
and GlassFish ESB v3 (Fuji) Server support within NetBeans. You can obtain this zipfile from the
resources/plugins
directory on the
DVD.
Go to
Tools

Plugins

Downloaded
and select the 2 Fuji support .nbm files (obtained from the zip) and click Install – Ignore any
validation errors and select to
Restart IDE now
.
Restart the NetBeans IDE manually if it does not do so automatically.
4. Configure Maven Plugin
Some post-install steps are necessary to use the pre-built OpenESB v3 artifacts with the Maven plugin
.
Go to
Tools

Options

Miscellanous
, Within the
Maven
tab, populate the
External Maven Home
to point to the full path of the
unpacked directory maven-2.0.9 (i.e. %MAVEN_HOME% on Windows or $MAVEN_HOME on UNIX), as shown below:
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
6 of 41
Since we are using a local repository, set the
Local Repository
to denote the full path to the
repository
directory extracted from the
fuji-repository.zip
, as shown above.
Within the same tab, click
Index Now
to cache Fuji archetypes (and others) within your local Maven repository. This should take under a
minute to complete.
Finally, from the Main Menu, go to
Tools

Options

Miscellanous
, Within the
Fuji
tab, select to use Fuji Archetypes Version
1.0-M6-
SNAPSHOT
as shown below:
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
7 of 41
Note (1):
If the dropdown list shown above is empty, it is possible that the archetypes did not finish indexing
. Repeat the previous step and
then restart your IDE.
5. Fuji Server for NetBeans IDE
Unpack
fujifelix-1.0-M6-SNAPSHOT.jar
to a directory of your choice (without spaces in directory path). This will create the
fuji
runtime directory. Keep the original JAR handy since you will need to unpack this again if you want t
o start afresh.
Note:
You can unpack .jar files from the command line using
jar xvf <filename>
.
Go to
Services

Fuji Servers
. Right click and select
Add Server
. Select the
fuji
directory you just unpacked
fujifelix-1.0-M6-
SNAPSHOT.jar
to and leave the other field defaults as shown below:
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
8 of 41
You will now see a valid
Fuji Server
within the services tab which you can deploy your projects to, as shown below:

Exercise 1: Basic routing and how to implement a "File to File" (the "Hello World" of EIPs)

This set of exercises collectively and iteratively implement an end-of-day batch trade processing app
lication.
A fictional investment bank, Duke Bank, closes out its end-of-day trader books every day of trading a
fter the markets close. Trades for each day
are aggregated by a back-end system and placed in order of trade id into a single file. The trader bo
oks cannot be updated directly from this
batchfile containing bulk trade data. Therefore the trades need to be enriched, sorted and filtered i
nto specific files and then loaded into
individual trader books. It is also important that end-of-day batch files are archived for auditing p
urposes.
These exercises will provide an overview how common and repeatable Enterprise Implementation Patterns
(EIPs) can be used to describe,
model and implement the aforementioned use case. We will introduce and explore the use of a domain sp
ecific language for defining such
patterns in OpenESB v3 known as the Integration Flow Language (IFL) in order to implement the busines
s solution required.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
9 of 41
This first exercise introduces the use of services and basic routing patterns in IFL. To start with,
we will implement a very simple integration
application which takes the end of day trade batchfile and moves it to another location.
- Objective: Learn about basic routing and service definition
- Expected duration: 20 minutes
- Brief description: Learn to use the IFL domain specific language to declare services and route
messages.

Introducing Open ESB v3 Concepts
Maven Archetypes
Overview of EIPs
OSGi
In this exercise we are going to learn about basic routing and definition of services, using simple f
ile to file processing. We will use IFL which is a
domain specific language (or DSL) to declare two file services and define a route so that all message
s received in one file will be routed to the
other.
Steps to Follow

Step 1: Create a new Integration Application
In this step, we will use a Maven project based on an OpenESB v3 Integration Application archetype as
a fast-track to building OpenESB v3
applications from a pre-defined project template containing all the required dependencies and build s
ystem targets. The goal here is to use
Integration Flow Language to build something which reads an input file, enriches the data using a ser
vice and sends the result to an output file.
Start the NetBeans IDE if it is not already running.
1.
When NetBeans has started, select
File

New Project
and select
Maven Project
from the Maven category.
2.
Click
Next
.
3.
From the list of available archetypes, select the
Fuji Integration Application Archetype
. If there are multiple versions in the list, use the
version relating to the OpenESB v3 release for this exercise, which is
1.0-M6-SNAPSHOT
. The version can be found by selecting the
archetype and viewing the version information in the Description pane.
4.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
10 of 41
Enter a project name
lab6264
and click
Finish
.
Note:
Changing the package name, version and Group ID is entirely optional for this HOL.
5.
Step 2: Creating the IFL Definition
Expand the IFL Files tree within the new Integration Application you have just created, and open the
app.ifl
in the NetBeans code pane.
You will see an empty IFL definition:
1.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
11 of 41
#IFL - Integration Flow Language
Declare the services that will be used for this application. Since we are reading from a source file
and writing to a destination file, we can
declare our file services to have meaningful names as follows:
2.
#IFL - Integration Flow Language
file "source_file"
file "destination_file"

Note:
For those familiar with JBI, these service keywords correspond to the available binding components an
d service engines. The variable
names correspond to service units.
Create a
route
block, surrounded by a do and end and denote that all
source_file
messages should be routed to the
destination_file:
with:
3.
#IFL - Integration Flow Language
file "source_file"
file "destination_file"
route do
from "source_file"
to "destination_file"
end
Note:
In the above case, since there is only one route, a block is not required and it is possible to rewri
te the above as:
route from "source_file" to "destination_file"
.
Step 3: Creating the service artifacts
Your definition is now complete. The next stage is to configure the properties that the declared serv
ices will use by first generating the
service artifacts for these declared services. This is achieved using a special Maven build target. T
his has already been configured in the
Maven project based on the archetype (or template) that was used to create the project. It is easily
accessed from the NetBeans IDE by
right-clicking on the code pane canvas and selecting
Generate Service Artifacts
.
1.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
12 of 41
Note:
Another way to generate the service artifacts is to right-click on the Maven project and select Custo
m-->Generate Artifacts.
Note:
For those familiar with command-line use of Maven, the generation of service artifacts can be execute
d on the command line with
mvn fuji:generate-artifacts
.
This will initially download a number of dependencies from the Maven repository (only required the fi
rst time) and will then create a number
of service artifacts. The property configuration files can be found in the
Service Config Files
tree within your Integration Application. There
will be a
service.properties
generated for both source_file and destination_file.
2.
Modify the
service.properties
for the source_file to use a
fileName
of batchtrades-in.xml (which is the test input we will be using
throughout these exercises) and a
fileDirectory
that is applicable to your machine's drive layout:
file.use=literal
file.fileName=batchtrades-in.xml
file.pollingInterval=1000
file.fileDirectory=c:/hol6264/files/in
file.fileNameIsPattern=false
file.multipleRecordsPerFile=false
file.recordDelimiter=
Note:
You can navigate to the required service.properties file directly from the IFL editor by right-clicki
ng the required service and selecting
Edit Configuration
.
3.
Likewise, modify the
service.properties
for the destination_file, so it uses a
fileName
and
fileDirectory
that is applicable to your
machine's drive layout.
file.use=literal
file.fileName=batchtrades-all.xml
file.pollingInterval=1000
file.fileDirectory=c:/hol6264/files/out
file.fileNameIsPattern=false
file.multipleRecordsPerFile=false
file.recordDelimiter=
Warning:
Do not remove any of the properties in a
service.properties
file since each of the properties specified is used to substitute
into the service definition of the generated WSDL files required by the JBI specification. Removing o
r commenting any of these properties
will therefore cause deployment errors.
Path Conventions
Unix and many Unix-derived systems use a forward slash (/) to show subdirectories in a file path. Win
dows, normally
uses a backslash (\) for this purpose. However, since in the above steps we are editing a Java proper
ties file which would
normally use a forward slash or double-backslash convention. Throughout this document we use the forw
ard-slash
convention for file paths.
Please remember that you may have to leave out the drive letter in the generic examples if you are wo
rking in a Unix or
Unix-derived system.
Step 4: Start the Server
With the NetBeans IDE
This step is only required if you have not already started the Felix server.
To start the Felix OSGi runtime, click on the
Services
panel in NetBeans to show the available Fuji Servers.
a.
Expand Fuji Servers, right-click
Fuji Server
and select
Start
.
b.
4.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
13 of 41
View the Fuji Server window within the NetBeans IDE and you should see:
Starting Fuji instance [Fuji Server]....
cwd=C:\dev\fuji
Welcome to Felix.
=================
c.
From the command prompt
You can also start the server from the command line. From the directory in which you unpacked the fuj
ifelix-1.0.jar, enter:
c:\dev\fuji>java -jar bin/felix.jar
When you receive the following message, you're up and running succesfully:
Welcome to Felix.
=================
a.
Step 5: Build and deploy the Application
You are now ready to build, deploy and test your application to the OSGi container. The first step is
to compile/build your application as an
OSGi-compliant JAR file.
With the NetBeans IDE
Right-click on the Integration Application project and select
Build
. This will create the OSGi-compliant JAR file (i.e. OSGi bundle) in the
target directory from where it can be deployed.
1.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
14 of 41
To deploy your bundle from within the NetBeans IDE, right-click the Integration Application project a
nd select
Deploy...
.
2.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
15 of 41
Note:
Another way to deploy the bundle is to go to the
Services
panel in NetBeans, expand Fuji Servers and (with Fuji running) right-click
Install Bundle...
. Select the
lab6264-1.0-SNAPSHOT.jar
which can be located in the target directory of your project and the bundle will be
deployed and started.
From the command prompt
If you're not using NetBeans, with the server running from the command line.
-> install file:c:/nbproj/lab6264/target/lab6264-1.0-SNAPSHOT.jar
Bundle ID: 80
1.
Depending on the bundle ID returned, you can then start the application with:
-> start 80
Warning: The encoding 'UTF-8' is not supported by the Java runtime.
Note:
The above warnings - if you see them - are generated by specific versions of the JDK. They will not a
ffect the lab testing phase so
please ignore them.
2.
Step 6: Testing the Application
The file service (i.e. binding component) will create the desired source and target directory structu
re automatically so there should be no need to
do this manually (although the current user must have permissions to do so). To test the application,
copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified fileDirectory e.g.
c:\hol6264\files\in
. The file should be immediately
processed and removed from the source directory and a new file created
batchtrades-all.xml
in the target directory with identical content.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
16 of 41
Troubleshooting
If your application fails to deploy or work as expected in the testing phase, please consider the fol
lowing steps:
Firstly, check that you have carried out all of the instructions as described and are using the corre
ct directory locations for your machine.
Ensure that you have not removed any of the properties in the
service.properties
file(s) since all properties are mandatory.
1.
If all is correctly specified, try undeploying (i.e. uninstalling) the application bundle and then re
starting the Fuji server and then redeploying
the bundle. You can uninstall an application bundle in NetBeans by right-clicking the bundle name wit
hin the
Service Assemblies
of the
expanded
Fuji Server
tree under the
Services
tab. If you know the bundle ID, you can also do this from the command line by stopping and
then uninstalling with:
-> stop 80
-> uninstall 80
Note:
You can find the bundle ID and its status for your application by taking
ps
at the console.
2.
If you are still having problems, stop the Fuji server and NetBeans IDE, and delete the
fuji
directory you unpacked from the
fujifelix-
1.0-M6-SNAPSHOT.jar
. Unpack the jar again to start with a fresh instance of Fuji and then restart your NetBeans IDE and
restart Fuji.
You will not need to add the Fuji Server to NetBeans again. Now try redeploying your application bund
le again.
3.
Summary

In this exercise, you created a basic integration flow in IFL using service definition and the route
pattern. You learned how to generate and
configure your service artifacts and how an integration application can be built and deployed to an O
SGi container.
Now that you understand the basics, we will move on to introduce more EIPs to enhance the application
.


LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
17 of 41
Exercise 2: Splitting messages using the Split EIP

This exercise introduces the use of a splitter. The splitter is required to be able to process each m
essage in the batch seperately. In the example
of Duke Bank, we need to go on to enrich each trade and route them accordingly based on content and i
n order to do so we need to split each
trade so that they can be processed seperately.
- Objective: Using the split EIP
- Expected duration: 10 minutes
- Brief description: Learn how to use the split keyword in IFL to split an end of trade batchfile
into multiple trades.

Introducing Open ESB v3 Concepts
Split EIP
The purpose of the split pattern is to take a single input message and output one or more output mess
ages based on a boundary condition.
The boundary condition can be specified in a wide variety of languages and is generally tied to the t
ype of data being split (e.g. XML ->
XPath). Some split expressions are more powerful than others, with the option to mangle or enrich the
data as a side effect of being split.
Steps to Follow

Continuing from the previous exercise, we will split the messages coming into our application from th
e input file so that each trade goes into a
separate output file.
Step 1: Modify the IFL Definition
Expand the IFL Files tree within the new Integration Application you created in Exercise 1, and open
the existing
app.ifl
in the NetBeans
code pane. Modify the IFL definition to include the split keyword as follows:
1.
#IFL - Integration Flow Language
file "source_file"
file "destination_file"
route do
from "source_file"
split xpath("/Batch/Trade")
#split the batch file into multiple trade messages
to "destination_file"
end
Note:
You can insert comments anywhere in IFL (or service.properties) using the # prefix, even inline, as s
hown above.
Step 2: Modify the service artifacts
Since we have not added any new service declarations, there is no need to regenerate the service arti
facts. However, in order to witness the
effects of using split, we need to modify the
service.properties
file for the
destination_file
service to use one file per message created. The
default is to append messages into the same target file.
The property configuration files can be found in the
Service Config Files
tree within your Integration Application. Locate the
service.properties
file that was generated for the destination_file.
1.
Modify the
service.properties
for the destination_file to set
fileNameIsPattern=true
and
fileName=trade-%d.xml
. This will ensure that a
2.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
18 of 41
new file is created with an incremental number in the filename as each new message is sent to the des
tination_file service.
file.use=literal
file.fileName=trade-%d.xml
file.pollingInterval=1000
file.fileDirectory=c:/hol6264/files/out
file.fileNameIsPattern=true
file.multipleRecordsPerFile=false
file.recordDelimiter=
Note:
Remember that you can navigate to the required service.properties file directly from the IFL editor b
y right-clicking the required
service definition and selecting
Edit Configuration
.
Step 3: Build and deploy the Application
Build and deploy your application to the OSGi container as before.
Step 4: Testing the Application
To test the application, copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified
fileDirectory e.g.
c:\hol6264\files\in
. The file should be immediately processed and removed from the source directory and multiple new fil
es
created beginning with
trade-0.xml
in the target directory.
Summary

In this exercise, you modified an existing integration flow in IFL to use a splitter.
Now that the messages are split into individual trades, we can begin to apply more EIPs to enhance th
e application.


LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
19 of 41
Exercise 3: Filtering messages using Pipes and Filters

This next exercise introduces the use of a filter. Now that each message represents a single trade, w
e can determine whether a particular
message is of interest or if it should be discarded (or filtered out). The filter behaves in a very s
imilar way to the splitter and can be used with an
xpath expression. In the example of Duke Bank, some of the end of day trades we need to filter out an
y trades that do not have an amount such
as limit orders that have not been filled yet or options granted. These do not affect the trader book
s and can be safely discarded.
- Objective: Using the filter EIP
- Expected duration: 10 minutes
- Brief description: Learn how to use the filter keyword in IFL to discard messages from the end
of day trade batch.

Introducing Open ESB v3 Concepts

Message Filter EIP
A Message Filter examines the message content and passes the message to a service only if the message
content matches certain criteria,
otherwise the message is discarded.
Steps to Follow

Continuing from the previous exercise, we will take each message (i.e. each split trade) and filter i
t out if the trade amount is 0 (zero).
Step 1: Modify the IFL Definition
Expand the IFL Files tree within the new Integration Application you created in Exercise 1, and open
the existing
app.ifl
in the NetBeans
code pane. Modify the IFL definition to include the filter keyword as follows:
1.
#IFL - Integration Flow Language
file "source_file"
file "destination_file"
route do
from "source_file"
split xpath("/Batch/Trade")
filter xpath("/Trade/Amount>0")
to "destination_file"
end
Note:
Only messages that satisfy the filter will be allowed to filter through to the next pipe. Therefore i
n the example above, messages that do
not have a Trade Amount > 0 will be discarded.
Step 2: Build and deploy the Application
Build and deploy your application to the OSGi container as before.
Step 3: Testing the Application
To test the application, first remove the files in the
c:\hol6264\files\out
directory (or delete the entire directory). Now copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified fileDirectory e.g.
c:\hol6264\files\in
. The file should
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
20 of 41
be immediately processed and removed from the source directory and multiple new files created beginni
ng with
trade-?.xml
in the target
directory, where ? is incremental from the last batch of files created. You will notice that there ar
e less files created than before since the original
batchfile contains
two
trades with trade amount equal to zero. Therefore there should only be 8 instead or 10 trade-%d.xml
files. Inspect the
c:\hol6264\files\out
directory to confirm that the trades with amount equal to zero were in fact discarded.
Summary

In this exercise, you modified an existing integration flow in IFL to use a filter.
Now that we have discarded messages that we are not concerned with, we can go on to enrich the remain
ing trades before they are applied to
our trader books.


LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
21 of 41
Exercise 4: Enriching messages using JRuby services

This exercise introduces the use of web services to transform or enrich the trade messages. Now that
each message represents a single trade,
we can invoke a service to add content to each message. To demonstrate this in this example we will u
se a JRuby script which is really a type of
message translator or adapter which converts our messages into a format that will be understood by th
e target system. In the example of Duke
Bank, the target system will be the trader book systems and these systems require a local currency to
be present in the data which the batchfile
messages do not contain. The local currency therefore needs to be added to each message. For simplici
ty, we do not need to do any exchange
rate conversion.
- Objective: Writing and invoking a JRuby service
- Expected duration: 15 minutes
- Brief description: Learn how to write a JRuby script and invoke it from IFL to enrich each mess
age in the batch.

Introducing Open ESB v3 Concepts

JRuby services
Steps to Follow

The way that we invoke a web service is similar to how we used the filter EIP since the web service h
as an output message which we can use to
continue our flow. Following on from the previous exercise, we will invoke the JRuby service after th
e filter. As with our file service(s), we must
declare the service before we implement it.
Step 1: Modify the IFL Definition
Expand the IFL Files tree within the new Integration Application you created in Exercise 1, and open
the existing
app.ifl
in the NetBeans
code pane. Modify the IFL definition to declare the JRuby service and invoke it using the "to" keywor
d within the main route, as follows:
1.
#IFL - Integration Flow Language
file "source_file"
file "destination_file"
jruby "enrich_service"
route do
from "source_file"
split xpath("/Batch/Trade")
filter xpath("/Trade/Amount>0")
to "enrich_service"
to "destination_file"
end
Note:
Pressing CTRL + SPACE anywhere within the IFL window will pop up a list of service declaration types
and keywords, context-sensitive
to the current location of the cursor. This makes it possible to see which component types (file, res
t, scheduler, jruby etc...) are currently
supported.
Step 2: Creating the new JRuby service artifacts
Since we have declared the use of a new service, it is necessary to again generate the service artifa
cts for the new JRuby service. Again,
this is accessed from the NetBeans IDE by right-clicking on the code pane canvas and selecting
Generate Service Artifacts
.
1.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
22 of 41
Note:
Regenerating service artifacts does not 'reset' the custom properties you have already defined for ex
isting services. However, if you
were to rename or comment the service declaration, by default the service.properties will be removed
when regenerating service artifacts. It
is possible to change this default behaviour through configuration of the Fuji Maven plugin.
Generating service artifacts in this case actually generates the source code stubs for our JRuby serv
ice in a file named
service.rb
. This can
be found under
Other Sources
as shown above. The boilerplate code generated should look like:
require 'java'
require 'XPath'
require 'ESB'
include_class "javax.xml.namespace.QName"
@@service = QName.new "http://fuji.dev.java.net/application/[app]", "[service]"
def process(inMsg)
payload = inMsg.getPayload
# your code goes here
# return message
inMsg
end
2.
Modify the
service.rb
JRuby script to append a new element
LocalCurrency
to the
Trade
element and set its value to
USD
. The complete
code is as follows:
require 'java'
require 'XPath'
require 'ESB'
include_class "javax.xml.namespace.QName"
@@service = QName.new "http://fuji.dev.java.net/application/[app]", "[service]"
def process(inMsg)
payload = inMsg.getPayload
# your code goes here
3.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
23 of 41
puts "Got message payload"
# get the trade
trade = XPath.findNode(payload, "//Trade")
if trade
local_ccy = trade.getOwnerDocument.createElement("LocalCurrency")
local_ccy.setTextContent("USD")
trade.appendChild(local_ccy)
else
puts "Could not find Trade node in message"
end
# return message
inMsg
end
Note:
The use of
puts "output"
will generate a message in the server logfile for each message that is processed and is useful for
debugging your application.
Step 2: Build and deploy the Application
Build and deploy your modified application to the OSGi container as before.
Step 3: Testing the Application
To test the application, first remove the files in the
c:\hol6264\files\out
directory (or delete the entire directory). Now copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified fileDirectory e.g.
c:\hol6264\files\in
. The file should
be immediately processed and removed from the source directory and multiple new files created beginni
ng with
trade-?.xml
in the target
directory, where ? is incremental from the last batch of files created. If you open any of these file
s you will observe that they have a new
<localCurrency> element that is set to USD. Inspect the
c:\hol6264\files\out
directory to confirm that these trades were in fact enriched.
Summary

In this exercise, you modified an existing integration flow in IFL to call out to a JRuby script whic
h was connected to the service bus.
Now that we have enriched the messages, our trader books can accept our message format. But firstly,
we must ensure that we route our
messages to different trader books based on their content.


LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
24 of 41
Exercise 5: Routing messages based on content

This next exercise introduces the use of the Content-Based Router EIP to route messages to different
service endpoints based on data
contained within the actual message. You will use xpath as a way of checking specific field values co
ntained within the message. In the example
of Duke Bank, the target system will be the trader book systems. At Duke Bank, each trader book corre
sponds to each type of trading activity, so
trades for bonds go into the 'bond' trader book, cash trades go into the 'cash' book. All other trade
types such as buy-sellbacks go into the 'other'
trader book.
- Objective: Using the Content-Based Router to route messages
- Expected duration: 15 minutes
- Brief description: Learn how to add a content-based router construct in IFL.

Introducing Open ESB v3 Concepts

Content-based router EIP
The Content-Based Router examines the message content and routes the message onto a different route b
ased on data contained in the
message. The routing can be based on a number of criteria, such as existence of fields, specific fiel
d values, and so on.
Steps to Follow

Continuing from the previous exercise, following the enrich service, we will route messages based on
content. Although it is possible to
implement the content rules externally, for the purposes of this exercise we will implement fixed rul
es directly in IFL.
Step 1: Modify the IFL Definition
Expand the IFL Files tree within the Integration Application you updated in Exercise 4, and open the
existing
app.ifl
in the NetBeans code
pane. Modify the IFL definition to firstly comment / remove the output to the
destination_file
service since we now have multiple file
destinations and add a file service declaration for each of bond, cash and other.
1.
#IFL - Integration Flow Language
file "source_file"
#file "destination_file"
jruby "enrich_service"
file "bond_file"
file "cash_file"
file "other_file"
route do
from "source_file"
split xpath("/Batch/Trade")
filter xpath("/Trade/Amount>0")
to "enrich_service"
# to "destination_file"
end
We can now incorporate the CBR EIP within the main route using the
select
keyword to inspect and match upon the Type element within
the Trade message, as follows:
2.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
25 of 41
#IFL - Integration Flow Language
file "source_file"
#file "destination_file"
jruby "enrich_service"
file "bond_file"
file "cash_file"
file "other_file"
route do
from "source_file"
split xpath("/Batch/Trade")
filter xpath("/Trade/Amount>0")
to "enrich_service"
# to "destination_file"
select xpath ("/Trade/Type") do
when "BOND" route to "bond_file"
when "CASH" route to "cash_file"
else route to "other_file"
end
end
Note:
We are not restricted to using XPath for the various EIPs used in this hands on lab. Pressing CTRL +
SPACE after the select keyword
shows up a list of possibilities including
regexp
for a regular expression and
drools
for a dynamic, external rule applied using the Drools rules
engine.
Step 2: Creating the new service artifacts
Since we have declared the use of three new file services, it is necessary to again generate the serv
ice artifacts and modify the
service.properties for each of these. Again, this is accessed from the NetBeans IDE by right-clicking
on the code pane canvas and selecting
Generate Service Artifacts
.
Note:
Regenerating service artifacts will remove artifacts and customisations to
service.properties
for commented services such as
destination_file
above.
1.
Modify the generated service.properties for each of our trader books as follows:
bond_file:
2.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
26 of 41
file.use=literal
file.fileName=bond-%d.xml
file.pollingInterval=1000
file.fileDirectory=c:/hol6264/files/out
file.fileNameIsPattern=true
file.multipleRecordsPerFile=false
file.recordDelimiter=
cash_file:
file.use=literal
file.fileName=cash-%d.xml
file.pollingInterval=1000
file.fileDirectory=c:/hol6264/files/out
file.fileNameIsPattern=true
file.multipleRecordsPerFile=false
file.recordDelimiter=
other_file:
file.use=literal
file.fileName=other-%d.xml
file.pollingInterval=1000
file.fileDirectory=c:/hol6264/files/out
file.fileNameIsPattern=true
file.multipleRecordsPerFile=false
file.recordDelimiter=
Step 3: Build and deploy the Application
Build and deploy your modified application to the OSGi container as before.
Step 4: Testing the Application
To test the application, first remove the files in the
c:\hol6264\files\out
directory (or delete the entire directory). Now copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified fileDirectory e.g.
c:\hol6264\files\in
. The file should
be immediately processed and removed from the source directory and multiple new files created beginni
ng with
bond-0.xml
,
cash-0.xml
and
other-0.xml
in the target directory. If you open these files you will observe that their trade type corresponds
to the trader book represented in the
filename i.e. a Trade Type equal to cash will be in a file with a 'cash' prefix. The
<localCurrency>
element (set to USD) will also be present in
every generated file. Inspect each of the files in the
c:\hol6264\files\out
directory to confirm that these trades belong in the correct file and that
they were in fact enriched with the
<localCurrency>
tag.
Summary

In this exercise, you modified an existing integration flow in IFL to use a content-based router.
We no longer need separate messages for trades belong to a single trader book. In the next exercise,
we will aggregate the messages into a file
per trader book.


LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
27 of 41
Exercise 6: Aggregating multiple messages into a single output message

This exercise introduces the aggregate EIP which is used to take a set of one or more input messages
and create a single output message. In
the example of Duke Bank, each target system is a trader book system. At Duke Bank, each trader book
corresponds to each type of trading
activity, so trades for bonds go into the 'bond' trader book, cash trades go into the 'cash' book. Al
l other trade types such as buy-sellbacks go
into the 'other' trader book. The trader book systems are able to take multiple trades as input in a
single file per trader book - they do not need
trades to be individually stored as separate files. In fact, this would slow the performance of the t
rader book end of day activities. Therefore the
aggregate pattern must be used to batch up trades destined for each trader book into a single file.
- Objective: Using the Aggregate pattern to reassemble messages into a batch
- Expected duration: 15 minutes
- Brief description: Learn how to add the aggregate construct in IFL.

Introducing Open ESB v3 Concepts

Aggregate EIP
The purpose of the aggregate pattern is to take a set of one or more input messages and create from t
hat a single output message.
Steps to Follow

Continuing from the previous exercise, we will aggregate messages that have been routed based on cont
ent into a single 'set' which is then sent
to a file service as a single message. The IFL allows us to perform the aggregation within the conten
t-based selection performed in the main
route or to 'hand-off' control to a new route. The aggregate EIP allows us to control some properties
of the set to be created, such as the number
of messages to aggregate or a timeout window to hold messages for until they aggregated. For this exe
rcise, we will use a timeout window and
we will also use a feature to surround or envelope the generated messages with a &ltbatch> tag so tha
t each target file remains as valid XML
that the Trader Book systems can process.
Step 1: Modify the IFL Definition
Expand the IFL Files tree within the Integration Application you updated in Exercise 5, and open the
existing
app.ifl
in the NetBeans code
pane. Firstly, modify the IFL definition to declare an embedded route which performs the aggregate pa
ttern for all bond trades. This is
considered to be an 'embedded' route since it is declared in-line to the content-based selection that
we defined in the previous exercise.
The aggregate set will wait 15 seconds for trades to be aggregated into a single message and will env
elope the message with a <batch>
tag.
1.
#IFL - Integration Flow Language
file "source_file"
#file "destination_file"
jruby "enrich_service"
file "bond_file"
file "cash_file"
file "other_file"
route do
from "source_file"
split xpath("/Batch/Trade")
filter xpath("/Trade/Amount>0")
to "enrich_service"
# to "destination_file"
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
28 of 41
select xpath ("/Trade/Type") do
when "BOND" do
route do
aggregate set ("timeout=15s,header=<Batch>,trailer=</Batch>")
to "bond_file"
end
end
when "CASH" route to "cash_file"
else route to "other_file"
end
end
We can now move on to making the same changes for both cash and 'other' trades. This time we will use
named routes rather than
embedded routes, as follows:
2.
#IFL - Integration Flow Language
file "source_file"
#file "destination_file"
jruby "enrich_service"
file "bond_file"
file "cash_file"
file "other_file"
route do
from "source_file"
split xpath("/Batch/Trade")
filter xpath("/Trade/Amount>0")
to "enrich_service"
# to "destination_file"
select xpath ("/Trade/Type") do
when "BOND" do
route do
aggregate set ("timeout=15s,header=<Batch>,trailer=</Batch>")
to "bond_file"
end
end
when "CASH" route to
"cash_route"
else route to
"other_route"
end
end
route "cash_route" do
aggregate set ("timeout=15s,header=<Batch>,trailer=</Batch>")
to "cash_file"
end
route "other_route" do
aggregate set ("timeout=15s,header=<Batch>,trailer=</Batch>")
to "other_file"
end
Note:
In the above IFL, we have had to change the CASH and 'else' routes for the content-based router to pi
pe to the new named routes.
Step 3: Build and deploy the Application
Build and deploy your modified application to the OSGi container as before.
Step 4: Testing the Application
To test the application, first remove the files in the
c:\hol6264\files\out
directory (or delete the entire directory). Now copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified fileDirectory e.g.
c:\hol6264\files\in
. The file should
be immediately processed and removed from the source directory and new files created (approximately 1
5 seconds later) with the names
bond-?.xml
,
cash-?.xml
and
other-?.xml
in the target directory, where ? is incremental from the last batch of files created.
If you open these files you will observe that they each contain multiple trades, enveloped in a
<batch>
tag. All the trades within a single file will
be of the same type and that will correspond to the trader book represented in the filename e.g. all
trades with Trade Type equal to cash will be
in the file
cash-?.xml
. The
<localCurrency>
element (set to USD) will also be present in every generated file. Inspect each of the files in the
c:\hol6264\files\out
directory to confirm that these trades belong in the correct file and that they were in fact enriche
d with the
<localCurrency>
field.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
29 of 41
Summary

In this exercise, you modified an existing integration flow in IFL to use an aggregation of messages
into a single output message.
In the next exercise, we will add a wire-tap to 'peek' at the messages as they are being processed an
d without interrupting the existing flow.


LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
30 of 41
Exercise 7: Archiving messages using the wire tap

This exercise introduces the wire tap EIP which is used to take a copy of a message and do something
with it in parallel and independently to
the original message flow. In the example of Duke Bank, every bulk trade file that is processed by ou
r integration application needs to be
recorded in an archive file for auditing purposes. This needs to happen before the trade messages are
enriched, filtered or split so that the file
can be backed up and replayed if necessary. Therefore the batch files must be tee'd off to an archive
file at the start of the flow.
- Objective: Using the Wire Tap pattern to archive end of day batch files
- Expected duration: 10 minutes
- Brief description: Learn how to add the wire tap pattern in IFL.

Introducing Open ESB v3 Concepts

Wire Tap EIP
The purpose of the Wire Tap pattern (also known as Tee) is to tap into a message path, make a copy of
the original message for alternate
independent parallel processing and let the original message flow (unmodified) to the original recipi
ent. This is very useful in cases when a
snapshot of a message needs to be taken without altering/disturbing the original message flow.
Steps to Follow

Continuing from the previous exercise, we will simply add a wire tap once the message is received fro
m the source file. This could be used to
initiate a named route (as used by the content-based router in the previous exercise). In the case of
Wire Tap, a copy of the message is taken
when it is tee'd and any named or embedded route would run in parallel to the original flow.
Step 1: Modify the IFL Definition
Expand the IFL Files tree within the Integration Application you updated in Exercise 6, and open the
existing
app.ifl
in the NetBeans code
pane. Firstly, modify the IFL definition to declare a new file service that will be used to store the
archived file. Next add the tee before the
split and immediately after it is received from the source file, as shown below:
1.
#IFL - Integration Flow Language
file "source_file"
#file "destination_file"
jruby "enrich_service"
file "bond_file"
file "cash_file"
file "other_file"
file "archive_file"
route do
from "source_file"
tee "archive_file"
split xpath("/Batch/Trade")
filter xpath("/Trade/Amount>0")
to "enrich_service"
# to "destination_file"
select xpath ("/Trade/Type") do
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
31 of 41
when "BOND" do
route do
aggregate set ("timeout=15s,header=<Batch>,trailer=</Batch>")
to "bond_file"
end
end
when "CASH" route to "cash_route"
else route to "other_route"
end
end
route "cash_route" do
aggregate set ("timeout=15s,header=<Batch>,trailer=</Batch>")
to "cash_file"
end
route "other_route" do
aggregate set ("timeout=15s,header=<Batch>,trailer=</Batch>")
to "other_file"
end
Note:
We can also use tee with a named route but this does not change the processing order or functionality
.
Step 2: Creating the new service artifacts
Since we have declared the use of a new file service, it is necessary to again generate the service a
rtifacts and modify the newly-created
service.properties
file. Again, this is accessed from the NetBeans IDE by right-clicking on the code pane canvas and se
lecting
Generate
Service Artifacts
.
1.
Modify the generated service.properties for our achive file as follows:
file.use=literal
file.fileName=archive-%d.xml
file.pollingInterval=1000
2.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
32 of 41
file.fileDirectory=c:/hol6264/files/archive
file.fileNameIsPattern=true
file.multipleRecordsPerFile=false
file.recordDelimiter=
Step 3: Build and deploy the Application
Build and deploy your modified application to the OSGi container as before.
Step 4: Testing the Application
To test the application, first remove the files in the
c:\hol6264\files\out
directory (or delete the entire directory). Now copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified fileDirectory e.g.
c:\hol6264\files\in
. The file should
be immediately processed and removed from the source directory. The archive will be created as
archive-0.xml
in the target directory
c:\hol6264\files\archive
and this should not affect the trading book files being created (approximately 15 seconds later) wit
h the names
bond-?.xml
,
cash-?.xml
and
other-?.xml
in the target directory
c:\hol6264\files\out
.
Summary

In this exercise, you modified an existing integration flow in IFL to use a wire tap to archive messa
ges into a new archive file without affecting the
rest of the message flow. Our trader book integration application is now fully-functional and complet
e!
In the final exercise, we will look at an alternative way to wire these patterns together using a web
front-end.


LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
33 of 41
Exercise 8: Using the Web GUI

The final exercise requires that you build part or all of the scenario again but this time using a we
b front-end instead of directly in IFL. While you
are doing so, compare and contrast the use of the web UI versus using the domain specific language (i
n IFL). Consider which are you more
comfortable working with and why.
- Objective: Using the Web GUI to implement EIPs
- Expected duration: 20 minutes
- Brief description: Learn how to build patterns in the web GUI.

Introducing Open ESB v3 Concepts

Message Flow Editor (Web GUI)
The web front-end allows developers to create, check-in, deploy and monitor integration projects with
out the need for an IDE.
Steps to Follow

Starting afresh, let's recreate the integration application in stages - this time graphically rather
than in IFL. While you are attempting this
exercise, ask yourself which is the more convenient way to work - the domain-specific language (i.e.
IFL) or the web front-end.
Step 1: Start the Fuji editor
With the Fuji server running, navigate your web browser to
http://localhost:8080/fuji/editor
. Your browser should quickly render an interactive
canvas, as shown below. Components (i.e. service definition adapters and EIPs) can be dragged and dro
pped onto the canvas from the
palette on the left hand side.
Note:
If port 8080 clashes with another service on your machine, you can change this by stopping the Fuji S
erver, navigating to the
fuji/conf
directory where you unpacked the Fuji runtime to and modifying the following line in
config.properties
:
1.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
34 of 41
org.osgi.service.http.port=8080
If you must change the port, start the server and point your browser to http://localhost:
XXXX
/fuji/editor
Step 2: Re-implement Message Flow (from Exercises 1 to 4)
Drag and drop two File Adapters, a Split, Filter and JRuby service from the palette and connect them
up as shown below:
1.
Double click on the "file-1" component to set the service properties for the input file service. This
will open a dialog box where you can set
basic, display and advanced properties. Set the File Directory, File Name values as per Exercise 1 in
the Basic tab as shown below. Also
set the Display Name to 'Batch' (in the Display tab) and click
Save
to save your changes.
2.
Double click on the "split" component and, with XPath selected from the dropdown, enter the split exp
ression used in Exercise 2 (without
any brackets or quotes), as shown below. Click
Save
to save your changes.
3.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
35 of 41
Likewise, double click on the "filter" component and, with XPath selected from the dropdown, enter th
e filter expression used in Exercise 3
(without any brackets or quotes), as shown below. Click
Save
to save your changes.
4.
Double click on the "jruby-1" component and enter the JRuby code from Exercise 4 directly into the di
alog box. You can also change the
display name to 'enrich' from the Display tab. Click
Save
to save your changes.
5.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
36 of 41
Double click on the "file-2" component and set the properties as shown below. You can also change the
display name to 'trades' from the
Display tab. Click
Save
to save your changes.
Note:
Remember to check the checkbox
Name is Pattern
, as shown above.
6.
Step 3: Save and deploy the Application
Click the
Save
button shown below to save your message flow. When you are prompted to enter a code name and display
name, use
hol6264ui
for both and click
Save
. This will check in your model to subversion, which is already configured and running in the Fuji se
rver
1.
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
37 of 41
OSGi runtime.
Note:
It is also possible to view the IFL for this message flow by clicking the rightmost button
View IFL Source
.
Before deploying the new message flow, uninstall the existing service assembly (i.e. application bund
le). To do so, firstly navigate to the
Services tab within the NetBeans IDE, expand the available Service Assemblies under the Fuji Server a
nd right-click the application and
select
Uninstall
, as shown below.
2.
Click the
Deploy
button shown below to deploy the new message flow from the web GUI.
3.
Step 4: Testing the Application
To test the application, first remove the files in the
c:\hol6264\files\out
directory (or delete the entire directory). Now copy the source file
batchtrades-in.xml
which can be found in the artifacts directory for this lab to the specified fileDirectory e.g.
c:\hol6264\files\in
. The file should
be immediately processed and removed from the source directory and multiple new files created beginni
ng with
trade-?.xml
in the target
directory, where ? is incremental from the last batch of files created. If you open any of these file
s you will observe that they have a new
<localCurrency> element that is set to USD. Inspect the
c:\hol6264\files\out
directory to confirm that these trades were in fact enriched.
Summary

In this exercise, you created another integration flow (or message flow) using a simple GUI and witho
ut using IFL. Insofar, you have
implemented a subset of the trader book integration functionality but the GUI can be used to implemen
t the same functionality that is available in
IFL.
It is recommended that you finish implementing the complete scenario at your convenience so that you
end up with the complete flow shown
below, which includes the wiretap, content-based router and aggregate patterns:
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
38 of 41
We sincerely hope you enjoyed the lab! Now that you have understood the basics of EIP-based developme
nt using OpenESB v3, please take a
look at what else OpenESB v3 (Project Fuji) has to offer at
https://fuji.dev.java.net/
.

LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
39 of 41
Congratulations!
You have successfully completed LAB-6264: Implementing Enterprise Integration Patterns with GlassFish
v3 and OpenESB v3.
Where to send questions or feedbacks on this lab and public discussion forums:
You can send technical questions via email to the authors of this Hands-on lab (and experts on the su
bject).
Please post questions that are relevant only to this hands-on lab.
You can send your other questions to the public users alias:
users@open-esb.dev.java.net
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
40 of 41
About Sun
|
About This Site
|
Newsletters
|
Contact Us
|
Employment
How to Buy
|
Licensing
|
Terms of Use
|
Privacy
|
Trademarks


Copyright
1994-2009
Sun Microsystems, Inc.
A Sun Developer Network
Site
Unless otherwise licensed,
code in all technical manuals
herein (including articles, FAQs,
samples) is provided under this
License
.


Sun Developer RSS Feeds
LAB-6264: Implementing Enterprise Integration Patterns with GlassFish v3 and OpenESB v3
41 of 41