Index Changes

Embedding Java calls in xpath expressions

Java calls can be embedded in any xpath expressions used in business process, examples are < from >, < to > and < condition > elements. Java calls also can be embedded in xslt style sheets invoked from doXslTransform

Java methods are either written on demand, or existing libraries or JDK library functions. They can be either static or member functions and parameters passed to these functions & return value types needs to be one of the types supported by xpath. They are String, Number, Boolean and Node.
Number maps to all sub classes of java.lang.Number and is converted to java.lang.Double.
Node maps to org.w3c.dom.Node.

Example transformations/utilities that can be implemented could be

  1. copy elements/attributes from one variable to another variable.
  2. validate/enrich the data
  3. to access the JDK utilities like System.currentTimeMillis() & System.nanoTime() that are not enabled to extension functions
  4. search the data
  5. to execute math functions etc.

Usage and Syntax

Syntax is based on http://xml.apache.org/xalan-j/extensions.html#ext-func-calls static functions.

Let us explore syntax details using an example. Please check out working example from cvs -d :pserver:guest@cvs.dev.java.net:/cvs co open-jbi-components/driver-tests/bpelse/POJOCalls

Query for person's address where city is Monrovia

"AddressSearchOperationIn" business process variable, it's part points to a "person" document. Java function (AddressSearchByCity.addressSearchByCity) matches addresses by given city name and returns them. package name - address class name - AddressSearchByCity method name - addressSearchByCity

Define a prefix with fully qualified class name, xmlns:addSearch="java://address.AddressSearchByCity". Invocation would be prefix:function name, for this example it is addSearch:addressSearchByCity

complete syntax

<copy xmlns:addSearch="java://address.AddressSearchByCity">
    <from>addSearch:addressSearchByCity($AddressSearchOperationIn.part1, "Monrovia")</from>
    <to>$AddressSearchOperationOut.part1</to>
</copy>

This example demonstrates usage of Java method calls in combination with other xpath expressions. Xpath expression is converting tmpDouble to string and concatenating with value of $inputVar.inputType/ns2:paramA.

<copy xmlns:javastring="java://java.lang.String">
    <from>concat($inputVar.inputType/ns2:paramA, ' + ',javastring:valueOf($tmpDouble))</from>
    <to>$outputVar.resultType/ns2:paramA</to>
</copy>

Packaging

Package Java code in jar file and drop into BPEL project "Process Files" (src) folder. Alternatively it can be placed on Glassfish class path.

If the jar's are big and not specific to the bpel project and are generic utilities that need to be accessed by multiple service units then its best to add it to the application server class-path. The image below shows how that can be achieved using the application server admin console (http://{host-name}:4848), where the ojdbc14.jar is added to the application server system class-path.

Point to Note

Since this is a new feature, the BPEL editor validation logic has not yet accounted for the syntax of the java method calls, therefore to successfully build and deploy the test project the following steps have to be followed. 1. Right click the BPEL project and choose "properties". 2. Select the check-box "Allow build and deploy with errors". The below image shows the selection.

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-29) was last changed on 02-Apr-09 19:59 PM, -0700 by Murali