3 messages in com.googlegroups.google-enterprise-developerSharepoint java integration through w...
FromSent OnAttachments
Ranjanlal18 Aug 2007 09:42 
Ranjanlal18 Aug 2007 09:45 
ryan...@gmail.com28 Sep 2007 06:24 
Subject:Sharepoint java integration through web services returns (401)Unauthorized error
From:Ranjanlal (rlbh@gmail.com)
Date:08/18/2007 09:42:14 AM
List:com.googlegroups.google-enterprise-developer

Hi All,

I am trying to connect Microsoft Sharepoint services through its web services from java code. I am setting domain/username and password at system as well as application level.

Everytime it is returning (401)Unauthorized error.

I am able to connect the web services through 4 process. All the processes returning same error code.

First Process:

File file = new File("C:/axis.bat"); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); byte b[] = new byte[bis.available()]; bis.read(b); Object data[] = new Object[4]; data[0] = "First"; data[1] = "Second"; data[2] = "abcd.doc"; data[3] = b; String endpoint = "http://server/_vti_bin/lists.asmx"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("AddAttachment")); call.setSOAPActionURI("http://schemas.microsoft.com/sharepoint/soap/ GetListCollection"); call.setUsername("DOMAIN\\username"); call.setPassword("password"); String ret = (String) call.invoke(data); System.out.println(ret);

Second Process:

ListsSoapStub stub; ListsLocator locator = new ListsLocator(); URL url = new URL("http://server/_vti_bin/lists.asmx"); stub = (ListsSoapStub)locator.getListsSoap(url); stub.setUsername("DOMAIN\\username"); stub.setPassword("password"); stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "DOMAIN\ \username"); stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "password"); stub._setProperty("http.username", "DOMAIN\\username"); stub._setProperty("http.password", "password"); File file = new File("C:/axis.bat"); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); byte b[] = new byte[bis.available()]; bis.read(b); System.out.println(b.length); Object data[] = new Object[4]; data[0] = "First"; data[1] = "Second"; data[2] = "abcd.doc"; data[3] = b; stub.addAttachment("First", "Second", "axis.bat", b);

Third process:

String stUrl = "http://servername/_vti_bin/lists.asmx"; Service service = new Service(); File file = new File("C:/axis.bat"); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); byte b[] = new byte[bis.available()]; bis.read(b); System.out.println(b.length); Object data[] = new Object[4]; data[0] = "First"; data[1] = "Second"; data[2] = "abcd.doc"; data[3] = b; Call call = (Call) service.createCall(); ListsLocator lc = new ListsLocator(); ListsSoap ls = lc.getListsSoap(); ((ListsSoapStub)ls).setPassword("test123!"); ((ListsSoapStub)ls).setUsername("GDC-TEST\\administrator"); ls.addAttachment("First", "Second", "axis.bat", b);

Fourth Process:

System.setProperty("http.username", "DOMAIN/username"); System.setProperty("http.password", "password"); String endpoint = "http://servername/_vti_bin/lists.asmx"; Service service = new Service(); Call call = (Call) service.createCall(); call.setUsername("DOMAIN/username"); call.setPassword("password"); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("AddAttachment")); call.setOperationName(new QName("", "AddAttachment")); call.setSOAPActionURI("http://schemas.microsoft.com/sharepoint/soap/ GetListCollection"); call.setUseSOAPAction(true); call.setUsername("DOMAIN/username"); call.setPassword("password"); call.addParameter("listName", org.apache.axis.Constants.SOAP_STRING, ParameterMode.IN); call.addParameter("listItemID", org.apache.axis.Constants.SOAP_STRING, ParameterMode.IN); call.addParameter("fileName", org.apache.axis.Constants.SOAP_STRING, ParameterMode.IN); call.addParameter("attachment", org.apache.axis.Constants.SOAP_BASE64, ParameterMode.IN); call.setReturnType(org.apache.axis.Constants.SOAP_STRING); File file = new File("C:/axis.bat"); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); byte b[] = new byte[bis.available()]; bis.read(b); Object data[] = new Object[4]; data[0] = "First"; data[1] = "Second"; data[2] = "abcd.doc"; data[3] = b; Object greet = (Object)call.invoke(data); System.out.println(greet.getClass().getName()); System.out.println(greet.toString());

Any idea?