Search in sources :

Example 31 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project screenbird by adamhub.

the class FileUtil method postData.

public static String[] postData(String data, final JProgressBar pbUpload, String anonymous_token, String csrf_token, String user_id, ProgressBarUploadProgressListener listener, String upload_url) throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost(upload_url);
    //File file = new File(fileLocation);
    //MultipartEntity mpEntity = new MultipartEntity();
    ProgressMultiPartEntity mpEntity = new ProgressMultiPartEntity(listener);
    //ContentBody cbFile = new FileBody(file, "video/quicktime");
    //mpEntity.addPart("videoupload", cbFile);
    //ContentBody cbToken = new StringBody(title);
    //mpEntity.addPart("csrfmiddlewaretoken", cbToken);
    ContentBody cbUser_id = new StringBody(user_id);
    mpEntity.addPart("user_id", cbUser_id);
    ContentBody cbAnonym_id = new StringBody(MediaUtil.getMacAddress());
    mpEntity.addPart("anonym_id", cbAnonym_id);
    //ContentBody cbTitle = new StringBody(title);
    //mpEntity.addPart("title", cbTitle);
    //        ContentBody cbSlug = new StringBody(slug);
    //        mpEntity.addPart("slug", cbSlug);
    //        ContentBody cbPublic = new StringBody(is_public ? "1" : "0");
    //        mpEntity.addPart("is_public", cbPublic);
    //        ContentBody cbDescription = new StringBody(description);
    //        mpEntity.addPart("description", cbDescription);
    //        ContentBody cbChecksum = new StringBody(checksum);
    //        mpEntity.addPart("checksum", cbChecksum);
    //        ContentBody cbType = new StringBody(video_type);
    //        mpEntity.addPart("video_type", cbType);
    httppost.setEntity(mpEntity);
    System.out.println("===================================================");
    System.out.println("executing request " + httppost.getRequestLine());
    System.out.println("===================================================");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    String[] result = new String[2];
    String status = response.getStatusLine().toString();
    result[0] = (status.indexOf("200") >= 0) ? "200" : status;
    System.out.println("===================================================");
    System.out.println("status from request " + result[0]);
    System.out.println("===================================================");
    if (resEntity != null) {
        result[1] = EntityUtils.toString(resEntity);
        EntityUtils.consume(resEntity);
    }
    httpclient.getConnectionManager().shutdown();
    return result;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ContentBody(org.apache.http.entity.mime.content.ContentBody) HttpEntity(org.apache.http.HttpEntity) StringBody(org.apache.http.entity.mime.content.StringBody) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ProgressMultiPartEntity(com.bixly.pastevid.util.view.ProgressMultiPartEntity) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 32 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project OpenAttestation by OpenAttestation.

the class SslUtil method getServerCertificates.

public static X509Certificate[] getServerCertificates(URL url) throws NoSuchAlgorithmException, KeyManagementException, IOException {
    if (!"https".equals(url.getProtocol())) {
        throw new IllegalArgumentException("URL scheme must be https");
    }
    int port = url.getPort();
    if (port == -1) {
        port = 443;
    }
    X509HostnameVerifier hostnameVerifier = new NopX509HostnameVerifierApache();
    CertificateStoringX509TrustManager trustManager = new CertificateStoringX509TrustManager();
    SSLContext sslcontext = SSLContext.getInstance("TLS");
    sslcontext.init(null, new X509TrustManager[] { trustManager }, null);
    SSLSocketFactory sf = new SSLSocketFactory(sslcontext, hostnameVerifier);
    Scheme https = new Scheme("https", port, sf);
    SchemeRegistry sr = new SchemeRegistry();
    sr.register(https);
    BasicClientConnectionManager connectionManager = new BasicClientConnectionManager(sr);
    HttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
    HttpClient httpClient = new DefaultHttpClient(connectionManager, httpParams);
    log.debug("Saving certificates from server URL: {}", url.toExternalForm());
    HttpHead request = new HttpHead(url.toExternalForm());
    HttpResponse response = httpClient.execute(request);
    log.debug("Server status line: {} {} ({})", new String[] { response.getProtocolVersion().getProtocol(), response.getStatusLine().getReasonPhrase(), String.valueOf(response.getStatusLine().getStatusCode()) });
    httpClient.getConnectionManager().shutdown();
    return trustManager.getStoredCertificates();
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) HttpResponse(org.apache.http.HttpResponse) SSLContext(javax.net.ssl.SSLContext) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpHead(org.apache.http.client.methods.HttpHead) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) X509HostnameVerifier(org.apache.http.conn.ssl.X509HostnameVerifier) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicClientConnectionManager(org.apache.http.impl.conn.BasicClientConnectionManager) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) BasicHttpParams(org.apache.http.params.BasicHttpParams)

Example 33 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android_frameworks_base by ParanoidAndroid.

the class FsUtils method getLayoutTestsDirContents.

public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse, boolean mode) {
    String modeString = (mode ? "folders" : "files");
    URL url = null;
    try {
        url = new URL(SCRIPT_URL + "?path=" + dirRelativePath + "&recurse=" + recurse + "&mode=" + modeString);
    } catch (MalformedURLException e) {
        Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" + modeString, e);
        return new LinkedList<String>();
    }
    HttpGet httpRequest = new HttpGet(url.toString());
    ResponseHandler<LinkedList<String>> handler = new ResponseHandler<LinkedList<String>>() {

        @Override
        public LinkedList<String> handleResponse(HttpResponse response) throws IOException {
            LinkedList<String> lines = new LinkedList<String>();
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                return lines;
            }
            HttpEntity entity = response.getEntity();
            if (entity == null) {
                return lines;
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    lines.add(line);
                }
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
            return lines;
        }
    };
    try {
        return getHttpClient().execute(httpRequest, handler);
    } catch (IOException e) {
        Log.e(LOG_TAG, "getLayoutTestsDirContents(): HTTP GET failed for URL " + url);
        return null;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ResponseHandler(org.apache.http.client.ResponseHandler) HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) URL(java.net.URL) LinkedList(java.util.LinkedList) BufferedReader(java.io.BufferedReader)

Example 34 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android_frameworks_base by ParanoidAndroid.

the class AbstractProxyTest method testExplicitNoProxyCancelsSystemProperty.

public void testExplicitNoProxyCancelsSystemProperty() throws Exception {
    server.enqueue(new MockResponse().setBody("Via the origin server!"));
    server.play();
    System.setProperty("http.proxyHost", "proxy.foo");
    System.setProperty("http.proxyPort", "8080");
    HttpClient client = newHttpClient();
    HttpGet request = new HttpGet(server.getUrl("/bar").toURI());
    request.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, ConnRouteParams.NO_HOST);
    HttpResponse response = client.execute(request);
    assertEquals("Via the origin server!", contentToString(response));
    RecordedRequest recordedRequest = server.takeRequest();
    assertEquals("GET /bar HTTP/1.1", recordedRequest.getRequestLine());
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

Example 35 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android_frameworks_base by ParanoidAndroid.

the class AbstractProxyTest method testConnectToHttps.

public void testConnectToHttps() throws Exception {
    TestSSLContext testSSLContext = TestSSLContext.create();
    server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
    server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
    server.play();
    HttpClient httpClient = newHttpClient();
    SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
    sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
    httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
    HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
    assertEquals("this response comes via HTTPS", contentToString(response));
    RecordedRequest request = server.takeRequest();
    assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestSSLContext(libcore.javax.net.ssl.TestSSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Aggregations

HttpResponse (org.apache.http.HttpResponse)4366 Test (org.junit.Test)2158 HttpGet (org.apache.http.client.methods.HttpGet)1833 IOException (java.io.IOException)1110 URI (java.net.URI)834 HttpPost (org.apache.http.client.methods.HttpPost)759 HttpClient (org.apache.http.client.HttpClient)600 HttpEntity (org.apache.http.HttpEntity)541 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)398 Header (org.apache.http.Header)385 StringEntity (org.apache.http.entity.StringEntity)363 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)338 HttpPut (org.apache.http.client.methods.HttpPut)320 ArrayList (java.util.ArrayList)316 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)253 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)209 File (java.io.File)196