Saturday, August 11, 2012

In my previous post (Part-1) I explained how to send email from OSB. But in that case we can send email only to one address and it does not have Email subject populated. In this post I will explain how to send email to different users with different contents and subject.
In this post we will create one proxy service which sets the email address, email subject and email content dynamically and in message flow of proxy we will use "Transport Header" activity to set all these values dynamically.  We also need one schema that we will use in proxy service.

1.) Start by creating a simple schema, you can create this schema in Jdeveloper.
  • Use below schema for this sample.
<?xml version="1.0"encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/DynamicEmail" xmlns:tns="http://www.example.org/DynamicEmail" elementFormDefault="qualified">
    <elementname="Email" type="tns:EmailType"></element>
    <complexType name="EmailType">
        <sequence>
            <elementname="Emailto" type="string"></element>
            <elementname="Emailsubject" type="string"></element>
            <elementname="Emailcontent" type="string"></element>
        </sequence>
    </complexType>
</schema>
  • Create schema in OSB project. Navigate to your project, click on Create Resource drop down.Choose XML Schema.
OSB Email Schema

2.)  Now create proxy service. Navigate to your project, click on Create Resource drop down. Choose Proxy Service.
  • Choose Message Service as Service type.
OSB Email Proxy Service
  • In Message Type Configuration choose XML as "Request Message Type" as we are using schema to create proxy service. Then click on Browse button and select the schema that we added above.
OSB Email Proxy Service Message
  • Select request element "Email" of the browse schema.
OSB Email Proxy Service Schema Element
  • Now accept default values and create proxy service.
OSB Email Proxy Service Properties
3.) Now we have business and proxy service ready. We need to pass Email subject, Email content and Email to address dynamically to business service. Navigate to Message flow of proxy service.

  • We link proxy service to business service by using route node.
Proxy service to Business Service Call
  • Right click on EmailBuinessService and choose Edit Route. Add an action in Route node to invoke business service. Select Business Service in Route to option.
Proxy to business route
  •  Add Transport Header activity. By Default it shows only one header but we can add headers as per our requirement. In our case we need only two headers one for Email To and other for Email subject. For Email content we will use Replace activity.Choose email->To from drop down and in action assign value from request message ($body/dyn:Email/dyn:Emailto/text())

Add Transport Header
  • Add header for Email subject. Click Add Header and choose email -> Subject from drop down list and in action assign the value from request message ($body/dyn:Email/dyn:Emailsubject/text( ))

OSB Email Transport Header Properties
  • To pass Email content dynamically we need to use Replace activity. Set XPATH=. ,variable=body and with= ($body/dyn:Email/dyn:Emailcontent/text( )).
Replace Email Content
  • Save all the change, activate the session and you are ready to test your proxy service.

0 comments :

Post a Comment