Code for web service client to invoke OC4J web service with WSS Username Token policy

  1. Put UsernameToken.xml in the same package of the web service client class.
  2. Please find the code below for the coding details:
protected Location locationWebSPort = null;
protected static volatile LocationWebSManager me;
protected String endpoint = null;
protected String userName = null;
protected String password = null;

protected LocationWebSManager(){
}
public static LocationWebSManager getInstance(){
if (me == null){
synchronized(LocationWebSManager.class){
me = new LocationWebSManager();
}
}
return me;
}


public Location getWebService() throws Exception{
if (locationWebSPort == null){
synchronized(LocationWebSManager.class){
ClientPolicyFeature cpf = new ClientPolicyFeature();
InputStream asStream = LocationWebSManager.class.getResourceAsStream("UsernameToken.xml");
cpf.setEffectivePolicy(new InputStreamPolicySource(asStream));
URL url = new URL(getEndpoint());
QName qName = new QName("http://location.ws.xxx.xx/","Location");
Location_Service service = new Location_Service(url, qName);
Location port = service.getLocationSoapHttpPort(new WebServiceFeature[]{cpf});
Map requestContext = ((BindingProvider)port).getRequestContext();
setPortCredentialProviderList(requestContext);
locationWebSPort = port;
}
}
return locationWebSPort;
}

protected void setPortCredentialProviderList(Map requestContext) throws Exception {
List credList = new ArrayList();
credList.add(getUNTCredentialProvider(getUserName(), getPassword()));
requestContext.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credList);
}

留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser