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;
}
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();
}
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;
}
}
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());
}
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());
}
Aggregations