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

XML Manipulation

In some cases our BPEL processes will invoke web services that return strings. The content of these strings is XML. This approach is used by some developers, particularly on the .NET platform. Using such web services with BPEL is problematic because no function exists to parse string content to XML. In programming languages such as Java and C# we use XML parser functions or XML serialization (JAXB in Java).


(continued)




Oracle therefore provides a custom function called ora:parseEscapedXML(). The function takes a string as a parameter and returns structured XML data:

ora:parseEscapedXML(string)

Let us suppose that the Employee web service returns a string instead of XML. We can parse itusing the ora:parseEscapedXML() function:

<!-- Synchronously invoke the Employee Travel Status Web
     Service -->
<invoke partnerLink="employeeTravelStatus"
        portType="emp:EmployeeTravelStatusPT"
        operation="EmployeeTravelStatus"
        inputVariable="EmployeeTravelStatusRequest"
        outputVariable="EmployeeTravelStatusResponseString" />

<assign>
   <copy>
      <from expression="ora:parseEscapedXML(
         bpws:getVariableData('EmployeeTravelStatusResponseString'))"/>
      <to variable="EmployeeTravelStatusRespose" part="employee"/>
   </copy>
</assign>

To perform an inverse operation—convert structured XML to a string—we can use the ora:getContentAsString() function. It takes structured XML data as a parameter and returnsa string:

ora:getContentAsString(XMLElement)

To set a value of an XML node, Oracle provides the ora:setNodeValue() function with the following syntax:

ora:setNodeValue('variable_name', 'part', 'query', 'new_node_value')

To get a value of an XML node as a string, we can use the ora:getNodeValue() function with the following syntax:

ora:setNodeValue(node)

To get the node value as an integer instead of a string we can use the ora:integer() function:

ora:integer(node)

To add single quotes to a string we can use the ora:addQuotes() function:

ora:addQuotes(string)

Oracle even provides a function to read the content of a file. The function is called ora:readFile() and is often used together with the ora:parseEscapedXML() function, which converts the file content to structured XML (if the file content is XML). The syntax of the ora:readFile() function is:

ora:readFile('file_name')

Next, we look at the expressions related to date and time.

Date and Time Expressions

Sometimes in our BPEL processes we need the current date and/or time, for example, to timestamp certain data. For this, we can use the Oracle-specific functions:

  • ora:getCurrentDate(): Get current date
  • ora:getCurrentTime(): Get current time
  • ora:getCurrentDateTime(): Get current date and time

Note that all three functions return strings (and not the date or date/time types). All three functionsalso take an optional parameter that specifies the date/time format. The format is specified according to java.text.SimpleDateFormat. For details, refer to Java API documentation at http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html>).

To format an XML Schema date or dateTime to a string representation, which is more suitable for output, Oracle provides the ora:formatDate() function. The syntax of the function that returns a string is:

ora:formatDate('dateTime', 'format')

Once again, the format is specified according to java.text.SimpleDateFormat format.

Finally, let's look at functions related to process identification.

Process Identification

Oracle provides several functions related to process identification. With these functions we can get process IDs, URLs, and more. These functions are:

  • ora:getProcessId(): Returns the ID of the current BPEL process
  • ora:getProcessURL(): Returns the root URL of the current BPEL process
  • ora:getInstanceId(): Returns the process instance ID
  • ora:getConversationId(): Returns the conversation ID used in asynchronous conversations
  • ora:getCreator(): Returns the process instance creator
  • ora:generateGUID(): Generates a unique GUID (Globally Unique ID)

E-mail and JMS Messaging Support

Oracle BPEL Process Manager provides two built-in services to integrate BPEL processes with email and messaging. These services expose their operations like any other web service and are actually wrappers for the underlying e-mail or JMS (Java Message Service) services. So, in order to use them with our own processes we create partner links and then invoke the operations on the corresponding port types. The two built-in services with the WSDL locations are:

  • E-mail service: http://localhost:9700/orabpel/xmllib/MailService.wsdl
  • JMS service: http://localhost:9700/orabpel/xmllib/JMSService.wsdl

The Oracle E-mail service offers two port types: MailService and MailServiceCallback. The MailService port type is used to:

  • Send e-mail messages (using the sendMessageoperation)
  • Subscribe (or unsubscribe) to be notified about incoming messages (using subscribe and unsubscribe operations)

The MailServiceCallback port type is a callback interface that should be implemented by our BPEL process. It provides the onMessage operation through which our process is notified about an incoming e-mail message. All operations require parameters (input messages). Their exact structure will be shown in the next example (can also be seen from the E-mail service WSDL). The following figure shows the architecture of the E-mail service:


(Full Size Image)

The JMS service can be used to integrate BPEL processes with applications using JMS. It is similar to the E-mail service and offers two port types: JMSService and JMSServiceCallback. The JMSServiceport type provides sendMessage, subscribe and unsubscribe operations. The JMSServiceCallbackinterface provides the onMessage operation.

E-mail Example

To demonstrate how to use the E-mail service we will add an e-mail confirmation to our travel process example. Originally our process selected the best ticket offer by comparing offers from American and Delta Airlines web services and invoked a callback to the client. We will add an email message confirmation just before the client callback.

Before we start modifying the BPEL code, we need to make modifications to the TravelRequest message in the travel process WSDL. We must add the e-mail address to which our process will send the confirmation. Therefore we first define an EmailType (in the Travel.wsdl file):

<types>
   <xs:schema elementFormDefault="qualified"
              targetNamespace="http://packtpub.com/bpel/travel/">
      <xs:complexType name="EmailType">
         <xs:sequence>
            <xs:element name="Address" type="xs:string" />
         </xs:sequence>
      </xs:complexType>
  </xs:schema>
</types>

Next we add a new email part to the TravelRequestMessage:

<message name="TravelRequestMessage">
   <part name="employee" type="emp:EmployeeType" />
   <part name="flightData" type="aln:FlightRequestType" />
   <part name="email" type="tns:EmailType" />
</message>

Now we are ready to modify the BPEL source code (Travel.bpel file). First we have to add the namespace declaration to our process. The E-mail service uses the http://services.oracle.com/bpel/mail namespace, so we add the following line to the <process> tag:

<process name="BusinessTravelProcess"
         targetNamespace="http://packtpub.com/bpel/travel/"
         xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
         xmlns:trv="http://packtpub.com/bpel/travel/"
         xmlns:emp="http://packtpub.com/service/employee/"
         xmlns:aln="http://packtpub.com/service/airline/"
         xmlns:mail="http://services.oracle.com/bpel/mail" >

Next we add the partner link according to the partner link type definition in the E-mail service WSDL. Let's call the link MailService and the partner role MailServiceProvider. The role of our process is MailServiceRequester:

...
   <partnerLink name="MailService"
                partnerLinkType="mail:MailService"
                partnerRole="MailServiceProvider"
                myRole="MailServiceRequester"/>
...
Note: E-mail service (and JMS service) partner links can be added using BPEL Designer UDDI Browser (select built-in BPEL services).

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