title: JAX-WS Sharepoint 401 Unauthorized NTLM
body: <p>I try to access a Sharepoint list via JAX-WS as described <a href="http://davidsit.wordpress.com/2010/02/10/reading-a-sharepoint-list-with-java-tutorial/" rel="noreferrer">here</a></p>
  
  <p>However, when running the code below I get:</p>
  
  <pre><code>java.lang.Exception: Exception. See stacktrace.com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized
  </code></pre>
  
  <p>Sharepoint requires NTLM authentication. What may be the problem? Thanks a lot!</p>
  
  <pre><code>public static ListsSoap sharePointListsAuth(String userName, String password) throws Exception {
      ListsSoap port = null;
      if (userName != null &amp;&amp; password != null) {
          try {
              Lists service = new Lists();
              port = service.getListsSoap();
              System.out.println("Web Service Auth Username: " + userName);
              ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
              ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
          } catch (Exception e) {
              throw new Exception("Error: " + e.toString());
          }
      } else {
          throw new Exception("Couldn't authenticate: Invalid connection details given.");
      }
      return port;
  }
  </code></pre>