Put UsernameToken.xml in the same package of the web service client class. 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://loc...
Add @WebService(name="", serviceName="", portName="") annotation for the class. Add @Policy(uri = "policy:UsernameToken.xml") for the class. Add @WebMethod(operationName="") for method. Add @WebResult(name="") for method return name. Add @WebParam(name="") for method argument. Create policies folder under WEB-INF. Put the UsernameToken.xml under policies folder. The content of the xml file: <?xml version="1.0"?> <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512" > <sp:SupportingTokens> <wsp:Policy> <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient"> <wsp:Policy> <sp:WssUsernameToken10/> </wsp:Policy> </sp:UsernameToken> </wsp:Policy> </sp:SupportingTokens...
Add Dynamic Web Module and Oracle WebLogic Web Service Clients in Project Facets. Add Oracle WebLogic Server 11g in the Project Facets -> Runtimes. Right Click on the project and new a WebLogic Web Services -> Web Service Client. Select Remote WSDL Location. In the Customization Options, choose Define WSDL location at runtime when client instantiated.