How to write a Java Client supplying username/password for a WebService secured using the oracle/wss_username_token_service_policy

In the EM Console go to the ‘Test’ page for the service you are developing a client for and copy the WSDL url.

WSDLFromEM

In JDeveloper, in your Java Project, create a new Web Service Proxy

NewWSProxy

When setting the wsdl url, change ‘wsdl’ to ‘orawsdl’

orawsdl

Go through the wizard accepting the defaults and setting appropriate package names for the generated classes. In the Client policy section, select ‘oracle/wss_username_token_service_policy’

SelectClientPolicy

When you finish this wizard the Web Service client classes will be generated. Look at the code below to see how the User Id and Password are set when calling the Web Service.

package webserviceClientApp;</code>

import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceRef;

import weblogic.wsee.jws.jaxws.owsm.SecurityPoliciesFeature;
// !THE CHANGES MADE TO THIS FILE WILL BE DESTROYED IF REGENERATED!
// This source file is generated by Oracle tools
// Contents may be subject to change
// For reporting problems, use the following
// Version = Oracle WebServices (11.1.1.0.0, build 130224.1947.04102)

public class UserNamePasswordStartPortClient {
@WebServiceRef
private static UserNamePasswordStartService userNamePasswordStartService;

public static void main(String[] args) {
userNamePasswordStartService = new UserNamePasswordStartService();
SecurityPoliciesFeature securityFeatures =
new SecurityPoliciesFeature
(new String[] { "oracle/wss_username_token_client_policy" });
UserNamePasswordStartPortType userNamePasswordStartPortType =
userNamePasswordStartService.getUserNamePasswordStartPort(securityFeatures);
// Add your code to call the desired methods.
((BindingProvider)userNamePasswordStartPortType).
getRequestContext().put(BindingProvider.USERNAME_PROPERTY,"jaideep");
((BindingProvider)userNamePasswordStartPortType).
getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,"welcome1");
userNamePasswordStartPortType.start();

}
}
Jaideep