Skip to main content

Write Java Code inside XSL of Oracle BPM

This post talks about writing custom xsl functions using Java in Oracle BPM process. Please check my previous post on creating custom XSL functions in Oracle SOA/BPEL process.

Below example explains about creating XSL function for finding age of person based on Date Of Birth input.

Step1 : Create a BPM Synchronous process inside Jdeveloper BPM studio.Something like shown in below. I took very basic example,since the main aim is to create Custom XSL function based on Java code.



   i) XSD created to handle input and output of BPM process is :

 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://ande.prabhas.org/xsd/v1"
            targetNamespace="http://ande.prabhas.org/xsd/v1"
            elementFormDefault="qualified">
  <xsd:element name="Request" type="tns:RequestType"/>
  <xsd:element name="Response" type="tns:ResponseType"/>
  <xsd:element name="CustomFault" type="tns:FaultType"/>
  
  <xsd:complexType name="RequestType">
    <xsd:sequence>
     <xsd:element name="input" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
  
  <xsd:complexType name="ResponseType">
    <xsd:sequence>
     <xsd:element name="output" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
  
  <xsd:complexType name="FaultType">
    <xsd:sequence>
     <xsd:element name="error" type="xsd:string"/>
     <xsd:element name="errorCode" type="xsd:string"/>
     <xsd:element name="errorDescription" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
    
</xsd:schema>

   ii) Java Utils class created to handle dob calculation for XSL custom function is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ande.prabhas.org;


import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Utils {
    public Utils() {
        super();
        
        System.out.println("--- Utils Class Loaded ---");
    }
    
    
    public static int calcAge(String dob) {
        
        Date date = convStringToDate(dob);
        Calendar today = Calendar.getInstance();
        Calendar birthDate = Calendar.getInstance();
        
        int age=0;
        
        birthDate.setTime(date);
        
        if(birthDate.after(today))
            throw new IllegalArgumentException("DOB cant be in future");
        long diffInMillis = today.getTimeInMillis()-birthDate.getTimeInMillis();
        long diffInYears = (diffInMillis/(24*60*60*1000))/365;
        
        age =(int)diffInYears;
        return age;
    }
    
    private static Date convStringToDate(String inDate) {
        
        System.out.println("BDate::"+inDate);
        SimpleDateFormat sd = new SimpleDateFormat("MM/dd/yyyy");
        Date date = null;
        
        try{
            date = sd.parse(inDate);
            System.out.println(date);
        }catch(ParseException e) {
            e.printStackTrace();
        }
        
        return date;
    }    
   
}

Step2: Create respective Process Data Objects and perform data association in BPM process end to end . Refer below screen shots.





Step3: Create XSL function inside script task by dragging XSL transformation icon on DataAssociation properties dialog box onto "ResponsePDO" data object as shown in below image.
Which in turn will ask you to provide source and target message/element types to perform transformation.



 i) XSL Transformation created with custom code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
  <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
  <mapSources>
    <source type="XSD">
      <schema location="../xsd/ProcessIO.xsd"/>
      <rootElement name="Request" namespace="http://ande.prabhas.org/xsd/v1"/>
      <param name="RequestPDO" />
    </source>
  </mapSources>
  <mapTargets>
    <target type="XSD">
      <schema location="../xsd/ProcessIO.xsd"/>
      <rootElement name="Response" namespace="http://ande.prabhas.org/xsd/v1"/>
    </target>
  </mapTargets>
  <!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.7.8(build 150622.2350.0222) AT [SAT FEB 24 12:36:35 EST 2018]. -->
?>
<xsl:stylesheet version="1.0"
                xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
                xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:med="http://schemas.oracle.com/mediator/xpath"
                xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
                xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
                xmlns:tns="http://ande.prabhas.org/xsd/v1"
                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:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:bpmn="http://schemas.oracle.com/bpm/xpath"
                xmlns:ora="http://schemas.oracle.com/xpath/extension"
                xmlns:jutil="http://www.oracle.com/XSL/Transform/java/ande.prabhas.org.Utils"
                xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
                exclude-result-prefixes="xsi xsl tns xsd bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref bpmn ora socket ldap">
  <xsl:template match="/">
    <tns:Response>
      <tns:output>        
        <xsl:value-of select="jutil:calcAge(/tns:Request/tns:input)"/>
      </tns:output>
    </tns:Response>
  </xsl:template>
</xsl:stylesheet>


Step4: Deploy the bpm process and test dob functionality.

i) Send DOB input to deployed process in EM console.



ii) Verify the output and check the server console if the custom java function being triggered.




Comments

Popular posts from this blog

How to control CUDA Devices to be used in Windows 10 for Keras/Theano/TensorFlow training

I've two 1080ti GPUs , I would like to use only one of the device for DeepLearning Training purpose,Most of the google suggestions advising to use CUDA_VISIBLE_DEVICES environment variable.Setting CUDA_VISIBLE_DEVICES either in windows environment variables are as programmatic way dint help much. But below approach helped to control the GPU usage for CUDA operations. Open NVIDIA Control Panel" by right clicking on the desktop screen. And select CUDA-GPUs to the desired gpu you want to use for DL training, In my case: I chose 2nd GPU Peace!!

Send and Receive Task example in Oracle BPM

This post talks about Oracle BPM process communication with Asynchronous service. When we talk about BPM process communication with other processes or services, Those processes or services can be synchronous or asynchronous. Synchronous process/service can be invoked with Service Call flow object in Oracle BPM. It will be a straight forward approach,just by adding WebService adapter at external references and using service task to invoke the service. In case of Asynchronous process /service,we must use send /receive task or throw/catch message events when designing flows in BPM. Summary : Asynchronous process wont wait for response to be returned immediately. As soon as its been invoked ,the process will be running in the background.Its the responsibility of calling process  to make sure to look for callback response from asynchronous process for the sent request. In order to identify the correlation between request and response , the design has to be made in such a way to use

Send/Receive task vs Throw/Catch Message events in Oracle BPM

In Oracle BPM "Service task" is used for invoking Synchronous web-service calls. It wont be useful for Asynchronous service calls. To deal with  Asynchronous service calls,  Send/Receive or Throw/Catch events need to be used. There are few differences and similarities between Send/Receive and Throw/Catch Message events. Please have a look at them below. Send/Receive Task Throw/Catch Message Events Can it be used to initiate task? Yes Yes Can it be used to call/invoke Synchronous services/processes? No No Can it be used to call/invoke Asynchronous services/processes? Yes Yes Does correlation/conversation need to be set to deal with Asynchronous tasks? Yes Yes Can it have boundary events associated to it? Yes No Can these pair be used to create synchronous process /service? Yes Yes Can these pair be used to create Asynchronous process /service? Yes Yes Send and Receive task example with boundary events attached to it can be fou