Pages

Monday, May 25, 2009

Middleware 11g performance guide

I was searching for some documentation about MDS errors and I came across this online help Oracle® Fusion Middleware Performance Guide 11g Release 1. Just check this out, dont know how long this page will be available ( it is beta).
For example you can use this console logger in your JDeveloper 11g application. It opens automatically when you start your web application.

To activate this just add these context parameters to your web.xml

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

Monday, May 18, 2009

Weblogic WS policies and Netbeans & Metro (WSIT)

In JDeveloper 11g and in the Weblogic 10.3 Console it is easy to add a security policy on a web service. But calling these services in a web service client is a different story. So far there is no support for these policies in web service proxy client wizard of JDeveloper 11g. Gerard Davison is doing a great job by making a lot of blog items how to do this programmatically in JDeveloper 11g. But lucky for us there is an alternative. With a little help of Netbeans and Metro it is not so difficult to call these webservices with Wssp1.2-2007 policies.
First we start by making a JAX-WS Web Service and adding a policy.
The Helloworld Web Service with HTTPS and plain username policy which I use in this example.

package nl.whitehorses.ws.saml;

import javax.jws.WebService;
import weblogic.jws.Policy;

@WebService(name = "HelloWorldService", portName = "HelloWorldServiceSoapHttpPort")
@Policy(uri = "policy:Wssp1.2-2007-Https-UsernameToken-Plain.xml")
public class HelloWorld {
public HelloWorld() {
}

public String sayHello() {
return "Hello world";
}
}

Deploy this on a Weblogic server and make sure the HTTPS port is working. See the keystore / ssl tab of the Weblogic server configuration.

Now we can download the latest Netbeans ( I use version 6.5.1 ) and Metro 1.5. Install Netbeans and add the latest Metro jars to your Glassfish 2 server. ( use ant & metro-on-glassfish.xml for this ). The Weblogic 2007/02 policies are using 256 bits encryption, so we need to download the Java Cryptography Extension (JCE) files and install this on every JDK we are using. The last install step is add to the wsit demo keystores to the glassfish server.

Step 1 is to download the WSDL of the Helloworld Service.
Save this xml to the HelloworldService.wsdl file and open this in a editor. We have to remove the policy reference in the porttype and add this to the binding

<portType name="HelloWorldService" wsp:PolicyURIs="#Wssp1.2-2007-Https-UsernameToken-Plain.xml">
<operation name="sayHello">
<input message="tns:sayHello"/>
<output message="tns:sayHelloResponse"/>
</operation>
</portType>
<binding name="HelloWorldServiceSoapHttpPortBinding" type="tns:HelloWorldService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayHello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

to

<portType name="HelloWorldService">
<operation name="sayHello">
<input message="tns:sayHello" />
<output message="tns:sayHelloResponse" />
</operation>
</portType>
<binding name="HelloWorldServiceSoapHttpPortBinding" type="tns:HelloWorldService">
<ns2:PolicyReference xmlns:ns2="http://www.w3.org/ns/ws-policy" URI="#Wssp1.2-2007-Https-UsernameToken-Plain.xml"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<operation name="sayHello">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>

Else the Netbeans wizard won't detect the policy.

Create a new Web Application in Netbeans
Select the new project and add a new Web Service Client

Select the HelloworldService wsdl

Select the just created web service reference and select "Edit Web Service Attributes" on this reference

Deselect "Use development defaults" and provide a Username / password of a valid Weblogic account.

Select for the private key which will be used in the encryption.


And the select the public key of the Weblogic server certificate.
When we take a look at the META-INF folder in the source folder, we can see that the wizard has created a web service configuration file which will be used by Metro to setup the security to the Weblogic Web Service

To test this web service client, we will add a servlet to the project


Deselect the comment and use the right button to add a web service client reference
At the project properties we can call the servlet by using the servlet url in the relative url ( Run)

That's all , it should be working now. For more policies examples see this url , there are some nice examples about Secure Token Service STS.
I am happy Oracle has bought Sun, let's integrate everything to one IDE.