5 Replies Latest reply: Sep 4, 2013 11:38 AM by 847931e4-79eb-49cf-ac43-b21d5130614e RSS

    Generating random numbers in BPEL

    847931e4-79eb-49cf-ac43-b21d5130614e

      I have a use case that requires I generate a random 2 digit number, something similar to "math:random * 100". I noticed that this functionality is not readily accessable in the SOA Composite editor. Can anyone suggest how this can be done?

        • 1. Re: Generating random numbers in BPEL
          JF4MW

          Hi, I have accomplished this using the Embedded Java function with BPEL.

           

          Here's a sample of code you can use and stick your Embedded Java function:

                  Random random = new Random();

                  int abc = random.nextInt(100);

                  System.out.print(abc);

          Remember to import import java.util.Random;

           

          Not sure if you've used this function before

          • 2. Re: Generating random numbers in BPEL
            847931e4-79eb-49cf-ac43-b21d5130614e

            That sounds like the right answer. I'm a bit new to the Embedded Java capability of the SOA composite editor. Would it be possible for you to copy-paste the entire contents of the contents of the Code_Snippet section of the Edit Java Embedding dialogue?

            • 3. Re: Generating random numbers in BPEL
              Eric Elzinga

              [code]

              <?xml version = "1.0" encoding = "UTF-8" ?>

              <!--

              ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                Oracle JDeveloper BPEL Designer

               

                Created: Mon Sep 02 07:58:14 CEST 2013

                Author:  Eric

                Type: BPEL 1.1 Process

                Purpose: Asynchronous BPEL Process

              ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

              -->

              <process name="BPELProcess1"

                       targetNamespace="http://xmlns.oracle.com/KIMServices/embedded_java/BPELProcess1"

                       xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"

                       xmlns:client="http://xmlns.oracle.com/KIMServices/embedded_java/BPELProcess1"

                       xmlns:ora="http://schemas.oracle.com/xpath/extension"

                       xmlns:bpelx="http://schemas.oracle.com/bpel/extension"

                       xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"

                       xmlns:bpel2="http://docs.oasis-open.org/wsbpel/2.0/process/executable"

                       xmlns:xsd="http://www.w3.org/2001/XMLSchema"

                       xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"

                       xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"

                       xmlns:kimbpel="http://xml.ibridge.nl/nl/rsg/kim/bpel"

                       xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"

                       xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"

                       xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"

                       xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"

                       xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"

                       xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"

                       xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap">

               

               

                  <!--

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                      PARTNERLINKS                                                     

                      List of services participating in this BPEL process              

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                  -->

                  <partnerLinks>

                      <!--

                    The 'client' role represents the requester of this service. It is

                    used for callback. The location and correlation information associated

                    with the client role are automatically set using WS-Addressing.

                  -->

                      <partnerLink name="bpelprocess1_client" partnerLinkType="client:BPELProcess1" myRole="BPELProcess1Provider" partnerRole="BPELProcess1Requester"/>

                  </partnerLinks>

               

               

                  <!--

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                      VARIABLES                                                       

                      List of messages and XML documents used within this BPEL process

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                  -->

                  <variables>

                      <!-- Reference to the message passed as input during initiation -->

                      <variable name="inputVariable" messageType="client:BPELProcess1RequestMessage"/>

               

               

                      <!-- Reference to the message that will be sent back to the requester during callback -->

                      <variable name="outputVariable" messageType="client:BPELProcess1ResponseMessage"/>

                       <variable name="randomNumber" type="xsd:int"/>

                  </variables>

               

               

                  <!--

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                     ORCHESTRATION LOGIC                                              

                     Set of activities coordinating the flow of messages across the   

                     services integrated within this business process                 

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                  -->

                  <sequence name="main">

                      <!-- Receive input from requestor. (Note: This maps to operation defined in BPELProcess1.wsdl) -->

                      <receive name="receiveInput" partnerLink="bpelprocess1_client" portType="client:BPELProcess1" operation="process" variable="inputVariable" createInstance="yes"/>

                      <scope name="init" variableAccessSerializable="no">

                                  <sequence>

                                      <bpelx:exec import="java.util.Random"/>

                                      <bpelx:exec name="randomNumber" version="1.5"

                                                  language="java">

                                          <![CDATA[// Generate random number from java

               

               

              try {

               

               

                      Random random = new Random();

                      int abc = random.nextInt(100);

                      setVariableData("randomNumber", abc);       

                     

              }

              // end Generate random number from java

              catch(Exception e){}]]>

                                      </bpelx:exec>                       

                                  </sequence>

                              </scope>

                      <assign name="Assign2">

                          <copy>

                              <from variable="randomNumber"/>

                              <to variable="outputVariable" part="payload"

                                  query="/client:processResponse/client:result"/>

                          </copy>

                      </assign>

                      <!--

                        Asynchronous callback to the requester. (Note: the callback location and correlation id is transparently handled using WS-addressing.)

                      -->

                      <invoke name="callbackClient" partnerLink="bpelprocess1_client" portType="client:BPELProcess1Callback" operation="processResponse" inputVariable="outputVariable"/>

                  </sequence>

              </process>

              [/code]

               

              this should do it

              • 4. Re: Generating random numbers in BPEL
                JF4MW

                Sorry, for my late reply! the above is perfect... One thing to note is the imports and is very IMPORTANT not to forget it.

                Use BPEL 1.o specification because I had some issues with BPEL2

                 

                Remember to import <bpelx:exec import="java.util.Random"/>

                 

                If you leave out the above your code will not compile and isn't very specific on where to find the issue

                • 5. Re: Generating random numbers in BPEL
                  847931e4-79eb-49cf-ac43-b21d5130614e

                  That's exactly what I found after doing some research. The import was a sticking point, and thank you for pointing out how to do that.