Showing posts with label customXpath. Show all posts
Showing posts with label customXpath. Show all posts

Wednesday, September 4, 2013

OSB: Custom XPath vs Java Callout classloader difference

the Custom Xpath classloader doesn't access the jars in the domain lib folder (like /opt/oracle/domains/osbpl1do/lib folder), while the java callout does. So a function might work when invoked by JavaCallout, but give a nasty error from a customxpath:
 java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Hex
 at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
 at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
 at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)


If you need some common libraries in a Custom Xpath, you better add the jar explicitly to the JVM classpath
vi /opt/oracle/domains/osbpl1do/bin/setDomainEnv.sh

EXT_POST_CLASSPATH=/opt/oracle/domains/osbpl1do/lib/commons-codec-1.4.jar
restart your managed server
Check the JVM classpath:
pid="the managed server pid"
jinfo -sysprops ${pid} | grep java.class.path | awk -F'=' '{print $2}'

this gives me this new classpath:
....many more
/opt/oracle/fmw11_1_1_5/wlserver_10.3/server/lib/xqrl.jar
/opt/oracle/domains/osbpl1dom/lib/commons-codec-1.4.jar
/opt/oracle/fmw11_1_1_5/patch_wls1035/profiles/default/sys_manifest_classpath/weblogic_patch.jar
....many more

For more on WebLogic classloader, see here

Saturday, July 14, 2012

XmlObject Arrays in OSB Custom XPaths

I have lost 20 minutes to find out that, if you return a XmlObject[] in your Java function, in the customxpath.xml descriptor you should put
[Lorg.apache.xmlbeans.XmlObject;
and not
Lorg.apache.xmlbeans.XmlObject;

as the official doc might seem to suggest

Friday, July 13, 2012

java-content in OSB XQuery

http://docs.oracle.com/cd/E23943_01/admin.1111/e15867/context.htm#i1106669

The content's metadata (that is, its key) can be handled as any other XML, for example in an XQuery such as $pojo/java-content/@ref. This may be useful for logging or debugging, but the content of the object cannot be directly accessed.


The reference to the Java object cannot be passed to an XQuery, who can in turn pass it to a Custom XPath for further manipulation in Java????

A practical case; I have a Java Callout creating a Java object for me:

public static ConcurrentHashMap createPriceMap() {
ConcurrentHashMap result = new ConcurrentHashMap();
return result ;
}

I assign it to a $mymap variable; if I log $mymap I get:

<con:java-content ref="jcid:72c9f10e:1387982c6c6:-7fb8" xmlns:con="http://www.bea.com/wli/sb/context"/>


Yet I can pass this $mymap as input parameter to other Java Callouts, no tricks, no problem.

Yet it seems that in XQuery there is not a specific syntax to pass $mymap...not a way to get a reference to the pipeline context to retrieve the Java object based on its ref. how sad.

A workaround could be to store the Java Object in a global hashmap, accessible through a Java static method, using the java-content ref as a key, and remember to remove it otherwise it will leak memory...

Monday, December 19, 2011

Custom XPath libraries

http://code.google.com/p/soalabs/

We thank again Sandeep Phukan (we wrote about him here) for his excellent library of Custom XPath functions.

Here his wiki.

Tuesday, June 28, 2011

OSB Custom XPath Functions

I have followed the instructions here:

http://download.oracle.com/docs/cd/E21764_01/doc.1111/e15866/custom_xpath.htm


added an extra category and function to the  $ORACLE_HOME/Oracle_OSB1/config/xpath-functions/osb-built-in.xml  file,
in the same $ORACLE_HOME/Oracle_OSB1/config/xpath-functions/ directory I put the JAR with the function

the good news is that it really works! I find these custom XPath function a powerful way to carry out message manipulations too complex to do in XQuery.

Java rules! Use the Force!



to check if anything went wrong, grep for something like:
CustomXPathFunctionManager: Failed to register custom XPath function

also:
make sure no blank spaces are in the XML file

for arrays, make sure you use the notation [Ljava.lang.String;