Search in sources :

Example 76 with HttpGet

use of org.apache.http.client.methods.HttpGet in project FastDev4Android by jiangqqlmj.

the class IoUtils method getInputStream.

/**
     * 获取url的InputStream
     *
     * @param urlStr
     * @return
     */
public static InputStream getInputStream(String urlStr) {
    Log.d(TAG_LISTLOGIC, "get http input:" + urlStr);
    InputStream inpStream = null;
    try {
        HttpGet http = new HttpGet(urlStr);
        HttpClient client = new DefaultHttpClient();
        HttpResponse response = (HttpResponse) client.execute(http);
        HttpEntity httpEntity = response.getEntity();
        BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(httpEntity);
        // 获取数据流
        inpStream = bufferedHttpEntity.getContent();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (inpStream != null) {
            try {
                inpStream.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
    return inpStream;
}
Also used : HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) DataInputStream(java.io.DataInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 77 with HttpGet

use of org.apache.http.client.methods.HttpGet in project Talon-for-Twitter by klinker24.

the class VideoFragment method getDoc.

public Document getDoc() {
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet((tweetUrl.contains("http") ? "" : "https://") + tweetUrl);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) sb.append(line + "\n");
        String docHtml = sb.toString();
        is.close();
        return Jsoup.parse(docHtml);
    } catch (Exception e) {
        return null;
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 78 with HttpGet

use of org.apache.http.client.methods.HttpGet in project pinot by linkedin.

the class BackfillControllerAPIs method getAllSegments.

/**
   * Fetches the list of all segment names for a table
   * @param tableName
   * @return
   * @throws IOException
   */
public List<String> getAllSegments(String tableName) throws IOException {
    List<String> allSegments = new ArrayList<>();
    HttpClient controllerClient = new DefaultHttpClient();
    HttpGet req = new HttpGet(SEGMENTS_ENDPOINT + URLEncoder.encode(tableName, UTF_8));
    HttpResponse res = controllerClient.execute(controllerHttpHost, req);
    try {
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new IllegalStateException(res.getStatusLine().toString());
        }
        InputStream content = res.getEntity().getContent();
        String response = IOUtils.toString(content);
        List<String> allSegmentsPaths = getSegmentsFromResponse(response);
        for (String segment : allSegmentsPaths) {
            allSegments.add(segment.substring(segment.lastIndexOf("/") + 1));
        }
        LOGGER.info("All segments : {}", allSegments);
    } finally {
        if (res.getEntity() != null) {
            EntityUtils.consume(res.getEntity());
        }
    }
    return allSegments;
}
Also used : InputStream(java.io.InputStream) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 79 with HttpGet

use of org.apache.http.client.methods.HttpGet in project pinot by linkedin.

the class BackfillControllerAPIs method getSegmentMetadata.

/**
   * Returns the metadata of a segment, given the segment name and table name
   * @param tableName - table where segment resides
   * @param segmentName - name of the segment
   * @return
   * @throws IOException
   */
public Map<String, String> getSegmentMetadata(String tableName, String segmentName) throws IOException {
    Map<String, String> metadata = null;
    HttpClient controllerClient = new DefaultHttpClient();
    HttpGet req = new HttpGet(TABLES_ENDPOINT + URLEncoder.encode(tableName, UTF_8) + "/" + SEGMENTS_ENDPOINT + URLEncoder.encode(segmentName, UTF_8) + "/" + METADATA_ENDPOINT);
    HttpResponse res = controllerClient.execute(controllerHttpHost, req);
    try {
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new IllegalStateException(res.getStatusLine().toString());
        }
        InputStream content = res.getEntity().getContent();
        String metadataResponse = IOUtils.toString(content);
        metadata = getMetadataFromResponse(metadataResponse);
    } finally {
        if (res.getEntity() != null) {
            EntityUtils.consume(res.getEntity());
        }
    }
    return metadata;
}
Also used : InputStream(java.io.InputStream) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 80 with HttpGet

use of org.apache.http.client.methods.HttpGet in project pinot by linkedin.

the class SegmentPushControllerAPIs method deleteSegment.

private boolean deleteSegment(String tablename, String segmentName) throws IOException {
    boolean deleteSuccessful = false;
    HttpClient controllerClient = new DefaultHttpClient();
    HttpGet req = new HttpGet(TABLES_ENDPOINT + URLEncoder.encode(tablename, UTF_8) + "/" + SEGMENTS_ENDPOINT + URLEncoder.encode(segmentName, UTF_8) + DROP_PARAMETERS);
    HttpResponse res = controllerClient.execute(controllerHttpHost, req);
    try {
        if (res == null || res.getStatusLine() == null || res.getStatusLine().getStatusCode() != 200 || !isDeleteSuccessful(tablename, segmentName)) {
            LOGGER.info("Exception in deleting segment, trying again {}", res);
        } else {
            deleteSuccessful = true;
        }
    } finally {
        if (res.getEntity() != null) {
            EntityUtils.consume(res.getEntity());
        }
    }
    return deleteSuccessful;
}
Also used : DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

HttpGet (org.apache.http.client.methods.HttpGet)1143 HttpResponse (org.apache.http.HttpResponse)717 Test (org.junit.Test)504 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)242 TestHttpClient (io.undertow.testutils.TestHttpClient)239 IOException (java.io.IOException)200 HttpClient (org.apache.http.client.HttpClient)185 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)179 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)176 HttpEntity (org.apache.http.HttpEntity)152 Header (org.apache.http.Header)133 InputStream (java.io.InputStream)103 URI (java.net.URI)83 JsonNode (com.fasterxml.jackson.databind.JsonNode)68 ArrayList (java.util.ArrayList)60 MockResponse (com.google.mockwebserver.MockResponse)54 HttpPost (org.apache.http.client.methods.HttpPost)54 Deployment (org.activiti.engine.test.Deployment)49 ClientProtocolException (org.apache.http.client.ClientProtocolException)46 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)45