List of usage examples for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider
public synchronized final CredentialsProvider getCredentialsProvider()
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void loadBug18993() { try {/*from www .j a v a 2 s. com*/ DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8011), new UsernamePasswordCredentials("admin", "admin")); String document = "<foo>a space b</foo>"; String perm = "perm:rest-writer=read&perm:rest-writer=insert&perm:rest-writer=update&perm:rest-writer=execute"; HttpPut put = new HttpPut("http://localhost:8011/v1/documents?uri=/a%20b&" + perm); put.addHeader("Content-type", "application/xml"); put.setEntity(new StringEntity(document)); HttpResponse response = client.execute(put); HttpEntity respEntity = response.getEntity(); if (respEntity != null) { String content = EntityUtils.toString(respEntity); System.out.println(content); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void setPathRangeIndexInDatabase(String dbName, JsonNode jnode) throws IOException { try {/*from ww w.j a v a 2 s . c o m*/ DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPut put = new HttpPut( "http://localhost:8002" + "/manage/v2/databases/" + dbName + "/properties?format=json"); put.addHeader("Content-type", "application/json"); put.setEntity(new StringEntity(jnode.toString())); HttpResponse response = client.execute(put); HttpEntity respEntity = response.getEntity(); if (respEntity != null) { String content = EntityUtils.toString(respEntity); System.out.println(content); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void deleteRESTServer(String restServerName) { try {/*www . ja v 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/v1/rest-apis/" + restServerName + "&include=modules"); HttpResponse response = client.execute(delete); if (response.getStatusLine().getStatusCode() == 202) { Thread.sleep(3500); waitForServerRestart(); } else System.out.println("Server response " + response.getStatusLine().getStatusCode()); } catch (Exception e) { // writing error to Log System.out.println("Inside Deleting Rest server is throwing an error"); e.printStackTrace(); } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void deleteElementRangeIndexTemporalCollection(String dbName, String collectionName) 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/collections?collection=" + collectionName + "&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 ww . j a va 2 s . c o m*/ System.out.println("Collection: " + collectionName + " deleted"); System.out.println("=============================================================="); } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void createForestonHost(String fName, String dbName, String hName) { try {/* w ww . j ava 2 s . co m*/ DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/forests?format=json"); String JSONString = "{\"database\":\"" + dbName + "\",\"forest-name\":\"" + fName + "\",\"host\":\"" + hName + "\"}"; // System.out.println(JSONString); post.addHeader("Content-type", "application/json"); post.setEntity(new StringEntity(JSONString)); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:org.apache.manifoldcf.authorities.authorities.generic.GenericAuthority.java
protected DefaultHttpClient getClient() throws ManifoldCFException { synchronized (this) { if (client != null) { return client; }//from w w w. jav a 2s .co m DefaultHttpClient cl = new DefaultHttpClient(); if (genericLogin != null && !genericLogin.isEmpty()) { try { URL url = new URL(genericEntryPoint); Credentials credentials = new UsernamePasswordCredentials(genericLogin, genericPassword); cl.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), url.getPort() > 0 ? url.getPort() : 80, AuthScope.ANY_REALM), credentials); cl.addRequestInterceptor(new PreemptiveAuth(credentials), 0); } catch (MalformedURLException ex) { client = null; sessionExpirationTime = -1L; throw new ManifoldCFException("getClient exception: " + ex.getMessage(), ex); } } HttpConnectionParams.setConnectionTimeout(cl.getParams(), connectionTimeoutMillis); HttpConnectionParams.setSoTimeout(cl.getParams(), socketTimeoutMillis); sessionExpirationTime = System.currentTimeMillis() + 300000L; client = cl; return cl; } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void createDB(String dbName) { try {//from ww w.j a va2 s .c o m DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/databases?format=json"); String JSONString = "[{\"database-name\":\"" + dbName + "\"}]"; post.addHeader("Content-type", "application/json"); post.setEntity(new StringEntity(JSONString)); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void createForest(String fName, String dbName) { try {/*ww w .j av a2s . co m*/ DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/forests?format=json"); // System.out.println( getBootStrapHostFromML()); String hName = getBootStrapHostFromML(); String JSONString = "{\"database\":\"" + dbName + "\",\"forest-name\":\"" + fName + "\",\"host\":\"" + hName + "\"}"; // System.out.println(JSONString); post.addHeader("Content-type", "application/json"); post.setEntity(new StringEntity(JSONString)); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void createRESTServerWithDB(String restServerName, int restPort) { try {/*from ww w . j a va 2 s . c om*/ DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPost post = new HttpPost("http://localhost:8002" + "/v1/rest-apis?format=json"); // String JSONString = "{ \"rest-api\": {\"name\":\"" + restServerName + "\",\"port\":\"" + restPort + "\"}}"; //System.out.println(JSONString); post.addHeader("Content-type", "application/json"); post.setEntity(new StringEntity(JSONString)); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void detachForest(String dbName, String fName) { try {//from w w w. j a v a 2s . com DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/forests/" + fName); // List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("state", "detach")); urlParameters.add(new BasicNameValuePair("database", dbName)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }