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