Thursday, July 01, 2010

How to develop custom x-path in ESB

I already have covered how to create a custom x-path in BPEL and use it in following link.

Now in this exercise we will try to create a custom x-path function and see how to use it in ESB

Create a new application and a new project

Now within the project create a new java file append

package esbtest;

public class append {
public append() {
}
public static String addHello(String s){
return("hello" + s);}
}


Compile the java class

Select the code in jdev and say make

Once you will compile the java file it will create a .class file.

To know the location of .class file check in the jdeveloper bottom where is the .java file located.

go one directory up and you will find a classes folder you can get the .class file over there



Now go to the following location

SOA_HOME\integration\esb

and create following folder structure

SOA_HOME\integration\esb\system\classes\esbtest

and copy the .class file over there.

The path i have specified here in a similar way as it is defined for BPEL

esbtest is the name of the package where in my class is defined.



NOw go toSOA_HOME/j2ee//config/server.xml and Add the following line in the
shared library named oracle.bpel.common.



Once done the changes save it and restart your server and now you are ready to use the custom xpath function



NOw in order to verify our setting in ESB we will create a simple process and check if this xpath function can be used properly or not.

I will create a simple esb process which will take an input file and use the custom xpath to modify the input file and write it to output directory.

My ESB process will look something like this







I am not describing the exact process of how i have configured it.I left it to you to do some R &D.

I have used a delimited file which gives three element in input text file

so when i will put a file with following input

arpit,rahi,bangalore

I willl just show how my xsl transformation for this process



<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
<!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
<mapSources>
<source type="WSDL">
<schema location="filein.wsdl"/>
<rootElement name="input" namespace="http://TargetNamespace.com/filein"/>
</source>
</mapSources>
<mapTargets>
<target type="WSDL">
<schema location="fileout.wsdl"/>
<rootElement name="output" namespace="http://TargetNamespace.com/fileout"/>
</target>
</mapTargets>
<!-- GENERATED BY ORACLE XSL MAPPER 10.1.3.4.0(build 080718.0645) AT [FRI JUL 02 15:25:06 IST 2010]. -->
?>
<xsl:stylesheet version="1.0"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
xmlns:sample="http://www.oracle.com/XSL/Transform/java/esbtest.append"
xmlns:pc="http://xmlns.oracle.com/pcbpel/"
xmlns:ehdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.esb.server.headers.ESBHeaderFunctions"
xmlns:ns0="http://www.w3.org/2001/XMLSchema"
xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/"
xmlns:imp1="http://TargetNamespace.com/fileout"
xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/file/filein/"
xmlns:ns2="http://TargetNamespace.com/filein"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ora="http://schemas.oracle.com/xpath/extension"
xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
xmlns:hdr="http://xmlns.oracle.com/pcbpel/adapter/file/"
xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/file/fileout/"
exclude-result-prefixes="xsl plt sample pc ns0 jca ns1 ns2 hdr imp1 tns bpws ehdr hwf xp20 xref ora ids orcl">
<xsl:template match="/">
<imp1:output>
<imp1:C1>
<xsl:value-of select="sample:addHello(string(/ns2:input/ns2:C1))"/>
</imp1:C1>
<imp1:C2>
<xsl:value-of select="/ns2:input/ns2:C2"/>
</imp1:C2>
<imp1:C3>
<xsl:value-of select="/ns2:input/ns2:C3"/>
</imp1:C3>
</imp1:output>
</xsl:template>
</xsl:stylesheet>

Now there are few things to note down here.I have added the following parameter in my xsl


xmlns:sample="http://www.oracle.com/XSL/Transform/java/esbtest.append"

It is a xml namespace which use the following format,

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


Then add the defined prefix name to exclude-result-prefixes.

As you can see i have added it in my code the prefix sample

exclude-result-prefixes="xsl plt sample pc ns0 jca ns1 ns2 hdr imp1 tns bpws ehdr hwf xp20 xref ora ids orcl"

NOw finally in the xsl document we can use the code as follows


<xsl:value-of select="<prefix name>:<methodName>(string(Xpath expression or
constant value))"/>


as i have defined it in my case

xsl:value-of select="sample:addHello(string(/ns2:input/ns2:C1))"

Now once changes are done save the project and register it.

ONce we done the changes and input a file in to the input directory you may get an error like this


An unhandled exception has been thrown in the ESB system. The exception reported is: "org.collaxa.thirdparty.apache.wsif.WSIFException: esb:///ESB_Projects/Catch_NewTest/fileout.wsdl [ Write_ptt::Write(output) ] - WSIF JCA Execute of operation 'Write' failed due to: Translation Error.
Error while translating message to native format [Caused by: Element not completed: 'output'].
; nested exception is:
ORABPEL-11017
Translation Error.
Error while translating message to native format [Caused by: Element not completed: 'output'].
Check the error stack and fix the cause of the error. Contact oracle support if error is not fixable.



This error occurs if the custom code that you have defined is not configured correctly.

Verfiy it by removing the custom code and your process will run fine.This is a debugging step which will help you to identify if the root cause lies in the custom code.

1 comment:

bhanu sreee said...

Thank you for sharing wonderful information with us to get some idea about it.
Mulesoft Online Training
Mulesoft Online Course