Application Development for IBM WebSphere Process Server 7 and ...

groupertomatoInternet and Web Development

Jul 30, 2012 (4 years and 8 months ago)

704 views

P U B L I S H I N G
professi onal experti se di sti l l ed


Application Development for IBM
WebSphere Process Server 7 and
Enterprise Service Bus 7

Swami Chandrasekaran
Salil Ahuja

Chapter No.4
"Building Your Hello Mediation Project"
In this package, you will find:
A Biography of the authors of the book
A preview chapter from the book, Chapter NO.4 "Building Your Hello Mediation
Project"
A synopsis of the book’s content
Information on where to buy this book
About the Authors
Swami Chandrasekaran works for IBM as an Industry Executive Architect for its
Software Group—Industry Solutions. He provides architectural leadership for IBM
tooling / product suite and works with its global customers in delivery of best in class
solutions. His expertise includes next-generation networks, OSS/BSS, SOA, Dynamic
BPM and modern web-based architectures, and TM Forum Frameworx (NGOSS). He has
travelled to almost 24 countries and is constantly sought after within the company for his
technical leadership and client skills. His credits include technical and strategic interface
with various senior executive and institutions, including Fortune 100/500 companies and
international clients. He is the SME and Co-Lead Architect for the WebSphere Telecom
Content Pack.
He has presented at several conferences, authored articles within IBM, articles featured in
BearingPoint Institute for Thought Leadership, and also holds several patent disclosures.
He previously worked for BearingPoint and also for Ericsson Wireless Research. He lives
with his wife Ramya and daughter Harshitha in Dallas, Texas. He is an avid video gamer
and during his free time he likes to write at http://www. nirvacana.com. He holds a
Master's in Electrical Engineering from the University of Texas, Arlington.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book



There are many people whom I would like to thank. I thank my IBM
management team for encouraging and allowing me the time needed to
write this book. I'd like to thank all my mentors and my family members
including my in-laws who have helped and guided me over the last
several years. I'd like to thank the staff at Packt Publishing, including
Poorvi Nair, Sarah Cullington, Reshma Sundaresan, and Dhwani Devater
for their assistance in this effort. Finally and most importantly, I thank
my wife, Ramya and daughter, Harshitha for encouraging me to take this
immensely challenging journey and for all the weekends and time they
have sacrificed so that this book could become a reality.
I dedicate this book to my parents, my Gurus, and Ramya.

Salil Ahuja currently works for IBM as a Technical Lead in their AIM Customer
Programs group. He has been working in the IT industry for over eight years in a variety
of positions ranging from development to client services. As a certified IBM SOA
Designer, he has spent the majority of his career consulting with large healthcare players
on the design, implementation, and delivery of standards-based enterprise SOA solutions.
In his current role, he works with premium IBM clients to educate and enable them on
the leading edge technologies within the IBM Business Process Management portfolio.
Salil is a sought after expert on HIPAA and Health Level 7 Clinical Data Architecture,
and has presented to various IBM labs on healthcare information exchange in the
provider payer space.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


He lives in Austin, Texas with his wife Priyanka. In his spare time he enjoys the
outdoors, theater, and playing or watching basketball whenever possible. He can be
contacted on LinkedIn at http://www.linkedin.com/pub/salil-ahuja/0/b92/186.
This book is a result of a collaborative effort and I would like to
acknowledge those who helped make it possible. First, I thank IBM
management for approving the undertaking of this book project and
Packt publishing for helping materialize the book. Also, I would like to
extend thanks to my co-author, Swami Chandrasekaran, for bringing this
opportunity to me. We worked countless hours to make this book a
reality. I could not have completed this book without the continuous
support from my mentors, friends, and family - thank you to all of you.
Specifically, I would like to thank my parents, Sudha and Suvir, and my
brother, Nitin, for their constant support and encouragement that allows
me to continuously take on new challenges like this. And lastly, a very
special thanks to my wife Priyanka - thank you for your encouragement,
understanding, and patience that gave me the space and environment that
allowed me to write this book.
I dedicate this book to my parents - Sudha and Suvir, who have always
put my needs before theirs and laid the foundation for the life that I have
built.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book



Application Development for IBM
WebSphere Process Server 7 and
Enterprise Service Bus 7
By adopting an SOA approach in Business Process Management (BPM), you can make
your application flexible, reusable, and adaptable to new developments. This book
introduces basic concepts of Business Integration, SOA Fundamentals, and SOA
Programming Model, and implements them in numerous examples.
You will learn to analyze business requirements and rationalize your thoughts to see if an
SOA approach is appropriate for your project. Using the principles of Business Process
Management, Service Oriented Architecture, using IBM WebSphere Process Server
7(WPS), and WebSphere Enterprise Service Bus 7 (WESB), the authors guide you
through building an Order Management application from scratch.
What This Book Covers
Chapter 1, Introducing IBM BPM and ESB, discusses the core capabilities needed for a
process integration approach, IBM’s SOA Reference Architecture, and IBM’s Business
Process Management platform including WebSphere Process Server (WPS) and
WebSphere Enterprise Service Bus. It also discusses IBM’s BPM enabled by SOA
lifecycle methodology.
Chapter 2, Installing the Development Environment, takes you through the process of
installing and setting up the WID development environment. During the course of setting
up the environment, it takes a quick peek into some of the fundamentals of WID, key
concepts, and terms. It takes us through a crash course in using WID and also shows us
how to navigate using WID as well as some of the key activities that one would perform
and how to perform them.
Chapter 3, Building your Hello Process Project, discusses the fundamental SOA
programming model concepts and helps us understand how these concepts apply in the
context of WID/WPS/WESB. It also discusses, in detail, the Service Component
Architecture (SCA). It also rounds up the SOA programming model discussions with
BPEL. It also provides instructions on building our first business processbased
application—Greeting Solution. Though the application does a simple job, the purpose of
building this application is to understand how to go about using WID, the various
capabilities of WID, and how to apply these capabilities. It also briefly touches upon
logging, debugging, and troubleshooting basics and exporting projects from WID.
Chapter 4, Building your Hello Mediation Project, provides an overview of WESBbased
programming fundamentals including Service Message Objects (SMO) and Mediation


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Flows. It helps us to build our first HelloMediationModule. Instructions are provided to
create, implement, and assemble the HelloMediationModule and HelloProcess. These
modules are then deployed on the WebSphere Process Server, which is a part of the WID
Unit Test Environment.
Chapter 5, Business Process Choreography Fundamentals, discusses the various aspects
and functions of WPS and WESB that are absolutely and fundamentally essential. The
topics covered are Business Process (WS-BPEL), Business Objects, Business Rules,
State Machines, Visual Snippets, Compensation, Fault Handling, and Control Structures .
Chapter 6, Mediations Fundamentals, performs an in-depth study of mediation flows,
mediation primitives, and adapters. It walks us through the various aspects and concepts
about Mediation primitives and Service Message Objects that are absolutely fundamental
and essential. The other topics that this chapter touches upon are Adapters and
Dynamic routing.
Chapter 7, Sales Fulfillment Application for JungleSea Inc., guides you through the steps
involved in architecting the new Sales Fulfillment Application. It also identifies the
appropriate WPS and WESB components that will have to be built.
Chapter 8, Walk the Talk, provides details around the assembly phase of the IBM SOA
Reference Architecture. It discusses how to assemble components to catalog their
interface and data types in shared libraries that can then be leveraged by the different
modules of the Sales Fulfillment Application.
Chapter 9, Building the Order Handling Processes, guides us through how to build the
Process Services modules, namely, ProcessServices-OrderHandling and ProcessServices-
CustomerInterfaceManagement, and the associated businesses processes (BPELs). It
starts with the creation of shared libraries and then provides a top-down breakup of the
process, business, and access services that will be developed and assembled for the Sales
Fulfillment Application. It covers severaltopics including BPEL development steps,
using business rules in the process, implementing human tasks, usage of control
structures, fault handling including compensation, correlation sets, and discusses how to
test the business processes end-to-end, once the Business Service and Access Service
modules have been built.
Chapter 10, Integration with Various Applications, walks you through the
implementation of the first working version of the Sales Fulfillment Application along
with all the business service modules (with the associated components) and the
corresponding Access Services (with the associated components). Then it discusses how
to perform unit testing and component testing. It also helps in the implementation of the
Business and Access Service modules. It also provides a step-by-step method to
implement them and unit test them.
Chapter 11, Business Space, provides an overview of the Business Space and touches
upon some of the basic concepts and functionalities to help you get started.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book



Chapter 12, Deployment Topologies, provides information regarding the fundamental
aspects to take into consideration when choosing a deployment topology. It discusses the
fundamentals behind WebSphere Application Server Network Deployment (WAS ND),
which is the base foundation platform for the IBM BPM portfolio of products including
WPS and WESB. Then it discusses clustering, how to do vertical and horizontal
clustering, and briefly looks at the databases used by WPS. It also discusses the several
deployment patterns available from IBM and how, from them, we can choose the Remote
Messaging and Remote Support topology pattern (gold topology) as the production
topology.
Chapter 13, Management, Monitoring and Security, shows us how to perform some of
the most common solution administration tasks, including how to use the admin console
and various activities we can perform using it. Then it discusses installing versioned SCA
modules and how to monitor the applications deployed on WPS/ WESB. It also discusses
various tools and capabilities provided in WID/WPS/WESB to monitor the applications
and components.
Appendix, WID, WPS, and WESB Tips, Tricks, and Pointers will be a random yet useful
collection of typical questions, how-tos, and tips on different topics when developing
with WID, WPS, and WESB. It will cover some of the most common questions related to
WID tooling, managing, and administering the runtime. This chapter is meant to be a
quick reference where we scratch the surface of some advanced topics that warrant a
book by itself. It aims to provide you with the right pointers so that you can get to the
appropriate information and not have to search for it.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building Your Hello Mediation
Project
This chapter will be along similar lines as the previous chapter, where you will
build your fi rst HelloWorld WebSphere Enterprise Service Bus (WESB) mediation
application and WESB mediation fl ow-based application. This chapter will then give
an overview of Service Message Object (SMO) standards and how they relate to
building applications using an SOA approach. At the completion of this chapter, you
will have an understanding of how to begin building, testing, and deploying WESB
mediations including:
• Overview of WESB-based programming fundamentals including
WS-*? standards and Service Message Objects (SMOs)
• Building the fi rst mediation module project in WID
• Using mediation fl ows
• Deploying the module on a server and testing the project
• Logging, debugging, and troubleshooting basics
• Exporting projects from WID


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
108
]
WS standards
Before we get down to discussing mediation fl ows, it is essential to take a
moment and acquaint ourselves with some of the Web Service (WS) standards
that WebSphere Integration Developers (WIDs) comply with. By using WIDs,
user-friendly visual interfaces and drag-and-drop paradigms, developers are
automatically building process fl ows that are globally standardized and compliant.
This becomes critical in an ever-changing business environment that demands
fl exible integration with business partners.
Here are some of the key specifi cations that you should be aware of as defi ned by the
Worldwide Web Consortium (W3C):
• WS-Security: This is one of the secure standards used to secure Web Service
at the message level, independent of the transport protocol. To learn more
about WID and WS-Security refer to
http://publib.boulder.ibm.com/
infocenter/dmndhelp/v7r0mx/topic/com.ibm.wbit.help.runtime.doc/
deploy/topics/cwssecurity.html
.
• WS-Policy: A framework that helps defi ne characteristics about Web Services
through policies. To learn more about WS-Policy refer to:
http://www.w3.org/TR/ws-policy/
.
• WS-Addressing: This specifi cation aids interoperability between Web
Services, by standardizing ways to address Web Services and by providing
addressing information in messages. In version 7.0, enhancements were
made to WID to provide Web Services support for WS-Addressing
and Attachments. For more details about WS-Addressing refer to
http://www.w3.org/Submission/ws-addressing/
.
What are mediation fl ows?

As we discussed in Chapter 1, Introducing IBM BPM and ESB in an SOA, service
consumers and service providers use an ESB as a communication vehicle. When
services are loosely coupled through an ESB, the overall system has more fl exibility
and can be easily modifi ed and enhanced to meet changing business requirements.
We also saw that an ESB by itself is an enabler of many patterns and enables
protocol transformations and provides mediation services, which can inspect,
modify, augment and transform a message as it fl ows from requestor to provider. In
WebSphere Enterprise Service, mediation modules provide the ESB functionality.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
109
]
The heart of a mediation module is the mediation fl ow component, which provides
the mediation logic applied to a message as it fl ows from a service consumer to
a provider. The mediation fl ow component is a type of SCA component that is
typically used, but not limited to a mediation module. A mediation fl ow component
contains a source interface and target references similar to other SCA components.
The source interface is described using WSDL interface and must match the WSDL
defi nition of the export to which it is wired. The target references are described using
WSDL and must match the WSDL defi nitions of the imports or Java components
to which they are wired. The mediation fl ow component handles most of the ESB
functions including:
• Message fi ltering which is the capability to fi lter messages based on the
content of the incoming message.
• Dynamic routing and selection of service provider, which is the capability to
route incoming messages to the appropriate target at runtime based on
predefi ned policies and rules.
• Message transformation, which is the capability to transform messages
between source and target interfaces. This transformation can be defi ned
using XSL stylesheets or business object maps.
• Message manipulation/enrichment, which is the capability to manipulate
or enrich incoming message fi elds before they are sent to the target. This
capability also allows you to do database lookups as needed.
• If the previous functionalities do not fi t your requirements, you have the
capability of defi ning a custom mediation behavior in JAVA.
The following diagram describes the architectural layout of a mediation fl ow:


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
110
]
In the diagram, on the left-hand side you see the single service requester or source
interface and on the right-hand side are the multiple service providers or target
references. The mediation fl ow is the set of logical processing steps that effi ciently
route messages from the service requestor to the most appropriate service provider
and back to the service requestor for that particular transaction and business
environment. A mediation fl ow can be a request fl ow or a request and response fl ow.
In a request fl ow message the sequence of processing steps is defi ned only from the
source to the target. No message is returned to the source. However, in a request and
response fl ow message the sequence of processing steps are defi ned from the single
source to the multiple targets and back from the multiple targets to the single source.
In the next section we take a deeper look into message objects and how they are
handled in the mediation fl ows.
Mediation primitives
What are the various mediation primitives available in WESB?
Mediation primitives are the core building blocks used to process the request and
response messages in a mediation fl ow.
• Built-in primitives, which perform some predefi ned function that is
confi gurable through the use of properties.
• Custom mediation primitives, which allow you to implement the function
in Java.
• Mediation primitives have input and output terminals, through which the
message fl ows. Almost all primitives have only one input terminal, but
multiple input terminals are possible for custom mediation primitives.
• Primitives can have zero, one, or more output terminals.
• There is also a special terminal called the fail terminal through which the
message is propagated when the processing of a primitive results in
an exception.
The different types of mediation primitives that are available in a mediation fl ow,
along with their purpose, are summarized in the following table:
Service invocation
Service Invoke Invoke external service, message modifi ed with result
Routing primitives
Message Filter Selectively forward messages based on element values
Type Filter Selectively forward messages based on element types


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
111
]
Routing primitives
Endpoint Lookup Find potential endpoint from a registry query
Fan Out Starts iterative or split fl ow for aggregation
Fan In Check completion of a split or aggregated fl ow
Policy Resolution Set policy constrains from a registry query
Flow Order Executes or fi res the output terminal in a defi ned order
Gateway Endpoint Lookup Finds potential endpoint in special cases from a registry
SLA Check Verifi es if the message complies with the SLA
UDDI Endpoint Lookup Finds potential endpoints from a UDDI registry query
Transformation primitives
XSL Transformation Update and modify messages using XSLT
Business Object Map Update and modify messages using business object maps
Message element setter Set, update, copy, and delete message elements
Set message type Set elements to a more specifi c type
Database Lookup Set elements from contents within a database
Data Handler Update and modify messages using a data handler
Custom Mediation Read, update, and modify messages using Java code
SOAP header setter Read, update, copy, and delete SOAP header elements
HTTP header setter Read, update, copy, and delete HTTP header elements
JMS header setter Read, update, copy, and delete JMS header elements
MQ header setter Read, update, copy, and delete MQ header elements
Tracing primitives
Message logger Write a log message to a database or a custom destination
Event emitter Raise a common base event to CEI
Trace Send a trace message to a fi le or system out for debugging
Error handling primitives
Stop

Stop a single path in fl ow without an exception

Fail

Stop the entire fl ow and raise an excepti
on
Message Validator

Validate a message against a schema and assertions
Mediation subfl ow primitive
Subfl ow

Represents a user-defi ned subfl ow



For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
112
]
Service Message Objects (SMO)
The primary function of a mediation fl ow is to operate on a message between
endpoints, where a service requestor and a service provider are those endpoints.
However, this presents a problem. The fi rst point is that a message can take on many
different forms because the protocol used to send a message, whether JMS or Web
services, can vary. Also, each message is different depending upon the interface
and operation associated with the message and whether this is the request side or
response side of the interaction between the requestor and provider.
The next point to understand is that within the mediation fl ow, mediation primitives
are used to operate on the message. Mediation primitives examine and update the
message contents and therefore must understand what is contained in the message.
The solution is to provide mediation primitives with some kind of a common
representation of a message, and that is what a Service Message Object does. SMOs
provide a common representation of a message that accounts for differing protocols
and differing interfaces, operations, and parameters that the message represents.
SMOs are built using Service Data Object (SDO) technology. SDO uses a schema that
describes the basic structure of an SMO which is composed of three major sections.
The body of the message represents the specifi c interface, operation, and parameters
relevant to this message. The headers section of the message represents information
about the protocol over which the message was sent. The context section represents
data that is important to the internal logic of the fl ow itself. Each of these major
sections of the SMO is examined in more detail in subsequent slides. The data within
an SMO is accessed using SDO, specifi cally the SDO DataObject, which enables
access using XPath, the generic DataObject APIs, and some SMO-specifi c APIs that
are aware of the SMO schema.
The service requestor and service provider interact with the bus through the bindings
for the exports and imports of the mediation service module. The data representing the
message depends on the binding used for exports and imports. If the primitives in the
mediation fl ow component had to support the data representation for all the various
bindings, it would be diffi cult to implement primitives. For this reason, the fi rst
thing the runtime does is that it converts the binding-specifi c data into common data
structure, called Service Message Objects (SMO).


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
113
]
The SMO interface extends the DataObject interface, which is defi ned by the Service
Data Object (SDO), similar to other business objects used in WebSphere Process Server.
SMO includes the message headers, message data (payload) and context information
and provides an interface to access and modify the SMO data, including headers,
payload, and context information. In addition, the SDO data can be accessed using the
XPath reference mechanism. The mediation module input contains binding-specifi c
data representation. The mediation module output import binding dictates the data
representation that must be sent to the output message. As a result, there is a lack of
consistency in data representation and if the mediation fl ow primitives had to handle
all the different data representation, it would become a huge challenge. To solve this
problem, the data from binding-specifi c interaction is converted to a common data
structure called the Service Message Object (SMO).
If the mediation primitives in a message fl ow require a temporary area to save data
for other primitives down the message fl ow or need data set in the request fl ow to
be available during the response fl ow, context information is used as a scratch pad.
There are two types of context information: Transient context, as the name suggests, is
temporary and available only on the specifi c request fl ow or the response fl ow but is
not carried from the request to the response fl ow, and is therefore stored in memory.
Correlation context is the second type of context data that is available for the duration
of the complete request/response fl ow. Data set in the request fl ow is available for all
the primitives in the response fl ow. Any primitive can modify the context information
and downstream primitives in the message fl ow will have access to that information.
The context data are represented as data objects and the structure is inserted in the
SMO structure at the start of the mediation fl ow.
Creating mediation modules
You now have an understanding of the basic concepts of mediation and mediation
fl ows. Let's try implementing these concepts in a simple HelloMediationModule.
For this we shall build upon our example from the previous chapter. In the previous
chapter we had built a simple HelloProcess integration solution. We will use the
HelloProcess requirements as the basis and will build a mediation fl ow based
solution that will satisfy the following requirements:
• It should be capable of getting user input and more specifi cally their fi rst
name, last name, and age


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
114
]
• It should return a customized greeting based on their age
° Ages 25 and younger it should return—"What's up <FirstName
LastName>! Congrats on your fi rst hello world mediation fl ow"
° Ages 26 to 65 it should return—"Hey <FirstName LastName>!
Congrats on your fi rst hello world mediation fl ow"
° Ages 65 and above it should return—"Greetings <FirstName
LastName>! Congrats on your fi rst hello world mediation fl ow"
• The solution should be exposed through Web Services
If you remember, we used a XPath object within the BPEL to develop the logic to
return the custom greeting message. In this example, we shall build this logic in a
mediation fl ow using the message fi lter primitive along with the use of a correlation
context and message element setter primitive we just learnt.
Creating the Hello Mediation Flow
In order to create Hello Mediation Flow,
1. In a new WID workspace, create a new Integration Solution in WID, File |
New | Integration Solution and name it Greeting_Solution.
2. Import the GreetingLibrary that we created in the previous chapter
3. Click on File | New and select Mediation Module from the context menu.
Give the module the name HelloMediationModule and the name of the
mediation component as GreetingsFlow as shown in the following fi gure:


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
115
]
4. Specify the GreetingLibrary in the required libraries wizard screen and
proceed to next.
5. Make this mediation module part of the Greeting_Solution Integration
Solution. Click on the Finish button.
Upon clicking Finish the mediation module gets created and the Assembly diagram
opens for the new mediation module. On the canvas of this assembly diagram you
will notice that the GreetingsFlow mediation fl ow component has been created.
We will specify the HandleGreetingMessage as the interface on this mediation
fl ow component.
This can be done by as shown in the following steps:
1. Right-click on GreetingsFlow | Add... | Interface | HandleGreetingMessage.
Click on the OK
button, as shown in the following diagram:


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
116
]
2. Right-click on HelloMediationModule | Generate Export... | Web Service
Binding | SOAP1.1/HTTP. Click on the OK button,
as shown in the
following screenshot:
The Assembly Diagram should now look like the following screenshot:


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
117
]
Implementing the HelloMediationModule
1. Right-click on HelloMediationModule. Select Generate Implementation
and then select New Folder (or you can double-click on the component).
Enter the name of the new folder as com.junglesea.solution.greeting.
mediation and click on the OK button.
2. This will open the mediation fl ow overview. Click on the returnGreeting
operation and select Blank Mediation Flow, as shown in the
following screenshot:
3. The mediation fl ow editor should now be open. We shall cover details about
this editor in Chapter 6, Mediations Fundamentals. For now we shall focus on
building the GreetingsFlow and getting a basic understanding of mediation
fl ow components.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
118
]
4. We will fi rst use a "Message Filter" primitive to route the incoming message
based on age value. continue with this bullet. In the palette of the mediation
editor under Routing category, select and drag the Message Filter primitive
onto the canvas. Rename the message fi lter primitive to AgeBasedFilter by
clicking on the MessageFilter1 text below the component, as shown in the
following screenshot:
Message Filter primitive is used to route messages to target
based on a pre-defi ned condition or fi lter. In our example we
will use this primitive to check the age in the incoming message
and accordingly route the message to one of the three custom
mediation primitives that will print the response greeting in
Chapter 6, Mediations Fundamentals covers more in-depth details.
5. Select AgeBasedFilter and open Properties, and select the Terminal tab
on the left-hand side. Rename the Output terminal match1 to LessThan25.
Right-click on Output terminal (shown in the following fi gure) and
select Add Output Terminal, and add one more output terminals named
MoreThan25LessThan65 as shown in the following screenshot:


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
119
]
6. Wire the Input node to the AgeBasedFilter primitive.
7. From the palette of the mediation editor under the Transformation category,
select and drag the Custom Mediation primitive on to the canvas. Name
this primitive SayGreetingWhatsUp. Repeat the same and create two more
custom mediation primitives named SayGreetingWhatsHappening and
SayGreetingGoodDay.
8. Wire the AgeBasedFilter primitive default terminal to the
SayGreetingGoodDay custom mediation primitive . Similarly
wire LessThan25 and MoreThan25LessThan65 terminals to the
SayGreetingWhatsUp and SayGreetingWhatsHappening custom
mediation primitives respectively.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
120
]
9. Now let’s specify the age based message fi ltering patterns. Select the
AgeBasedFilter primitive and open Properties and select the Details tab
on the left-hand side. Click on the Add button as shown in the
following screenshot:
10. In the Add/Edit properties dialog box enter the pattern /body/
returnGreeting/inputPartyInfo/Age[self::node()<=25].
11. As shown in the following screenshot select Terminal name as LessThan25
and click on the Finish button.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
121
]
12. Repeat the preceding steps to add the /body/returnGreeting/inputPartyInfo/
Age[self::node()>25 and self::node()<=65] matching pattern to the
MoreThan25LessThan65 terminal.
13. We will defi ne a correlation context named greetingMessageCtx to store the
greeting message so that it can be used to hold the greeting message and can
be mapped to the response message – outputGreetingMessage. Correlation
context’s are for passing values from the request fl ow to the response fl ow
inside a mediation fl ow. Think of them as temporary variables that are
accessible in both the request and response fl ows with a mediation fl ow.
14. Then specify within the custom mediation primitives the greeting messages
to return. Go to SayGreetingGoodDay primitive and switch to the Visual
implementation model and add the logic as shown in the following fi gure.
As you can see we use the append text standard utility function to create the
response message and then store it in the greetingMessageCtx correlation
context we defi ned in the previous step.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
122
]
15. Repeat the same steps for the SayGreetingWhatsHappening and
SayGreetingGoodDay custom mediation primitives as shown in the
following screenshot:
16. From the palette of the mediation editor under Service Invocation category,
select and drag the Callout primitive on to the canvas. A callout node is an
end point in the request fl ow. It sends the processed message to the target
operation and in our case this will be sent back as the response. Wire the
output of the SayGoodDayGreeting custom primitive and go to the Callout
node. If you look you will see a response fl ow that will get added when
you add the Callout. Repeat the same for the SayGreetingWhatsUp and
SayGreetingWhatsHappening custom primitives.
17. Go to the response fl ow and add a Message Element Setter primitive
(that will copy the value of the greeting from the correlation context to the
response element) in between the callout response and input response. Your
mediation response fl ow will look as shown in the following screenshot.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
123
]
Congratulations! You have now created your fi rst mediation module. We will now
unit test the mediation fl ow.
Testing modules and components
In the last chapter, we tested the HelloBPEL process using the WID unit test
environment (UTE) that is installed as a part of WebSphere Integration Developer and
consists of a separate installation of the WPS and WESB. We have also talked about
the fact that the WebSphere Process Server is built on WebSphere Application Server
and contains an Enterprise Service Bus. This helps this server to provide the ideal
environment to test HelloMediationModule.
Deploying the modules
You will now deploy your HelloMediationModule on your WebSphere Process
Server UTE environment (or the WESB server if you have it set up). In the Server view,
1. Click on the Servers tab, and start the WPS server by clicking on the green
play button and wait for the server to start. This may take a few minutes.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Building your Hello Mediation Project
[
124
]
2. Right-click on WebSphere Process Server v7.0, select Add and Remove
Projects. Select HelloMediationModuleApp, and then click on
Add | Finish. The HelloMediationModule will now get deployed and
published on the WebSphere Process Server. You will be able to verify this
by seeing it listed under WebSphere Process Server v7.0, as shown in the
following screenshot:
Executing the modules
After deploying the modules, the next step is to execute the modules. Similar to how
we did in the previous chapter, we will use the integration test client to unit test the
HelloMediationModule module and more specifi cally test the interface operations of
the GreetingsFlow mediation fl ow component.
1. Right-click anywhere in the assembly diagram and select Test Module. This
will bring up the Integration Test Client editor. Enter appropriate values
and press the play button that will execute the module and you will be able
to see the greeting message depending on the age you entered.
2. In the following fi gure the request values and the appropriate response
messages are shown when the mediation module is executed.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Chapter 4
[
125
]
Summary
This chapter gave an overview of WESB-based programming fundamentals including
Service Message Objects (SMO) and Mediation Flows. This discussion gave the
fundamentals to build our fi rst mediation fl ow component. Instructions were provided
to create, implement and assemble the HelloMediationFlow. This mediation module
was deployed on the server and unit tested using the WID Unit Test Environment.


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book


Where to buy this book
You can buy Application Development for IBM WebSphere Process Server 7 and
Enterprise Service Bus 7 from the Packt Publishing website:
https://www.packtpub.com/ibm-websphere-process-server-7-
enterprise-service-bus-7-applications-development/book
Free shipping to the US, UK, Europe and selected Asian countries. For more information, please
read our
shipping policy
.
Alternatively, you can buy the book from Amazon, BN.com, Computer Manuals and
most internet book retailers.
P U B L I S H I N G
professi onal experti se di sti l l ed

www.PacktPub.com


For More Information:

www.PacktPub.com/ibm-websphere-process-server-7-enterprise-service-bus-
7
-
applications
-
development
/
book