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();
listsStub.setUsername("NotMyDomain\\NotMyUser");
listsStub.setPassword("NotMyPassword");
GetListResponseGetListResult result = listsStub.getList("Test1");
for(MessageElement me : result.get_any()) {
System.out.println(me.toString());
}
}
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.out.println(System.getProperty("javax.net.ssl.trustStore"));
System.out.println(System.getProperty("javax.net.ssl.trustStorePassword"));
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
HttpTransportProperties.Authenticator();
auth.setUsername ("notMyUser");
auth.setPassword("notMyPassword");
auth.setDomain ("DOMAIN");
auth.setHost("host.domain.com");
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();
getListItems0.setListName("MyList");
listsStub.getListItems(getListItems0);
}
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).