Search in sources :

Example 1 with HttpGet

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

the class PTestClient method downloadTestResults.

private void downloadTestResults(String testHandle, String testOutputDir) throws Exception {
    HttpGet request = new HttpGet(mLogsEndpoint + testHandle + "/test-results.tar.gz");
    FileOutputStream output = null;
    try {
        HttpResponse httpResponse = mHttpClient.execute(request);
        StatusLine statusLine = httpResponse.getStatusLine();
        if (statusLine.getStatusCode() != 200) {
            throw new RuntimeException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
        }
        output = new FileOutputStream(new File(testOutputDir, "test-results.tar.gz"));
        IOUtils.copyLarge(httpResponse.getEntity().getContent(), output);
        output.flush();
    } finally {
        request.abort();
        if (output != null) {
            output.close();
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) HttpGet(org.apache.http.client.methods.HttpGet) FileOutputStream(java.io.FileOutputStream) HttpResponse(org.apache.http.HttpResponse) File(java.io.File)

Example 2 with HttpGet

use of org.apache.http.client.methods.HttpGet in project PlayerHater by chrisrhoden.

the class PlaylistParser method parsePls.

private static Uri[] parsePls(Uri uri) {
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(uri.toString()));
        HttpEntity entity = response.getEntity();
        InputStream inputStream = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String header = reader.readLine();
        if (header.trim().equalsIgnoreCase("[playlist]")) {
            String line;
            ArrayList<Uri> uriList = new ArrayList<Uri>();
            do {
                line = reader.readLine();
                if (line != null) {
                    if (line.startsWith("File")) {
                        String fileName = line.substring(line.indexOf("=") + 1).trim();
                        uriList.add(Uri.parse(fileName));
                    }
                }
            } while (line != null);
            if (uriList.size() > 0) {
                Uri[] res = new Uri[uriList.size()];
                return uriList.toArray(res);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new Uri[] { uri };
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) Uri(android.net.Uri) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BufferedReader(java.io.BufferedReader)

Example 3 with HttpGet

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

the class WelcomeController method checkForUpdates.

private void checkForUpdates() {
    checkForUpdatesStatus.setText(localization.getString("welcome.checkForUpdates.label.currentlyChecking"));
    checkForUpdatesIndicator.setVisible(true);
    asyncTaskService.asyncTaskOf(() -> {
        RequestConfig requestConfig = //
        RequestConfig.custom().setConnectTimeout(//
        5000).setConnectionRequestTimeout(//
        5000).setSocketTimeout(//
        5000).build();
        HttpClientBuilder httpClientBuilder = //
        HttpClients.custom().disableCookieManagement().setDefaultRequestConfig(//
        requestConfig).setUserAgent("Cryptomator VersionChecker/" + ApplicationVersion.orElse("SNAPSHOT"));
        LOG.debug("Checking for updates...");
        try (CloseableHttpClient client = httpClientBuilder.build()) {
            HttpGet request = new HttpGet("https://cryptomator.org/downloads/latestVersion.json");
            try (CloseableHttpResponse response = client.execute(request)) {
                if (response.getStatusLine().getStatusCode() == 200 && response.getEntity() != null) {
                    try (InputStream in = response.getEntity().getContent()) {
                        Gson gson = new GsonBuilder().setLenient().create();
                        Reader utf8Reader = new InputStreamReader(in, StandardCharsets.UTF_8);
                        Map<String, String> map = gson.fromJson(utf8Reader, new TypeToken<Map<String, String>>() {
                        }.getType());
                        if (map != null) {
                            this.compareVersions(map);
                        }
                    }
                }
            }
        }
    }).andFinally(() -> {
        checkForUpdatesStatus.setText("");
        checkForUpdatesIndicator.setVisible(false);
    }).run();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Gson(com.google.gson.Gson) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) TypeToken(com.google.gson.reflect.TypeToken) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 4 with HttpGet

use of org.apache.http.client.methods.HttpGet in project elasticsearch-analysis-ik by medcl.

the class Dictionary method getRemoteWords.

/**
	 * 从远程服务器上下载自定义词条
	 */
private static List<String> getRemoteWords(String location) {
    List<String> buffer = new ArrayList<String>();
    RequestConfig rc = RequestConfig.custom().setConnectionRequestTimeout(10 * 1000).setConnectTimeout(10 * 1000).setSocketTimeout(60 * 1000).build();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    CloseableHttpResponse response;
    BufferedReader in;
    HttpGet get = new HttpGet(location);
    get.setConfig(rc);
    try {
        response = httpclient.execute(get);
        if (response.getStatusLine().getStatusCode() == 200) {
            String charset = "UTF-8";
            // 获取编码,默认为utf-8
            if (response.getEntity().getContentType().getValue().contains("charset=")) {
                String contentType = response.getEntity().getContentType().getValue();
                charset = contentType.substring(contentType.lastIndexOf("=") + 1);
            }
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset));
            String line;
            while ((line = in.readLine()) != null) {
                buffer.add(line);
            }
            in.close();
            response.close();
            return buffer;
        }
        response.close();
    } catch (ClientProtocolException e) {
        logger.error("getRemoteWords {} error", e, location);
    } catch (IllegalStateException e) {
        logger.error("getRemoteWords {} error", e, location);
    } catch (IOException e) {
        logger.error("getRemoteWords {} error", e, location);
    }
    return buffer;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStreamReader(java.io.InputStreamReader) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 5 with HttpGet

use of org.apache.http.client.methods.HttpGet in project rainbow by juankysoriano.

the class RainbowIO method createInputRaw.

/**
     * Call createInput() without automatic gzip decompression.
     */
public static InputStream createInputRaw(Context context, final String filename) {
    InputStream stream = null;
    if (filename == null) {
        return null;
    }
    if (filename.length() == 0) {
        return null;
    }
    if (filename.indexOf(":") != -1) {
        // at least smells like URL
        try {
            HttpGet httpRequest = null;
            httpRequest = new HttpGet(URI.create(filename));
            final HttpClient httpclient = new DefaultHttpClient();
            final HttpResponse response = httpclient.execute(httpRequest);
            final HttpEntity entity = response.getEntity();
            return entity.getContent();
        } catch (final MalformedURLException mfue) {
        } catch (final FileNotFoundException fnfe) {
        } catch (final IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    // Try the assets folder
    final AssetManager assets = context.getAssets();
    try {
        stream = assets.open(filename);
        if (stream != null) {
            return stream;
        }
    } catch (final IOException e) {
    }
    // Maybe this is an absolute path, didja ever think of that?
    final File absFile = new File(filename);
    if (absFile.exists()) {
        try {
            stream = new FileInputStream(absFile);
            if (stream != null) {
                return stream;
            }
        } catch (final FileNotFoundException fnfe) {
        // fnfe.printStackTrace();
        }
    }
    // Maybe this is a file that was written by the sketch later.
    final File sketchFile = new File(sketchPath(context, filename));
    if (sketchFile.exists()) {
        try {
            stream = new FileInputStream(sketchFile);
            if (stream != null) {
                return stream;
            }
        } catch (final FileNotFoundException fnfe) {
        }
    }
    // Attempt to load the file more directly. Doesn't like paths.
    try {
        stream = context.openFileInput(filename);
        if (stream != null) {
            return stream;
        }
    } catch (final FileNotFoundException e) {
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) AssetManager(android.content.res.AssetManager) HttpEntity(org.apache.http.HttpEntity) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FileNotFoundException(java.io.FileNotFoundException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) File(java.io.File) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) FileInputStream(java.io.FileInputStream)

Aggregations

HttpGet (org.apache.http.client.methods.HttpGet)2944 HttpResponse (org.apache.http.HttpResponse)1804 Test (org.junit.Test)1369 IOException (java.io.IOException)635 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)600 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)585 URI (java.net.URI)580 HttpClient (org.apache.http.client.HttpClient)429 HttpEntity (org.apache.http.HttpEntity)376 TestHttpClient (io.undertow.testutils.TestHttpClient)340 InputStream (java.io.InputStream)315 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)263 Header (org.apache.http.Header)253 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)170 HttpPost (org.apache.http.client.methods.HttpPost)148 ArrayList (java.util.ArrayList)131 URISyntaxException (java.net.URISyntaxException)105 Identity (org.olat.core.id.Identity)102 URL (java.net.URL)99 ByteArrayInputStream (java.io.ByteArrayInputStream)94