Thursday, October 10, 2019

[JAVA-SOAP] How to build a client for Microsoft SOAP web service

Microsoft build the SOAP-based web service usually support two types of authentication:

  • NTLM - support both http and https
  • Basic - support https only
So before the web service is published(use https) we have to use NTLM(Windows Kerberos and NT LAN Manager), and this is not supported by any JAVA related SOAP service by default, to do so you have to customize, the below is the code snippet:

IService service = new Xa_Service().getXa();
Client client = ClientProxy.getClient(service);

// Set web serice endpoint
BindingProvider provider = (BindingProvider)service;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.x.com/service.wsdl");

// Register NTLM authentication
PolicyInterceptorProviderRegistry registry = client.getBus().getExtension(PolicyInterceptorProviderRegistry.class);
QName ntmlIgnore = new QName("http://schemas.microsoft.com/ws/06/2004/policy/http", "NtlmAuthentication");
registry.register(new IgnorablePolicyInterceptorProvider(ntmlIgnore));

// Set credential
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getAuthorization().setUserName(domain + "\\" + username);
http.getAuthorization().setPassword(password);

No comments:

Post a Comment