I am creating a client to access web service(which is using security token)
I am having the sample code,
private static String USERNAME = "user"; private static String PASSWORD = "user123!"; URL wsdlLocation = new URL("url?wsdl"); QName serviceName = new QName("namespaceURI", "Wservice"); Service s = Service.create(wsdlLocation, serviceName); Wservice wService = s.getPort(Wservice.class); final Binding binding = ((BindingProvider) wService).getBinding(); List<Handler> handlerList = binding.getHandlerChain(); if (handlerList == null) handlerList = new ArrayList<Handler>(); handlerList.add(new DefaultSOAPHandler(USERNAME, PASSWORD)); binding.setHandlerChain(handlerList);
Above code is working for me. But when i am using weblogic to deploy, it is giving an error:
javax.xml.ws.soap.SOAPFaultException: Unable to add security token for identity, token uri =docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken
So I added another mechanism using weblogic package to add username password to SOAP header
final List<CredentialProvider> credProviders = new ArrayList<CredentialProvider>(); CredentialProvider cp = new ClientUNTCredentialProvider(userName.getBytes(), password.getBytes()); //Add credential provider credProviders.add(cp); final Map<String, Object> context = ((BindingProvider) port).getRequestContext(); context.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders); context.put(BindingProvider.USERNAME_PROPERTY, userName); context.put(BindingProvider.PASSWORD_PROPERTY, password); context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlLocation.toString()); context.put(WSSecurityContext.TRUST_MANAGER, new TrustManager() { public boolean certificateCallback(X509Certificate[] chain, int validateErr) { return true; } });
Now this time i am getting another error:
javax.xml.ws.soap.SOAPFaultException: Unknown exception, internal system processing error. at com.sun.xml.ws.fault.SOAP12Fault.getProtocolException(SOAP12Fault.java:227) at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:122) at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:125)
please suggest me how to add security token for identity.