List of usage examples for org.apache.http.client.methods HttpGet HttpGet
public HttpGet(final String uri)
From source file:org.corfudb.sharedlog.examples.ConfigClnt.java
public static void main(String[] args) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); final BufferedReader prompt = new BufferedReader(new InputStreamReader(System.in)); CorfuConfiguration C = null;// w w w . java 2 s .c o m while (true) { System.out.print("> "); String line = prompt.readLine(); if (line.startsWith("get")) { HttpGet httpget = new HttpGet("http://localhost:8000/corfu"); System.out.println("Executing request: " + httpget.getRequestLine()); HttpResponse response = (HttpResponse) httpclient.execute(httpget); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); // response.getEntity().writeTo(System.out); // System.out.println(); // System.out.println("----------------------------------------"); C = new CorfuConfiguration(response.getEntity().getContent()); } else { if (C == null) { System.out.println("configuration not set yet!"); continue; } HttpPost httppost = new HttpPost("http://localhost:8000/corfu"); httppost.setEntity(new StringEntity(C.ConfToXMLString())); System.out.println("Executing request: " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); response.getEntity().writeTo(System.out); } } // httpclient.close(); }
From source file:org.openiot.gsn.http.rest.RemoteWrapperHttpClient.java
public static void main(String[] args) throws ClientProtocolException, IOException, ClassNotFoundException { DefaultHttpClient httpclient = new DefaultHttpClient(); final String url = "select * from localsystemtime where timed > 10/10"; HttpGet httpget = new HttpGet( "http://localhost:22001/streaming/" + URLEncoder.encode(url, "UTF-8") + "/12345"); HttpResponse response = httpclient.execute(httpget); ObjectInputStream out = (StreamElement4Rest.getXstream()) .createObjectInputStream((response.getEntity().getContent())); DataField[] structure = (DataField[]) out.readObject(); StreamElement4Rest se = null;/* www. j a va 2s .co m*/ try { while ((se = (StreamElement4Rest) out.readObject()) != null) { System.out.println(se.toStreamElement()); } } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:test1.ApacheHttpRestClient2.java
public final static void main(String[] args) { HttpClient httpClient = new DefaultHttpClient(); try {//w ww .jav a 2 s . com // this ona api call returns results in a JSON format HttpGet httpGetRequest = new HttpGet("https://api.ona.io/api/v1/users"); // Execute HTTP request HttpResponse httpResponse = httpClient.execute(httpGetRequest); System.out.println("------------------HTTP RESPONSE----------------------"); System.out.println(httpResponse.getStatusLine()); System.out.println("------------------HTTP RESPONSE----------------------"); // Get hold of the response entity HttpEntity entity = httpResponse.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release byte[] buffer = new byte[1024]; if (entity != null) { InputStream inputStream = entity.getContent(); try { int bytesRead = 0; BufferedInputStream bis = new BufferedInputStream(inputStream); while ((bytesRead = bis.read(buffer)) != -1) { String chunk = new String(buffer, 0, bytesRead); FileWriter file = new FileWriter("C:\\Users\\fred\\Desktop\\webicons\\output.txt"); //file.write(chunk.toJSONString()); file.write(chunk.toCharArray()); file.flush(); file.close(); System.out.print(chunk); System.out.println(chunk); } } catch (IOException ioException) { // In case of an IOException the connection will be released // back to the connection manager automatically ioException.printStackTrace(); } catch (RuntimeException runtimeException) { // In case of an unexpected exception you may want to abort // the HTTP request in order to shut down the underlying // connection immediately. httpGetRequest.abort(); runtimeException.printStackTrace(); } // try { // FileWriter file = new FileWriter("C:\\Users\\fred\\Desktop\\webicons\\output.json"); // file.write(bis.toJSONString()); // file.flush(); // file.close(); // // System.out.print(bis); // } catch (Exception e) { // } finally { // Closing the input stream will trigger connection release try { inputStream.close(); } catch (Exception ignore) { } } } } catch (ClientProtocolException e) { // thrown by httpClient.execute(httpGetRequest) e.printStackTrace(); } catch (IOException e) { // thrown by entity.getContent(); e.printStackTrace(); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpClient.getConnectionManager().shutdown(); } }
From source file:com.ny.apps.executor.httpclient.HttpRequestSender.java
public static void main(String[] args) throws ClientProtocolException, IOException { /*// ww w. j a v a 2 s . c o m CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("localhost", 80), new UsernamePasswordCredentials("root", "123")); CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); */ CloseableHttpClient client = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://www.baidu.com/"); httpGet.setHeader("Authorization", ""); logger.info("executing request " + httpGet.getURI()); ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { // TODO ? int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); return entity == null ? null : EntityUtils.toString(entity); } else { throw new ClientProtocolException("Unexpected response status: " + statusCode); } } }; try { String responseBody = client.execute(httpGet, responseHandler); System.out.println("----------------------------------------"); System.out.println(responseBody); System.out.println("----------------------------------------"); } finally { client.close(); } }
From source file:downloadwolkflow.getWorkFlowList.java
public static void main(String args[]) { CloseableHttpClient httpclient = HttpClients.createDefault(); String[] pageList = getPageList(); System.out.println(pageList.length); for (int i = 1; i < pageList.length; i++) { System.out.println(pageList[i]); System.out.println("---------------------------------------------------------------------------"); HttpGet httpget = new HttpGet(pageList[i]); try {//from w w w.j a v a 2 s . c o m HttpResponse response = httpclient.execute(httpget); String page = EntityUtils.toString(response.getEntity()); Document mainDoc = Jsoup.parse(page); Elements resultList = mainDoc.select("div.resource_list_item"); for (int j = 0; j < resultList.size(); j++) { Element workflowResult = resultList.get(j); Element detailInfo = workflowResult.select("div.main_panel").first().select("p.title.inline") .first().select("a").first(); String detailUrl = "http://www.myexperiment.org" + detailInfo.attributes().get("href") + ".html"; System.out.println(detailUrl); downloadWorkFlow(detailUrl, httpclient); Thread.sleep(1000); } } catch (IOException ex) { Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex); } } try { httpclient.close(); } catch (IOException ex) { Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:web.restful.ClientTest.java
public static void main(String[] args) throws ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/session"); put.setEntity(new StringEntity("upenkwbq"));// session ID client.execute(put);/*from w w w . j a v a 2 s .com*/ put.releaseConnection(); put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/bucket"); put.setEntity(new StringEntity("Level1/Level1_Bin_1.txt")); // bucket name client.execute(put); put.releaseConnection(); put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/method"); put.setEntity(new StringEntity("chauvenet")); // method name client.execute(put); put.releaseConnection(); HttpGet get = new HttpGet("http://localhost:8080/ss16-lab-web/resources/outliers"); HttpResponse response = client.execute(get); HttpEntity en = response.getEntity(); InputStreamReader i = new InputStreamReader(en.getContent()); BufferedReader rd = new BufferedReader(i); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } }
From source file:no.uib.tools.OnthologyHttpClient.java
public static void main(String[] args) { try {// ww w. j av a 2s .c o m CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet getRequest = new HttpGet( "http://www.ebi.ac.uk/ols/api/ontologies/mod/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMOD_00861/descendants?size=2002"); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed to get the PSIMOD onthology : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; FileWriter fw = new FileWriter("./mod.json"); System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); fw.write(output); } fw.close(); httpClient.close(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.cloudhopper.httpclient.util.HttpsGetMain.java
static public void main(String[] args) throws Exception { ////from w w w . j a v a 2 s . c om // target urls // String strURL = "https://localhost:9443/"; DefaultHttpClient client = new DefaultHttpClient(); // setup this client to not verify SSL certificates HttpClientFactory.configureWithNoSslCertificateVerification(client); // add pre-emptive authentication HttpClientFactory.configureWithPreemptiveBasicAuth(client, "user0", "pass0"); HttpGet get = new HttpGet(strURL); HttpResponse httpResponse = client.execute(get); HttpEntity responseEntity = httpResponse.getEntity(); // // was the request OK? // if (httpResponse.getStatusLine().getStatusCode() != 200) { logger.error("Request failed with StatusCode=" + httpResponse.getStatusLine().getStatusCode()); } // get an input stream String responseBody = EntityUtils.toString(responseEntity); logger.debug("----------------------------------------"); logger.debug(responseBody); logger.debug("----------------------------------------"); client.getConnectionManager().shutdown(); }
From source file:org.httpclient.lesson02.java
public static void main(String[] args) { HttpClient httpclient = new DefaultHttpClient(); try {/*from w w w.j av a 2 s . c o m*/ HttpGet get = new HttpGet("http://www.google.com"); System.out.println("execute request: " + get.getURI()); //create a response hendler ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(get, responseHandler); System.out.println("===================================="); System.out.println(responseBody); System.out.println("===================================="); } catch (Exception e) { System.out.println(e.getMessage()); } finally { //??? httpclient.getConnectionManager().shutdown(); } }
From source file:org.datacleaner.util.http.CASMonitorHttpClientTest.java
public static void main(String[] args) throws Exception { try (CASMonitorHttpClient client = new CASMonitorHttpClient(new DefaultHttpClient(), "https://localhost:8443/cas", "admin", "admin", "https://localhost:8443/DataCleaner-monitor")) { doRequest(client, new HttpGet("https://localhost:8443/DataCleaner-monitor/repository/DC/ping")); doRequest(client, new HttpGet( "https://localhost:8443/DataCleaner-monitor/repository/DC/launch-resources/conf.xml?job=Customer+completeness")); client.close();/* w ww. j a v a 2s. c o m*/ } try (CASMonitorHttpClient client = new CASMonitorHttpClient(new DefaultHttpClient(), "https://localhost:8443/cas", "admin", "admin", "https://localhost:8443/DataCleaner-monitor")) { doRequest(client, new HttpGet( "https://localhost:8443/DataCleaner-monitor/repository/DC/jobs/Customer+completeness.analysis.xml")); } }