www.codeguru.com/cpp/sample_chapter/article.php/c10789/

Back to Article

Home >> Visual C++ / C++ >> Sample Chapter


Oracle BPEL Process Manager
Rating:

Packt Publishing (view profile)
October 19, 2005

Go to page: Prev  1  2  3  4  5  6  7  8  9  10  11  12  13  Next

Sending E-mails

Next we add the e-mail confirmation code. We will send an e-mail confirmation after we have


(continued)




checked that the ticket has been approved and before invoking the callback to the client. We put all code related to the e-mail confirmation in a new scope called EmailConfirmation, where we also declare the required variables. We call the variable that holds the e-mail message sent by our process mailMsg. The e-mail reply message is stored in the variable mailResponse. Both variables are of type mailEnvelope. To subscribe the process to the incoming messages we need thesubscriptionRequest variable:

<scope name="EmailConfirmation">

   <variables>
      <variable name="mailMsg"
                messageType="mail:mailEnvelope"/>
      <variable name="subscriptionRequest"
                messageType="mail:subscriptionMessage"/>
      <variable name="mailResponse"
                messageType="mail:mailEnvelope"/>
   </variables>
...

Next we create the content of the send e-mail message and copy it to the mailMsg variable. We use the following assign:

...
   <sequence>
      <assign>
         <!-- Create the mail message -->
         <copy>
            <from>
               <mailMessage
                xmlns="http://services.oracle.com/bpel/mail">
                  <from>
                     <email>your.email@address.com</email>
                  </from>
                  <replyTo>
                     <email>your.email@address.com</email>
                  </replyTo>
                  <to>
                     <address>
                        <email/>
                     </address>
                  </to>
                  <subject/>
                  <mailAccount>TravelEmailAccount</mailAccount>
                  <contentType>text/plain</contentType>
                  <content/>
               </mailMessage>
            </from>
            <to variable="mailMsg" part="payload"/>
         </copy>
...

Next we copy the 'to' e-mail address from the TravelRequestmessage (client input) to the 'to' address:

...
   <!-- Add the email to address -->
   <copy>
      <from variable="TravelRequest" part="email"
            query="/email/Address"/>
      <to variable="mailMsg" part="payload"
          query="/mailMessage/to/address/email"/>
   </copy>
...

We also create the message subject and copy the travel response confirmation XML data into the message body:

...
      <!-- Add the message subject -->
      <copy>
         <from expression="concat('Travel confirmation for ',
                           bpws:getVariableData('TravelRequest',
                              'employee','/employee/LastName'))"/>
         <to variable="mailMsg" part="payload"
             query="/mailMessage/subject"/>
      </copy>

      <!-- Add the message content -->
      <copy>
         <from variable="TravelResponse" part="confirmationData" />
         <to variable="mailMsg" part="payload"
             query="/mailMessage/content"/>
      </copy>
   </assign>
...

Now we are ready to send the e-mail message. To do this, we have to invoke the sendMessage operation on the MailService partner link. Note that Oracle E-mail service is actually a wrapper that provides access to e-mail via web services. So, we can use the service in the same way as any other partner web service:

...
   <!-- Send the email by invoking the service -->
   <invoke partnerLink="MailService"
           portType="mail:MailService"
           operation="sendMessage"
           inputVariable="mailMsg"/>
...

Receiving E-mail Confirmations

Suppose we want the user to confirm the travel arrangement by replying to the e-mail message before completing the process. To implement this we will subscribe our BPEL process to the email account and then wait for the onMessage callback. The E-mail service will invoke the onMessage callback once the reply e-mail has been received.

To subscribe to the e-mail service we first have to create the subscription request. We will also add a filter to limit the subscription to the e-mail message with the specified subject and from address:

...
   <!-- Crate the subscription request -->
   <assign>

      <copy>
         <from>
            <subscription xmlns="http://services.oracle.com/bpel/mail">
               <mailAccount>TravelEmailAccount</mailAccount>
               <filter/>
            </subscription>
         </from>
         <to variable="subscriptionRequest" part="payload"/>
      </copy>

      <!-- Add a filter by subject and from address -->
      <copy>
         <from expression="concat('subject=&quot;',
            bpws:getVariableData('mailMsg','payload','/mailMessage/subject'),
               '&quot; and from=&quot;',
            bpws:getVariableData('TravelRequest','email','/email/Address'),
               '&quot;')"/>
         <to variable="subscriptionRequest" part="payload"
             query="/subscription/filter"/>
      </copy>
   </assign>
...

Then we will register our process for the incoming e-mail message by invoking the subscribe operation on the MailService:

...
   <!-- Register subscription by invoking the service -->
   <invoke partnerLink="MailService"
           portType="mail:MailService"
           operation="subscribe"
           inputVariable="subscriptionRequest"/>
...

Finally our process will wait for the callback. Therefore we add a <receive> activity for the onMessage operation:

...
      <!-- Wait for the confirmation email -->
      <receive partnerLink="MailService"
               portType="mail:MailServiceCallback"
               operation="onMessage"
               variable="mailResponse"/>
   </sequence>
</scope>

Configuring an E-mail Account

To make the e-mail example work, we also have to set up an e-mail account we will use. When sending and subscribing to the e-mail we have declared that we will use the TravelEmailAccount:

<mailAccount>TravelEmailAccount</mailAccount>

We create the TravelEmailAccount.xml file with the following content:

<mailAccount xmlns="http://services.oracle.com/bpel/mail/account">
   <userInfo>
      <displayName>[display name]</displayName>
      <organization>[organization name]</organization>
      <replyTo>[replyTo email address]</replyTo>
   </userInfo>

   <outgoingServer>
      <protocol>smtp</protocol>
      <host>[outgoing smtp server]</host>
      <authenticationRequired>false</authenticationRequired>
   </outgoingServer>

   <incomingServer>
      <protocol>pop3</protocol>
      <host>[incoming pop3 server]</host>
      <email>[email address]</email>
      <password>[email password]</password>
   </incomingServer>

   </mailAccount>

Remember to provide details of a valid e-mail account. We then copy this file to the BPEL Server domain. Since we are using the default domain, we copy the file to the following directory: c:\orabpel\domains\default\metadata\MailService.

We are now ready to compile, deploy, and test the example. The source code can be downloaded from http://www.packtpub.com/.

Go to page: Prev  1  2  3  4  5  6  7  8  9  10  11  12  13  Next

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed






internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers