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
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();
}
}
<?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>
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.
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";
}
}
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>
<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>
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.
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
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.