The notification service in Oracle BPEL Process Manager allows you to send a notification by email (as well as voice message, fax, pager, or SMS) from a BPEL process.
However another requirement is to be able to use the receipt of an email to initiate a BPEL process. This is thesubject of this blog, many thanks to Muruga Chinnananchi on whose original example this is based.Essentially we want to create a simple process EMailActivation which recieves an email sent to a particularemail address. To achive this there are two basic steps:
Configure the BPEL Server to be able to connect to the mail account.
Define the BPEL Process to be initiated on receipt of an email.
Configure Email Account:
To configure the email account which the BPEL Server should connect to, we need to place a MailAccount xml configuration file (in our example BpelMailAccount.xml) into the following directory:
SOA_DOMAIN\bpel\domains\default\metadata\MailService
Note: You will need to create the metadata and MailService directories.
The file itself can have any name (though must end with .xml) as you can define multiple accounts. However make a note of the name as you will need it to link your BPEL Process to the actual mail account.
Here’s one sample file:
<mailaccount xmlns="http://services.oracle.com/bpel/mail/account">
<userInfo>
<displayName> any a/c display name </displayName>
<organization> My Org </organization>
<replyTo> replyToAddress@localhost </replyTo>
</userInfo>
<outgoingServer>
<protocol> smtp </protocol>
<host > localhost </host >
<authenticationRequired > false </authenticationRequired >
<outgoingserver>
<incomingServer>
<protocol> pop3 </protocol>
<host > localhost </host >
<email> bpel </email>
<password> CRYPT{xdfg+Gs=}</password>
</incomingServer>
</mailAccount>
</mailAccount>
The outgoing SMTP service doesn’t need to be configured (as we use the notification service to send outgoing emails). However the incoming account is defined by the following tags:
<incomingServer>
<protocol>[protocol pop3 or imap]</protocol>
<host>[imap or pop3 server]</host>
<email>[imap or pop3 account]</email>
<password>[imap or pop3 password]</password>
<folderName>[imap only, inbox folder ]</folderName>
</incomingServer>
Note: When defining the account name, be careful to use the actual account name not the email address as they are not always the same.
Creating BPEL Process:-
The first step is to use JDeveloper to create an Asynchronous process initiated by a request message with a payload containing an element of type mailMessage (defined in Mail.xsd installed as part of BPEL PM).
To do this use the BPEL Project Creation wizard to create a BPEL Process in the normal way. After entering the process name and specifying the process template to be asynchronous, select "Next".
This will take you to the next step in the wizard where you specify the Input and Output Schema Elements, click on the flash light for the input schema and select Mail.xsd (located in <SOA_HOME>\bpel\system\xmllib)
Specifying input/output schema elements leads to opening the type chooser window to select the element to use from the imported schema. Select the mailMessage element
Once the process has been created you can remove the callBackClient activity as we won’t need this.
Import Common Schema:
If you now try and compile your process, you will find it fails with an error message. Thus is because the Mail.xsd itself imports a schema (common.xsd), so you need to import this schema as well.
To import the Mail Schema into your BPEL Process, ensure the diagram view for your BPEL process is open and selected in JDeveloper. Then within the BPEL Structure window, right click on the Project Schemas node and select "Import Schemas"
Note: Once imported, manually update the WSDL file to ensure the import statements for both the Mail.xsd and common.xsd are contained within the same element or it will still fail to compile. See previous blog - Using Nested Schemas with BPEL for details.
Define Mail Activation Agent
The process itself is now ready for deployment. However we need to complete one final activity, which is to tie the BPEL Process to a mail activation agent for the Email account that we defined earlier.
The Activation Agent will poll the defined mail box for emails and then for each email it receives invoke an instance of the process to handle it.
To do this you need to add the following definition to the bpel.xml file, after the <partnerlinkbindings>element:
<activationAgents>
<activationAgent className=”com.collaxa.cube.activation.mail.MailActivationAgent”
heartBeatInterval=”60”>
<property name=”accountName">BpelMailAccount</property>
</activationAgent>
</activationAgents>
Where heartBeatInterval is how often we want to poll the email account for new emails, and the accountName corresponds to the name of the account configuration file we defined earlier.
Finally deploy the process and send an email to the appropriate account.
Note: If you modify the BPEL process in JDeveloper, the bpel.xml file may lose its changes (i.e. the activationAgent definition), and as a result the process will never get initiated - so always check the bpel.xml file is correctly defined just before deploying the process.
Email Server:
Install and configure Email server according to product instructions
:-) Lift and Shift of the Matt's blog :
ReplyDeletehttp://blogs.bpel-people.com/2007/01/using-email-to-initiate-bpel-process.html
Well ! Even then it helped. Thanks.
Is this 10g or 11g , have you tried it on 11g.
ReplyDeleteNot working on 11g that is for sure ... N
ReplyDelete