I am making rest api calls to Sharepoint 2013 using Java. How can I connect to the sharepoint 2013 using jersey rest client?
Note: currently I am using apache http c
The following code executes an NTLM authenticated HTTP GET request that using Jersey:
public Response executeRestGet(String user, String pass) {
Client client = ClientBuilder.newClient(prepareClientConfig(user, pass));
WebTarget target = client.target("http://localhost/").path("site/_api/xxxxx");
return target.request(HTTP_ACCEPT_JSON).get();
}
private ClientConfig prepareClientConfig(String user, String pass) {
ClientConfig clientConfig = new ClientConfig();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//make sure to supply all 4 arguments to the NTCredentials constructor
credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(user, pass, null, null));
clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
clientConfig.connectorProvider(new ApacheConnectorProvider());
return clientConfig;
}
Please note that this approach requires: jersey-apache-connector
. Maven Dependency:
org.glassfish.jersey.connectors
jersey-apache-connector
2.22.2