Using the utility functionality

Oracle SOA Suite defines a set of utility functions to perform various operations. However, there is no unified place where we find the utility functions. In this recipe, we will learn how to format a message with the ora:format utility function and then implement the same functionality inside the Java Embedding activity.

Getting ready

To start, we will use the BPEL_and_Java_1_1 process. We change the schema definition of the response message. Open the BPEL_and_Java_1_1.xsd file and change the response part of the element:

<element name="processResponse">
  <complexType>
    <sequence>
      <element name="resultFmtBPEL" type="string"/>
     <element name="resultFmtJava" type="string"/>
    </sequence>
  </complexType>
</element>

Open the BPEL_and_Java_1_1 process and place a new assign activity (FormatBPEL) into it. The code for the assign activity is as follows:

<assign name="FormatBPEL">
 <copy>
  <from expression="ora:format('At {0} on {1} the BPEL was initiated with the following input parameter: {2}.',xp20:current-time(),xp20:current-date(),bpws:getVariableData('inputVariable','payload','/client:process/client:input') )"/>
  <to variable="outputVariable" part="payload"
    query="/client:processResponse/client:resultFmtBPEL"/>
 </copy>
</assign>

With the code, we formatted a message that contains the date and input message information. We assign the result to the output part of the variable (resultFmtBPEL).

How to do it…

We will now format the same message with the help of the Java Embedding activity. Start by adding the Java Embedding activity (FormatJava) into the BPEL_and_Java_1_1 process. The code snippet for the FormatJava activity is as follows:

  1. We start by reading the content of the input variable:
    String input_txt= ((oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/client:process/client:input")).getTextContent();       
  2. Instantiate the MessageFormat class for the formatting:
    java.text.MessageFormat mfmt= new java.text.MessageFormat("At {0, time} on {0,date} the BPEL was intatiated with the following input parameter: {1}.");
  3. Fill the variable of the object to be formatted:
    Object[] objs = {new java.util.Date(), input_txt};  
  4. Perform the actual formatting and send the results of the formatting to the output variable part (resultFmtJava):
    String result= mfmt.format(objs);
    setVariableData("outputVariable", "payload", "/client:processResponse/client:resultFmtJava", result);

How it works…

Both the methods described in this recipe use the same principle of formatting the messages. Actually, the BPEL method ora:format uses the same Java class that we used in this recipe (java.text.MessageFormat).

Oracle defines a set of utility functions to be utilized, summarized by the section in which we can find them in JDeveloper Expression Builder.

Advanced functions

Function name

What function does

ora:format

Formats the message based on the Java message formatting expression.

ora:genEmptyElem

Generates the specified number of empty elements specified by QName parameter.

ora:getChildElement

Returns the child element (index) of the given element.

Mathematical functions

Function name

What the function does

oraext:max-value-among-nodeset

Returns the maximum integer value from the list of given nodes. The nodes must be presented as text nodes.

oraext:min-value-among-nodeset

Returns the minimum integer value from the list of given nodes. The nodes must be presented as text nodes.

oraext:square-root

Returns the square root of the input number

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset