• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Talk to sharepoint through its web services

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I created a java code to get a list of files from sharepoint serverusing SSL.

Handshake is done correctly, but i'm still not able to get successfully connected.

Here is the message i'm getting:

You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.

Here is the code i'm using:
package httpclient;



import java.net.URL;
import java.security.Security;
import java.util.Iterator;

import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.auth.AuthScope;

import org.apache.commons.httpclient.methods.PostMethod;


/**
*
* @author Aladin SOHAILI
*/
public class HttpClientTest {

/** Creates a new instance of Main */
public HttpClientTest() {
}




/**
* @param args the command line arguments
*/
public static void main(String[] args) {

// spsearch.asmx@status

String statusQuery="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema/\" " +" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "+
"<soap:Body> "+
"<Status xmlns=\"urn:Microsoft.Search\" />"+
"</soap:Body>"+
"</soap:Envelope>";






//Lists.asmx@GetListItems

String sItems="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema/\" " +" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "+
"<soap:Body> "+
"<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\" >"+
"<listName>Shared Documents</listName>"+
"<viewName></viewName>"+
"<query>"+

"<Query xmlns:ns2=\"http://schemas.microsoft.com/sharepoint/soap/\" xmlns=\"\">"+
"<Where>"+
"<Eq>"+
"<FieldRef Name=\"DocIcon\" />"+
"<Value Type=\"Text\">txt</Value>"+
"</Eq>"+
"</Where>"+
"</Query>"+

"</query>"+

"<viewFields><ViewFields>"+
"<FieldRef Name=\"ID\" /><FieldRef Name=\"Title\" /><FieldRef Name=\"Editor\" /><FieldRef Name=\"Author\" /><FieldRef Name=\"Modified\" /><FieldRef Name=\"Created\" /><FieldRef Name=\"UniqueId\"/>"+
//"<FieldRef Name=\"ID\" /> <FieldRef Name=\"_x0031_\" /> <FieldRef Name=\"_x0032_\" /> <FieldRef Name=\"_x0033_\" />"+

"</ViewFields></viewFields>"+
"<rowLimit></rowLimit>"+

"<queryOptions>"+
"<QueryOptions xmlns:ns2=\"http://schemas.microsoft.com/sharepoint/soap/\" xmlns=\"\">"+
"<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>"+
"<ViewAttributes Scope=\"Recursive\" />"+
"</QueryOptions>"+
"</queryOptions>"+

"<webID></webID>"+
"</GetListItems>"+
"</soap:Body>"+
"</soap:Envelope>";



//System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

//Security.addProvider(new com.sun.crypto.provider.SunJCE());

System.setProperty("javax.net.ssl.trustStore","D:\\MyProjects\\CQIntegration\\Certificates\\db.keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

// Keystore location and password
//System.setProperty("javax.net.ssl.keyStore","D:\\MyProjects\\CQIntegration\\Certificates\\db.keystore");
//System.setProperty("javax.net.ssl.keyStorePassword", "changeit");

System.setProperty("javax.net.debug", "all");


PostMethod postMethod =null;


// TODO code application logic here
System.out.println("Welcome to Java SharePoint Search Client Sample\n");

System.out.println("Soap Query: --------------------------------");
System.out.println(sItems);
System.out.println("-----------------------------------------------");



HttpClient httpClient = new HttpClient();
NTCredentials credentials = new NTCredentials("administrator", "pass@word1", "", "dns");



httpClient.getState().setProxyCredentials(AuthScope.ANY, credentials);


try {

//Post Method



URL url = new URL("https://serverdns/Lists.asmx");

postMethod = new PostMethod(url.toExternalForm());
postMethod.addRequestHeader("Content-Type", "text/xml; charset=utf-8");

postMethod.setDoAuthentication(true);
postMethod.setRequestBody(sItems);

int returnCode = httpClient.executeMethod(postMethod);

if (returnCode != HttpStatus.SC_OK)
{
System.err.println("Method failed: "
+ postMethod.getStatusLine());

System.err.println("Error form server: "+ postMethod.getResponseBodyAsString());
}
else
{



String response = postMethod.getResponseBodyAsString();
System.out.println();

System.out.println("Soap Response: --------------------------------");
System.out.println(response.toString());
System.out.println("-----------------------------------------------");

System.out.println();


}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


finally
{
// Release the connection.
postMethod.releaseConnection();
}
}
}



Many Thanks & Regards.

Aladin
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hii,


I tried this article to get share point document library, but I'm getting the Http Erro 400:bad request.
Please Provide your suggestions


Thanks in advance
 
selvi sibi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I can retrieve getlist collection and getlistitems using the post method. but when access getlistitems with one list , no items are shown, but there is more than one items exists for that listname.
That means if there are list1, list2, list3 document, I get the list items for list2 only. List 1 and List 3 have more than 1 sub items but following ouput is generated when we given list1 and list3 as listname.

For list2

input xml is

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/"><soapenv:Header/><soapenv:Body><soap:GetListItems><soap:listName>List2</soap:listName><soap:viewName></soap:viewName><soap:query></soap:query><soap:viewFields></soap:viewFields><soap:rowLimit></soap:rowLimit><soap:webID></soap:webID></soap:GetListItems></soapenv:Body></soapenv:Envelope>



out xml is

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<rs:data ItemCount="9">
<z:row ows_LinkFilename='Finance' ......................................................................... etc


Output Generated

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<rs:data ItemCount="0">
</rs:data>
</listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>

The expected value for ItemCount is 4 for list1 and list3. We couldn't find any solution for getting different output with same code....
Please help me for this issue ......
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic