Search code examples
javasoapsoap-clientwsimport

Issue with wsimport authentication when generating SOAP Java client


I use the following command to generate web service client files for java.

wsimport -keep http://test.com/test?wsdl -xauthfile auth.txt

The following was in auth.txt

http://user:password@ip:port//path

But, the password was having special characters like abcw@sdsds. So I was getting wrong format error. So I have encoded password like abcw%40sdsds. But, now got authentication error due to wrong password because of parsing.

Is there any ways to handle this scenario ?


Solution

  • After checking online I found this bug was actually fixed in the latest version. But I still get the same issue. You can refer to the following links for information on the bug.

    https://github.com/javaee/metro-jax-ws/issues/1101

    So I finally made custom HTTP request with NTLM authentication using HTTP Client in Java.

    String bodyAsString = ""; //Provide Input SOAP Message
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY,
    new NTCredentials("UserName", "Password", "Host", "Domain"));
    HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
    HttpPost post = new HttpPost("URL"); //Provide Request URL
    try 
    {
       StringEntity input = new StringEntity(bodyAsString);
       input.setContentType("text/xml; charset=utf-8");
       post.setEntity(input);
       post.setHeader("Content-type", "text/xml; charset=utf-8");
       post.setHeader("SOAPAction", ""); //Provide Soap action
    
       org.apache.http.HttpResponse response = client.execute(post);
       HttpEntity responseEntity = response.getEntity();
       if (responseEntity != null) 
       {
          return EntityUtils.toString(responseEntity);
       }
    }
    

    I got the above solution from the following github link https://github.com/sujithtw/soapwithntlm