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.