use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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();
}
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project hive by apache.
the class PTestClient method post.
private <S extends GenericResponse> S post(Object payload, boolean agressiveRetry) throws Exception {
EndPointResponsePair endPointResponse = Preconditions.checkNotNull(REQUEST_TO_ENDPOINT.get(payload.getClass()), payload.getClass().getName());
HttpPost request = new HttpPost(mApiEndPoint + endPointResponse.getEndpoint());
try {
String payloadString = mMapper.writeValueAsString(payload);
StringEntity params = new StringEntity(payloadString);
request.addHeader("content-type", "application/json");
request.setEntity(params);
if (agressiveRetry) {
mHttpClient.setHttpRequestRetryHandler(new PTestHttpRequestRetryHandler());
}
HttpResponse httpResponse = mHttpClient.execute(request);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() != 200) {
throw new IllegalStateException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
}
String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
@SuppressWarnings("unchecked") S result = (S) endPointResponse.getResponseClass().cast(mMapper.readValue(response, endPointResponse.getResponseClass()));
Status.assertOK(result.getStatus());
if (System.getProperty("DEBUG_PTEST_CLIENT") != null) {
System.err.println("payload " + payloadString);
if (result instanceof TestLogResponse) {
System.err.println("response " + ((TestLogResponse) result).getOffset() + " " + ((TestLogResponse) result).getStatus());
} else {
System.err.println("response " + response);
}
}
Thread.sleep(1000);
return result;
} finally {
request.abort();
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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 };
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project Android by hmkcode.
the class MainActivity method POST.
public static String POST(String url, Person person) {
InputStream inputStream = null;
String result = "";
try {
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(url);
String json = "";
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", person.getName());
jsonObject.accumulate("country", person.getCountry());
jsonObject.accumulate("twitter", person.getTwitter());
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
// ** Alternative way to convert Person object to JSON string usin Jackson Lib
// ObjectMapper mapper = new ObjectMapper();
// json = mapper.writeValueAsString(person);
// 5. set json to StringEntity
StringEntity se = new StringEntity(json);
// 6. set httpPost Entity
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// 10. convert inputstream to string
if (inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
// 11. return result
return result;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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;
}
Aggregations