| Architect: SOA
Jumpstart for Oracle Service Bus Development
by Ronald van Luttikhuizen and Eric Elzinga
Tutorial 2: New Adapters
Published October 2009
In this article:
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.
Oracle Service Bus 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.
Message Format Language (MFL)
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.
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.
Routing and Transformation
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.
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.
Next we select the transport to use for this Proxy Service; in this case we will use 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.
Let's add the transformation logic in order to create a valid request payload for the Customer Proxy Service.
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.
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.
Deployment and Testing
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.