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 :
ii) Java Utils class created to handle dob calculation for XSL custom function is:
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.
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.
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
Post a Comment