Tutorial 2: New Adapters
by Ronald van Luttikhuizen and Eric Elzinga
Architect: SOA
Published October 2009
In this tutorail you will add self-service capabilities for Foo Inc. Customers of Foo Inc. can use this new service to email their personal information,which will be automatically be added to the back office systems, enabling customer to make online purchases.
More specifically we will create an OSB project that retrieves mail messages from a mail server and transform their content into the English canonical data model. The customer details will be used as input for the "AddCustomer" operation of the OSB Customer Service that was created in the previous tutorial. This service will then store the new customer information. This tutorial introduces MFL (Message Format Language) capabilities and Service Accounts.
Getting to know adapter support in Oracle Service Bus such as the email adapter. This is particularly interesting since Oracle ESB does not offer an email adapter.
Let's begin by creating a new project.
Figure 1: Folder structure of the new OSB project
OSB uses a Service Account to access the mailbox on the mail server through polling. Service Account resources provide a user name and password that Proxy and Business Services use for outbound authentication to a local or remote resource, such as an FTP server or a JMS server.
Figure 2: Configuration of the Service Account
To use the mail content in the remainder of the pipeline we need to transform its plain-text data into XML. Oracle Service Bus uses MFL (Message Format Language) to convert non-XML into XML or XML into non-XML.
Figure 3: Creating a Message Format File
Enter "MailToCustomer.mfl" as "File Name" and click "Finish". This will open the "Format Builder Tool" dialog. We will use this tool to transform the mail content into XML format. Select File → Properties from the menu and change the "Message Format Version" to "2.0.2". Click "OK".
Right-click the "MailToCustomer" item and select "Insert Field". Add the following elements:
Figure 4: Configuration of the MFL after adding all elements
Save all changes. Let's test the newly created transformation to see if the MFL transforms our mail message to a corresponding XML document.
Figure 5: The generated XML as result of the transformation
The MFL works and the target XML is shown in the dialog! We continue by routing the XML document to the Customer Proxy Service from the previous tutorial.
We will use the information from the mail message to invoke the "AddCustomer" operation of the Customer Proxy Service we created in the first tutorial. Although the MFL has generated XML, we still need to transform its contents into a valid request payload for the Customer Proxy Service. We will create an XQuery transformation to achieve this.
Figure 6: Creating the XQuery using the MFL XML response as Source Type
Select "XML" as "Target Type" and select the "AddCustomerRequest" element from the "WAAI_Case1_Customer_Service" project.
Figure 7: Creating the XQuery using the AddCustomerRequest variable as target
Finish the transformation by mapping the source element to the target elements. See the first tutorial in case you don't know how to apply type conversion.
Figure 8: XQuery mapping between the mail content and AddCustomer request payload
The following step involves defining a Proxy Service that will make use of the Service Account we created earlier to poll for new mail messages.
Figure 9: Configuration of the Proxy Service
Select "MFL" as "Request Message Type" in the "Messaging" tab and browse to the MFL file. Select "None" as "Response Message Type" as the Proxy Service won't be routing back any response; this is a fire-and-forget service. Save the Proxy Service.
Figure 10: Configuring the Proxy Service Message Type
Next we select the transport to use for this Proxy Service; in this case we will use the email transport.
Select "email" as "Protocol" in the "Transport" tab of the Proxy Service. Enter "mailfrom:server:port" as "Endpoint URI" and replace "server" and "port" with the settings of your mail server.
Figure 11: Configuring the email transport
Select the "Email Transport" tab to complete the configuration of the Proxy Service. Use the following setting:
Figure 12: Configuring the email transport
Next we need to complete the Message Flow by connecting the Proxy Service to the "AddCustomer" operation of the Customer Proxy Service and adding the required transformation activities.
Figure 13: Routing the Message Flow to the AddCustomer operation of the Customer Proxy Service
Let's add the transformation logic in order to create a valid request payload for the Customer Proxy Service.
Figure 14: Assigning the outcome of the XQuery transformation to the "mailToCustomer" variable
We have now applied the XQuery transformation to the XML output of the mail message. The result of the transformation is assigned to the "mailToCustomer" variable.
The final step in the Message Flow involves defining a valid request payload for the Customer Proxy Service using the "mailToCustomer" variable.
Figure 15: Replacing the request body with the contents of the "mailToCustomer" variable
The Message Flow is now completed and looks like the following:
Figure 16: Message Flow after adding all routing and transformation logic
This completes the OSB project! We are now ready to test it.
Deploy the OSB project to WebLogic Server as previously outlined and open Oracle Service Bus Console to inspect it.
The projects you imported in Oracle Workshop during the installation and configuration guide include a project called "MailClient" that can be used to test the OSB service. The test project contains a simple Java class that creates and sends a mail message to the mail server. This mail server is polled by the OSB project and the message is picked up and initiates an instance of the OSB project.
Open the MailClient.java class in the MailClient project and change the settings according to your mail server. Run the client by right-clicking the Java class and selecting Run As → Java Application .
Figure 17: Test result of the MailClient.java — the mail message is sent
The messages is routed to the "AddCustomer" operation of the Customer Proxy Service, which will route the message to the "AddKlant" operation of the KlantWebService project as outlined in the first tutorial. The Web Service implementation logs the Dutch input to the Console.
After sending the mail message the Console in Oracle Workshop logs the following:
Figure 18: Test result of invoking the "AddCustomer" operation
Also inspect the mail folders you have defined during the creation of the Proxy Service. These should contain the mail message that is processed by OSB.
We have now successfully tested the OSB project!
You have added self-service capabilities for Foo Inc. in this tutorial. Using this new service, Foo Inc. customers can email their personal information, which will automatically be added to the back office systems, enabling customers to make online purchases.
You have used OSB's support for mail transport, Service Accounts, and MFL to poll for new mail messages and convert its non-XML payload into XML format.