SimpleWS.java
package demo;
import weblogic.jws.WLHttpTransport;
import weblogic.jws.Policies;
import weblogic.jws.Policy;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
@WebService(name=”SimpleWSPortType”,
serviceName=”SimpleWSService”,
targetNamespace=”http://www.oracle.com”)
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
@WLHttpTransport(contextPath=”SimpleWSService”,
serviceUri=”SimpleWSService”,
portName=”SimpleWSServicePort”)
@Policy(uri=”policy:Sign.xml”)
public class SimpleWS {
@WebMethod()
public String sayHello(String s) {
return “Hello ” + s;
}
}
Client.java
package demo;
import demo.*;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import javax.xml.rpc.Stub;
import weblogic.security.SSL.TrustManager;
import weblogic.wsee.security.bst.ClientBSTCredentialProvider;
import weblogic.xml.crypto.wss.WSSecurityContext;
import weblogic.xml.crypto.wss.provider.CredentialProvider;
public class Client {
public static void main(String[] args) throws Throwable {
//client private key file
String keyFile = args[0];
//client certificate
String clientCertFile = args[1];
String wsdl = args[2];
// Standard JAX-RPC code to get a service and port type
SimpleWSService service = new SimpleWSService_Impl(wsdl);
SimpleWSPortType port = service.getSimpleWSServicePort();
//create emtpy list of credential providers
List credProviders = new ArrayList();
//Create client-side BinarySecurityToken credential provider that uses
// X.509 for identity, based on certificate and keys parameters
CredentialProvider cp = new ClientBSTCredentialProvider(clientCertFile, keyFile);
credProviders.add(cp);
Stub stub = (Stub)port;
// Set stub property to point to list of credential providers
stub._setProperty(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);
stub._setProperty(WSSecurityContext.TRUST_MANAGER,
new TrustManager(){
public boolean certificateCallback(X509Certificate[] chain, int validateErr){
return true;
}
} );
String response = port.sayHello(“World”);
System.out.println(“response = ” + response);
}
}
build.xml
<project name=”SimpleWS” default=”all” basedir=”.”>
<property name=”ws.file” value=”SimpleWS” />
<property name=”ear.dir” value=”EAR” />
<property name=”client.dir” value=”Client-dir” />
<path id=”client.class.path”>
<pathelement path=”${client.dir}”/>
<pathelement path=”${java.class.path}”/>
</path>
<taskdef name=”jwsc”
classname=”weblogic.wsee.tools.anttasks.JwscTask” />
<taskdef name=”clientgen”
classname=”weblogic.wsee.tools.anttasks.ClientGenTask” />
<target name=”all” depends=”clean,server,client, deploy” />
<target name=”build” depends=”clean,server,client” />
<target name=”clean”>
<delete dir=”${ear.dir}”/>
<delete dir=”${client.dir}”/>
</target>
<target name=”server”>
<mkdir dir=”${ear.dir}”/>
<jwsc
srcdir=”${basedir}”
destdir=”${ear.dir}”
classpath=”${java.class.path}”
fork=”true”
keepGenerated=”true”
deprecation=”${deprecation}”
debug=”${debug}”
verbose=”false”>
<jws file=”${ws.file}.java” explode=”true”/>
</jwsc>
</target>
<target name=”deploy”>
<wldeploy action=”deploy”
source=”${ear.dir}” user=”weblogic”
password=”weblogic” verbose=”true”
failonerror=”${failondeploy}”
adminurl=”t3://localhost:7001?
targets=”AdminServer” />
</target>
<target name=”redeploy”>
<wldeploy action=”redeploy” source=”${ear.dir}”
user=”weblogic” password=”weblogic” verbose=”true”
failonerror=”${failondeploy}”
adminurl=”t3://localhost:7001?
targets=”AdminServer” />
</target>
<target name=”client”>
<mkdir dir=”${client.dir}”/>
<clientgen
wsdl=”${ear.dir}/${ws.file}/WEB-INF/SimpleWSService.wsdl”
destDir=”${client.dir}”
classpath=”${java.class.path}”
packageName=”demo”/>
<javac
srcdir=”${client.dir}” destdir=”${client.dir}”
classpath=”${java.class.path}”
includes=”demo/*.java”/>
<javac
srcdir=”${basedir}” destdir=”${client.dir}”
classpath=”${java.class.path};${client.dir}”
includes=”Client.java”/>
</target>
<target name=”run” >
<java fork=”true”
classname=”demo.Client”
failonerror=”true” >
<classpath refid=”client.class.path”/>
<arg line=”client-key-pkcs8.der client-cert.der http://localhost:7001/SimpleWSService/SimpleWSService?WSDL” />
</java>
</target>
</project>
References:
http://download-llnw.oracle.com/docs/cd/E15051_01/wls/docs103/webserv_sec/message.html