Oracle Technologies Primer

June 24, 2011

Triggering an OSB Message Flow with Email

Often in our business processes/integrations we might have a situation where in we would need to trigger our message flow/process with an Email.

With OSB’s Email transport listening to a mailbox and triggering a message flow is very simple and comes out of the box.

The following article will explain as a tutorial how can this be achieved.

Prerequisites

The prerequisites for this tutorial are as under :

  1. Oracle Service Bus 11g (Link)
  2. Apache James Server (Link) that can act as a Mail server.

Getting Started

Setting Up Apache James

The first thing to get started would be to download the Apache James binary from here. Apache James would act as the email server through which we can send/receive emails.

Copy the James binary at any location on your computer. The binaries would come with a bin folder. Navigate to the bin folder to locate the run.bat file.

Apache James need JDK 1.5 and above so make sure JAVA_HOME is added with the JDK directory in the list of environment variables before running James.

Open a command prompt and run the run.bat file.

We can now see that Apache James server is up and running. Pretty simple.

image

Next we can verify by doing a telnet to the James Management port i.e. 4555. Login to James using the default Login Id and Password.

Login Id: root
Password: root

We can add user inboxes by the following command

adduser <username> <password>

After you add users the next thing you can do to verify this is use the command listusers that  will give you all users in the server.

image

Having done this we are good with the email server part. By default James runs both the SMTP server to send mail and a POP3 server that can be used to retrieve mails.

Creating the OSB Message Flow

The next thing would be to create a Message flow in OSB that can be triggered with the Email event.

Make sure that Oracle Service Bus domain is created and a server is up and running.

Open http:host:port/sbconsole and login with the username and password configured for the OSB domain.

The first step would be to create a SMTP server configuration. This is required as we would create a dummy Business Service to post a message to the configured inbox.

Once you have logged in to the OSB console go to System Administration –> SMTP Servers –> Add and create a SMTP server as under

image

Click on Save to save the configuration.

Now go to project explorer and create a project and name it EmailSub. Create an XML Schema resource from the Create Resource Icon based on the following XSD.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified" targetNamespace="http://www.beatechnologies.com/xsd/salesapp"
xmlns:sales="http://www.beatechnologies.com/xsd/salesapp">
<xsd:complexType name="ContentType">
<xsd:sequence>
<xsd:element name="MimeType" type="xsd:string" default="text/plain" minOccurs="0"/>
<xsd:element name="ContentBody" type="sales:OrderIndicatorType"/>
<xsd:element name="ContentEncoding" type="xsd:string" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="EmailPayloadType">
<xsd:sequence>
<xsd:element name="FromAccountName" type="xsd:string" minOccurs="0"/>
<xsd:element name="To" type="xsd:string" minOccurs="0"/>
<xsd:element name="ReplyToAddress" type="xsd:string" minOccurs="0"/>
<xsd:element name="Subject" type="xsd:string"/>
<xsd:element name="Content" type="sales:ContentType"/>
<xsd:element name="Cc" type="xsd:string" minOccurs="0"/>
<xsd:element name="Bcc" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="OrderIndicatorType">
<xsd:sequence>
<xsd:element name="OrderID" type="xsd:string" minOccurs="0"/>
<xsd:element name="OrderAmount" type="xsd:string" minOccurs="0"/>
<xsd:element name="CustomerID" type="xsd:string" minOccurs="0"/>
<xsd:element name="QuoteID" type="xsd:string"/>
<xsd:element name="BusinessUnitID" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="EmailPayload" type="sales:EmailPayloadType"/>
</xsd:schema>

Create a Business Service based on Messaging Service Type called SendEmailBS

image

Configure rest of the service as under

image

Save the service and activate the session. Test the business service that we just created. Also configure an email client to see whether you get this email.

Here is a test payload

<sal:EmailPayload xmlns:sal="http://www.beatechnologies.com/xsd/salesapp">
<sal:Content>
<sal:ContentBody>
<sal:OrderID>2003138758424</sal:OrderID>
<sal:OrderAmount>452617</sal:OrderAmount>
<sal:CustomerID>2000001120268</sal:CustomerID>
<sal:QuoteID>2002795866809</sal:QuoteID>
<sal:BusinessUnitID>4747</sal:BusinessUnitID>
</sal:ContentBody>
</sal:Content>
</sal:EmailPayload>
<pre>

Off course this is a very basic way of testing. You can also go on and create a front ending proxy service to pass the content payload, subject and other email headers dynamically.

image

For the second part we need to configure a Proxy Service that can poll this mail box and instantiate its message flow whenever an email arrives.

The first step for this would be to configure a Service Account of Type ‘Static’ that will basically have the user name and password for the mail box.

image

We would need to attach this Service Account while configuring the Proxy Service required to poll this mail box.

Next create a Messaging type Proxy Service based on the same Email.xsd as under

image

image

Lastly go and edit the Proxy Service Message Flow. Add a Pipeline Pair and in the Request Pipeline add a Stage.

Add some simple action to extract the payload from the body variable and log the body to validate whether we receive an email.

image

Well we are now almost done.

Use the dummy Business Service that we created and push one more message to the user Inbox. This time you will notice that the Proxy Service picks up the message and logs it to the server log.

Open the domain AdminServer.log file to see the message getting logged.

image

That is pretty much it. Now you can create your own message flow that can be executed with the trigger of an Email.

1 Comment »

  1. I am wokring on OSB project where in message flow I need to read the mail and iterate over the attachments.

    I am using following expression

    we have Upgraded OSB from 9 to 10g R3

    for Each variable [x] in ./ctx:attachment/ctx:body/ctx:binary-content/@ref of variables fileAttachments

    Buts its not coming in side the loop

    I printed my attachment variable.

    text/plain; name=”20121118130513.txt”
    20121118130513.txt
    attachment; filename=”loadshed20121118130513.txt”;
    size=1379; creation-date=”Sat, 18 Aug 2012 02:42:11 GMT”;
    modification-date=”Sat, 18 Aug 2012 03:30:15 GMT”
    base64
    FNAM 20121118130513.txt
    EOF

    >
    Please help me and suggest

    Comment by Abhishek — August 19, 2012 @ 5:07 am


RSS feed for comments on this post. TrackBack URI

Post your comments and suggestions here

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Silver is the New Black Theme. Blog at WordPress.com.

Adam Deane

Business Process and Workflow

Oracle Technologies Primer

Technical posts on OSB/WLS/AIA, Oracle SOA Suite, BPM and Fusion Middleware

SOA Community Blog

by Jürgen Kress

Technical posts on OSB/WLS/AIA, Oracle SOA Suite, BPM and Fusion Middleware

Technical posts on OSB/WLS/AIA, Oracle SOA Suite, BPM and Fusion Middleware

J@n van Zoggel

mumblings of a middleware minion

Oracle .. Java .. OpenSource .. SOA

Just another WordPress.com weblog

Nitin's Oracle Fusion Middleware and SOA World

SOA FMW BPM BPEL OSB Governance J2EE and all the Geeky stuff

RedStack

Musings on Integration with Oracle Fusion Middleware

Follow

Get every new post delivered to your Inbox.

Join 920 other followers

%d bloggers like this: