Step 1: down load jax-ws (jaxws-ri-2.2.8) jar file to convert wsdl to stub classes and run the following command to get the sub classes.
wsimport -keep -p com.thejavageek.client http://yourhostname:14000/spml-xsd/SPMLService?WSDL
Step 2: create a client program in your package
import java.util.List;
Step 2: create a client program in your package
import java.util.List;
import javax.xml.soap.SOAPException;
import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameRequestType;
import oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameResponseType;
public class TestOIMSPML
{
public static void main(String args[])
throws SOAPException
{
// WebServiceContext ctx=null;
// SOAPFactory sf = SOAPFactory.newInstance();
// SOAPMessageContext context = (SOAPMessageContext)(ctx.getMessageContext());
//HeaderHandlerResolver hh =new HeaderHandlerResolver("xelsysadm","Password");
SPMLService ss = new SPMLService();
SPMLRequestPortType port = ss.getSPMLServiceProviderSoap();
Binding binding = ((BindingProvider) port).getBinding();
List handlers = binding.getHandlerChain();
handlers.add(new HeaderHandlerResolver("xelsysadm","********"));
binding.setHandlerChain(handlers);
// ctx.getMessageContext();
ValidateUsernameRequestType validateUser = new ValidateUsernameRequestType();
validateUser.setUsername("sbeynon");
ValidateUsernameResponseType retValUser = port.spmlValidateUsernameRequest(validateUser);
System.out.println("spml validate user =" + retValUser.isValid());
}
}
Step 3: when you try to execute the above program you will get an error like security header is missing, to avoid this error. you need to append the security header in your request, for this develop the following class,
this class will generate security header.
import java.util.Collections;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class HeaderHandlerResolver
implements SOAPHandler
{
String userid;
String passowrd;
SOAPHeader soapHeader = null;
public HeaderHandlerResolver(String userid, String password)
{
this.userid = userid;
this.passowrd = password;
}
public Set getHeaders()
{
return Collections.emptySet();
}
public boolean handleMessage(MessageContext pcontext)
{
try
{
SOAPMessageContext context = (SOAPMessageContext) pcontext;
SOAPMessage message = context.getMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
if (header == null)
{
header = envelope.addHeader();
}
QName qNameUserCredentials =
new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
SOAPHeaderElement userCredentials =
header.addHeaderElement(qNameUserCredentials);
QName qUsernameToken =
new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken");
SOAPHeaderElement UsernameToken =
header.addHeaderElement(qUsernameToken);
userCredentials.addChildElement(UsernameToken);
QName qNameUsername = new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Username");
SOAPHeaderElement username = header.addHeaderElement(qNameUsername);
username.addTextNode(this.userid);
QName qNamePassword =
new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Password");
SOAPHeaderElement password = header.addHeaderElement(qNamePassword);
password.addTextNode(this.passowrd);
UsernameToken.addChildElement(username);
UsernameToken.addChildElement(password);
message.saveChanges();
System.out.println(message.getSOAPHeader().getTextContent());
}
catch (Exception e)
{
e.printStackTrace();
}
return true;
}
public boolean handleFault(MessageContext pContext)
{
return false;
}
public void close(MessageContext pContext)
{
}
}
import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameRequestType;
import oracle.iam.wsschema.model.spmlv2custom.username.ValidateUsernameResponseType;
public class TestOIMSPML
{
public static void main(String args[])
throws SOAPException
{
// WebServiceContext ctx=null;
// SOAPFactory sf = SOAPFactory.newInstance();
// SOAPMessageContext context = (SOAPMessageContext)(ctx.getMessageContext());
//HeaderHandlerResolver hh =new HeaderHandlerResolver("xelsysadm","Password");
SPMLService ss = new SPMLService();
SPMLRequestPortType port = ss.getSPMLServiceProviderSoap();
Binding binding = ((BindingProvider) port).getBinding();
List handlers = binding.getHandlerChain();
handlers.add(new HeaderHandlerResolver("xelsysadm","********"));
binding.setHandlerChain(handlers);
// ctx.getMessageContext();
ValidateUsernameRequestType validateUser = new ValidateUsernameRequestType();
validateUser.setUsername("sbeynon");
ValidateUsernameResponseType retValUser = port.spmlValidateUsernameRequest(validateUser);
System.out.println("spml validate user =" + retValUser.isValid());
}
}
Step 3: when you try to execute the above program you will get an error like security header is missing, to avoid this error. you need to append the security header in your request, for this develop the following class,
this class will generate security header.
import java.util.Collections;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class HeaderHandlerResolver
implements SOAPHandler
{
String userid;
String passowrd;
SOAPHeader soapHeader = null;
public HeaderHandlerResolver(String userid, String password)
{
this.userid = userid;
this.passowrd = password;
}
public Set getHeaders()
{
return Collections.emptySet();
}
public boolean handleMessage(MessageContext pcontext)
{
try
{
SOAPMessageContext context = (SOAPMessageContext) pcontext;
SOAPMessage message = context.getMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
if (header == null)
{
header = envelope.addHeader();
}
QName qNameUserCredentials =
new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
SOAPHeaderElement userCredentials =
header.addHeaderElement(qNameUserCredentials);
QName qUsernameToken =
new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken");
SOAPHeaderElement UsernameToken =
header.addHeaderElement(qUsernameToken);
userCredentials.addChildElement(UsernameToken);
QName qNameUsername = new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Username");
SOAPHeaderElement username = header.addHeaderElement(qNameUsername);
username.addTextNode(this.userid);
QName qNamePassword =
new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Password");
SOAPHeaderElement password = header.addHeaderElement(qNamePassword);
password.addTextNode(this.passowrd);
UsernameToken.addChildElement(username);
UsernameToken.addChildElement(password);
message.saveChanges();
System.out.println(message.getSOAPHeader().getTextContent());
}
catch (Exception e)
{
e.printStackTrace();
}
return true;
}
public boolean handleFault(MessageContext pContext)
{
return false;
}
public void close(MessageContext pContext)
{
}
}