I am trying to write my first SOAP client to access a document library(Test1) that I created in my company sharepoint server. So far I have created the Stubs using axis (1.4) and created the main method; but when I have tried this code it shows me a 401 Not allowed error in the console.

What is the cause? Something misconfigured? Or do I need to ask for special permissions to use the SP API?

public static int main() {
  String[] destinationUrls = {"https://[sharepoint host]/[sharepoint site]/Test1"};

  ListsLocator listsLocator = new ListsLocator();
  ListsSoapStub listsStub = (ListsSoapStub) listsLocator.getListsSoap();
  GetListResponseGetListResult result = listsStub.getList("Test1");
  for(MessageElement me : result.get_any()) {

As a side note, I do not like having to cast from ListsSoap to ListsSoapStub in order to be able to setup user and password, there is some other method more elegant to do that?

Update: It looks like the axis plugin I am using may be a little outdated, would you advise switching to Apache Axis2 plugin?

Update2: My axis2 code. The SysAdmin has confirmed that we use NTLM; I had to add the SSL certificate to cacerts and setup the System properties. Yet I get the same error.

public static void main(String[] args) throws Exception {
    System.setProperty("javax.net.ssl.trustStore", "C:/Archivos de programa/Java/jre1.6.0_02/lib/security/cacerts");
    System.setProperty("javax.net.ssl.trustStorePassword", "notAPassword");

    HttpTransportProperties.Authenticator auth = new
    auth.setUsername ("notMyUser");
    auth.setDomain ("DOMAIN");

    List<String> authPrefs = new ArrayList<String>(1);
    authPrefs.add (AuthPolicy.NTLM);
    auth.setAuthSchemes (authPrefs);

    ListsStub listsStub = new ListsStub("https://host.domain.com/_vti_bin/Lists.asmx");
    GetListItems getListItems0 = new GetListItems();

Final Update: Ok, this was easier, I only forgot the following line:

listsStub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);

Now it works (in the sense that the error appears while processing the SP WS response).

  • What's the authentication mechanism used on your SP site? NTLM? Basic? FBA? – Jaap Vossers Jul 27 '11 at 12:30
  • @'Jaap Vossers' I have checked with SA, it is NTLM – SJuan76 Jul 27 '11 at 13:06

My gut feel says the client is trying to authenticate using Basic auth. Use an http sniffer (like Fiddler) to inspect the http headers to confirm.

I reckon there is some extra work involved getting an Axis (Java) client to talk with a server that uses NTLM (Microsoft) authentication.

  • Since you left your comment I have been reading some documentation and probably you are right. Anyway it may take a time for me to confirm it; another of the things that I have found suggest that I should be using axis2 (WebServices) instead of axis (RPC), so it may be a couple of days before I can verify it (be patient). – SJuan76 Jul 27 '11 at 20:54
  • I have updated my code, the error still appears. – SJuan76 Jul 28 '11 at 11:47
  • I was setting the authentification option but not passing it to the stub. I do not know which of the many mistakes I have found is what caused the original message, but I would have stumbled with the NTLM sooner or later so I'll check it as the correct answer. – SJuan76 Jul 28 '11 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.