Search code examples
javawsdlsoap-clientnavision

call a method on Navision webservice using NTML authentication using Java


I've created a SOAP web-service client on Netbeans. The web-service is exposed on Navision with NTML authentication. During class generation, a login pop-up picks the required credentials and uses them for authentication. The issue is once the classes are generated and I try to invoke any method;

    ServicePort webservice_port = new WService().getServicePort();
    webservice_port.retrieveData();

I get an exception.

java.io.IOException: Server returned HTTP response code: 401 for URL: ...

Exception in thread "main" com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:275)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:246)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:209)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:178)
    at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:363)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:321)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:230)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:211)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:207)
    at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:114)
    at javax.xml.ws.Service.<init>(Service.java:57)
    at com.ntml.remote.MSACCO.<init>(MSACCO.java:42)

Is this an issue with NTLM authentication or is there another way to pass the credentials?


Solution

  • Found a working solution. Injecting an authentication mechanism to the client using the web service port.

            Port webservice_port = new Wservice().getServicePort();
            Client client = ClientProxy.getClient(webservice_port);
            HTTPConduit conduit = (HTTPConduit) client.getConduit();
            AuthorizationPolicy authorization = conduit.getAuthorization();
            authorization.setUserName(username);
            authorization.setPassword(password);
            conduit.getClient().setAllowChunking(false);
            conduit.getClient().setAutoRedirect(true);
            webservice_port.callWebMethod();