Basic steps to follow :
1.Create a java class and implement your method.
2.Create a configuration file that describes the XPath function and links it to the java method.
3.Add the function at design time in JDev.
4.Make the function available at run time.
For BPEL, Mediator and Human Workflow, this process is quite different.The class that contain the method must implement the interface oracle.fabric.common.xml.xpath.IXPathFunction.This interface has single method.The signature of he method is :
public Object call(oracle.fabric.common.xml.xpath.IXPathContext ctx,java.util.List params)
package xathbpelfunction;
import java.util.List;
import oracle.fabric.common.xml.xpath.IXPathContext;
import oracle.fabric.common.xml.xpath.IXPathFunction;
public class UtilityFunctions implements IXPathFunction{
public Object call(IXPathContext context,List args) {
String str=(String)args.get(0);
return processString(str);
}
private String processString(String str){
if(str==null)
return null;
return "hello "+str;
}
}
Now create an XML file named "ext-soa-xpath-functions-config.xml" and put it under the META-INF directory that you created.The source of the file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<soa-xpath-functions version="11.1.1" xmlns="http://xmlns.oracle.com/soa/config/xpath" xmlns:func="http://test.functions.com">
<function name="func:test">
<className>xathbpelfunction.UtilityFunctions</className>
<return type="string"/>
<params>
<param name="str" type="string"/>
</params>
<desc>hello world method</desc>
</function>
</soa-xpath-functions>
Newly created Java Project needs to include the oracle.soa.fabric.jar in its classpath to support custom functions. Right click on the new Java Project in the Application Explorer and choose “Libraries and Classpath” Click the “Add Jar” button and navigate to the oracle.soa.fabic.jar in the ${FMWHome}/Oracle_SOA1/soa/modules/oracle.soa.fabric_11.1.1/oracle.soa.fabric.jar
Next, notice that there is no method named test in out java class.Here the method 'call' is going to be invoked automatically when the function is invoked.Now create a jar file and follow the same steps as before to add the function in JDev at design time.Also, place the jar file in the <<MW_HOME>>/user_projects/domains/<<domain_name>>/lib or under a sub-directory of lib and restart the weblogic server.
To use the custom function in SOA Suite we need to add it to the SOA extension libraries. We do this by copying the jar file to the $ORACLE_SOA_HOME/soa/modules/oracle.soa.ext_11.1.1 directory on the SOA Suite installation. We then run ant in that directory (setting JAVA_HOME if necessary) by executing $FMW_HOME/modules/org.apache.ant_1.7.1/bin/ant.
[oracle@soa.ext_11.1.1]$ ../../../../modules/org.apache.ant_1.7.1/bin/ant
Buildfile: build.xml
create-manifest-jar:
[echo] Creating oracle.soa.ext at …/FMW/Oracle_SOA/soa/modules/oracle.soa.ext_11.1.1/oracle.soa.ext.jar…
BUILD SUCCESSFUL
Total time: 1 second
We then need to restart the SOA Suite to get it to recognise the change.
Now create a SOA project and add a BPEL process.Then drag an assign activity.Open the assign and select copy operation.Then bring up the expression builder and select user defined extension function from the drop down menu.The function test should appear.
No comments:
Post a Comment