Example usage for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider

List of usage examples for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider.

Prototype

public synchronized final CredentialsProvider getCredentialsProvider() 

Source Link

Usage

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void deleteDB(String dbName) {
    try {//from w  w w.j  av  a 2 s.  c  o  m
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));

        HttpDelete delete = new HttpDelete("http://localhost:8002/manage/v2/databases/" + dbName);
        client.execute(delete);

    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void clearDB(int port) {
    try {//from w  ww  . j  a  v  a2  s  .  c o m
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", port),
                new UsernamePasswordCredentials("admin", "admin"));
        String uri = "http://localhost:" + port + "/v1/search/";
        HttpDelete delete = new HttpDelete(uri);
        client.execute(delete);

    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void associateRESTServerWithDB(String restServerName, String dbName) throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials("admin", "admin"));
    String body = "{\"content-database\": \"" + dbName + "\",\"group-name\": \"Default\"}";

    HttpPut put = new HttpPut(
            "http://localhost:8002/manage/v2/servers/" + restServerName + "/properties?server-type=http");
    put.addHeader("Content-type", "application/json");
    put.setEntity(new StringEntity(body));

    HttpResponse response2 = client.execute(put);
    HttpEntity respEntity = response2.getEntity();
    if (respEntity != null) {
        String content = EntityUtils.toString(respEntity);
        System.out.println(content);
    }//from w w w. j  a v  a2 s. com
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void setAuthentication(String level, String restServerName)
        throws ClientProtocolException, IOException {
    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials("admin", "admin"));
    String body = "{\"authentication\": \"" + level + "\"}";

    HttpPut put = new HttpPut("http://localhost:8002/manage/v2/servers/" + restServerName
            + "/properties?server-type=http&group-id=Default");
    put.addHeader("Content-type", "application/json");
    put.setEntity(new StringEntity(body));

    HttpResponse response2 = client.execute(put);
    HttpEntity respEntity = response2.getEntity();
    if (respEntity != null) {
        String content = EntityUtils.toString(respEntity);
        System.out.println(content);
    }//from w w w .  ja va 2 s .com
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void associateRESTServerWithDefaultUser(String restServerName, String userName, String authType)
        throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials("admin", "admin"));
    String body = "{ \"default-user\":\"" + userName + "\",\"authentication\": \"" + authType
            + "\",\"group-name\": \"Default\"}";

    HttpPut put = new HttpPut(
            "http://localhost:8002/manage/v2/servers/" + restServerName + "/properties?server-type=http");
    put.addHeader("Content-type", "application/json");
    put.setEntity(new StringEntity(body));

    HttpResponse response2 = client.execute(put);
    HttpEntity respEntity = response2.getEntity();
    if (respEntity != null) {
        String content = EntityUtils.toString(respEntity);
        System.out.println(content);
    }//  w  w  w.  j a v a 2s.c o  m
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void setDefaultUser(String usr, String restServerName)
        throws ClientProtocolException, IOException {

    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials("admin", "admin"));
    String body = "{\"default-user\": \"" + usr + "\"}";

    HttpPut put = new HttpPut("http://localhost:8002/manage/v2/servers/" + restServerName
            + "/properties?server-type=http&group-id=Default");
    put.addHeader("Content-type", "application/json");
    put.setEntity(new StringEntity(body));

    HttpResponse response2 = client.execute(put);
    HttpEntity respEntity = response2.getEntity();
    if (respEntity != null) {
        String content = EntityUtils.toString(respEntity);
        System.out.println(content);
    }/*from   w  w  w. j  a  v a2  s.com*/
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void deleteRESTUser(String usrName) {
    try {//from  ww  w .  j a  v a  2s. co  m
        DefaultHttpClient client = new DefaultHttpClient();

        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));

        HttpDelete delete = new HttpDelete("http://localhost:8002/manage/v2/users/" + usrName);

        HttpResponse response = client.execute(delete);
        if (response.getStatusLine().getStatusCode() == 202) {
            Thread.sleep(3500);
        }
    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }

}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void deleteUserRole(String roleName) {
    try {//w  w w . j av a  2  s  .c  o  m
        DefaultHttpClient client = new DefaultHttpClient();

        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));

        HttpDelete delete = new HttpDelete("http://localhost:8002/manage/v2/roles/" + roleName);

        HttpResponse response = client.execute(delete);
        if (response.getStatusLine().getStatusCode() == 202) {
            Thread.sleep(3500);
        }
    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }

}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void deleteRESTServerWithDB(String restServerName) {
    try {//from  w w w.  ja  v  a2  s .  c  om
        DefaultHttpClient client = new DefaultHttpClient();

        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));

        HttpDelete delete = new HttpDelete(
                "http://localhost:8002/v1/rest-apis/" + restServerName + "?include=content&include=modules");

        HttpResponse response = client.execute(delete);
        if (response.getStatusLine().getStatusCode() == 202) {
            Thread.sleep(9500);
        }
    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void deleteElementRangeIndexTemporalAxis(String dbName, String axisName) throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials("admin", "admin"));

    HttpDelete del = new HttpDelete("http://localhost:8002/manage/v2/databases/" + dbName + "/temporal/axes/"
            + axisName + "?format=json");

    del.addHeader("Content-type", "application/json");
    del.addHeader("accept", "application/json");

    HttpResponse response = client.execute(del);
    HttpEntity respEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() == 400) {
        HttpEntity entity = response.getEntity();
        String responseString = EntityUtils.toString(entity, "UTF-8");
        System.out.println(responseString);
    } else if (respEntity != null) {
        // EntityUtils to get the response content
        String content = EntityUtils.toString(respEntity);
        System.out.println(content);
    } else {//from   w w  w.j av a 2 s .  c  o  m
        System.out.println("Axis: " + axisName + " deleted");
        System.out.println("==============================================================");
    }
}