Pages

Thursday, May 21, 2009

Get the full ESB request header of a routing service

Sometimes in an ESB routing service based on a WSDL, I want to retrieve data from the SOAP Header so I can use the xml signature in the xlst transformation. Oracle has made some xslt functions so you can retrieve data from the request header ( for more information see this presentation ) . These XSLT functions can only return the values even when you use xsl:copy-of. So let's make our own XSLT library.
First I start with a java class which returns the whole soap header, this class need to have static methods.

package nl.whitehorses.esb.xslt.functions.headers;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import oracle.tip.esb.server.headers.ESBHeaderContext;
import org.w3c.dom.Element;
import oracle.xml.parser.v2.XMLDocument;

public class ESBCustomFunctions {
public static String getHeader() throws IOException {
Element requestHeader = ESBHeaderContext.getRequestHeader();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
((XMLDocument)requestHeader.getOwnerDocument()).print(pw);
return sw.toString();
}
}

This class need the oraesb.jar to complie, this is located at your soa suite home.
Make a jar deployment profile and put this jar in the extension folder of your JDeveloper ( jdev\extensions ) and restart JDeveloper.
Next step is to make a User defined extension function config file. This file is a xml where we register our getHeader method.

<?xml version="1.0" encoding="UTF-8"?>
<extension-functions>
<functions xmlns:customESBFunctions="http://www.oracle.com/XSL/Transform/java/nl.whitehorses.esb.xslt.functions.headers.ESBCustomFunctions">

<function name="customESBFunctions:getHeader" as="string">
</function>

</functions>
</extension-functions>

Use this file in the xsl maps tab of the JDeveloper preferences
When we open a XSLT file, we can see our function in the component palette. Just drag this function in the editor

JDeveloper will automatically add the namespace to the xslt

Because this getHeader function give me the escaped soap header back, Let's transform this to xml with a litte help of the parseEscapedXML function.

Now we only have to put our jar with our getHeader function on the soa suite server. Put the jar in the applib folder of the soa suite container. Last step is to add the jar to the system.xml of the soa suite container. Add the jar to the oracle.bpel.common shared library entry.
That's all

No comments:

Post a Comment