use of org.apache.http.client.entity.GzipCompressingEntity in project android by JetBrains.
the class GoogleCrash method submit.
@NotNull
@Override
public CompletableFuture<String> submit(@NotNull final HttpEntity requestEntity) {
CompletableFuture<String> future = new CompletableFuture<>();
try {
ourExecutor.submit(() -> {
try {
HttpClient client = HttpClients.createDefault();
HttpEntity entity = requestEntity;
if (!UNIT_TEST_MODE) {
// The test server used in testing doesn't handle gzip compression (netty requires jcraft jzlib for gzip decompression)
entity = new GzipCompressingEntity(requestEntity);
}
HttpPost post = new HttpPost(myCrashUrl);
post.setEntity(entity);
HttpResponse response = client.execute(post);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() >= 300) {
future.completeExceptionally(new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()));
return;
}
entity = response.getEntity();
if (entity == null) {
future.completeExceptionally(new NullPointerException("Empty response entity"));
return;
}
String reportId = EntityUtils.toString(entity);
if (DEBUG_BUILD) {
//noinspection UseOfSystemOutOrSystemErr
System.out.println("Report submitted: http://go/crash-staging/" + reportId);
}
future.complete(reportId);
} catch (IOException e) {
future.completeExceptionally(e);
}
});
} catch (RejectedExecutionException ignore) {
// handled by the rejected execution handler associated with ourExecutor
}
return future;
}
use of org.apache.http.client.entity.GzipCompressingEntity in project android by JetBrains.
the class GoogleCrash method createPost.
@NotNull
private HttpUriRequest createPost(@NotNull FlightRecorder flightRecorder, @NotNull String issueText, @NotNull List<Path> logFiles) {
HttpPost post = new HttpPost(myCrashUrl);
ApplicationInfo applicationInfo = getApplicationInfo();
String strictVersion = applicationInfo == null ? "0.0.0.0" : applicationInfo.getStrictVersion();
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
// key names recognized by crash
builder.addTextBody(KEY_PRODUCT_ID, "AndroidStudio");
builder.addTextBody(KEY_VERSION, strictVersion);
builder.addTextBody("exception_info", getUniqueStackTrace());
builder.addTextBody("user_report", issueText);
if (ANONYMIZED_UID != null) {
builder.addTextBody("guid", ANONYMIZED_UID);
}
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
builder.addTextBody("ptime", Long.toString(runtimeMXBean.getUptime()));
// product specific key value pairs
builder.addTextBody("fullVersion", applicationInfo == null ? "0.0.0.0" : applicationInfo.getFullVersion());
builder.addTextBody("osName", StringUtil.notNullize(SystemInfo.OS_NAME));
builder.addTextBody("osVersion", StringUtil.notNullize(SystemInfo.OS_VERSION));
builder.addTextBody("osArch", StringUtil.notNullize(SystemInfo.OS_ARCH));
builder.addTextBody("locale", StringUtil.notNullize(LOCALE));
builder.addTextBody("vmName", StringUtil.notNullize(runtimeMXBean.getVmName()));
builder.addTextBody("vmVendor", StringUtil.notNullize(runtimeMXBean.getVmVendor()));
builder.addTextBody("vmVersion", StringUtil.notNullize(runtimeMXBean.getVmVersion()));
MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
builder.addTextBody("heapUsed", Long.toString(usage.getUsed()));
builder.addTextBody("heapCommitted", Long.toString(usage.getCommitted()));
builder.addTextBody("heapMax", Long.toString(usage.getMax()));
// add report specific data
builder.addTextBody("Type", "InstantRunFlightRecorder");
addFlightRecorderLogs(builder, flightRecorder, logFiles);
post.setEntity(new GzipCompressingEntity(builder.build()));
return post;
}
use of org.apache.http.client.entity.GzipCompressingEntity in project beam by apache.
the class InfluxDBPublisher method publishNexmark.
private static void publishNexmark(final Collection<Map<String, Object>> results, final InfluxDBSettings settings, final Map<String, String> tags) throws Exception {
final HttpClientBuilder builder = provideHttpBuilder(settings);
final HttpPost postRequest = providePOSTRequest(settings);
final StringBuilder metricBuilder = new StringBuilder();
results.forEach(map -> {
metricBuilder.append(map.get("measurement")).append(",").append(getKV(map, "runner"));
if (tags != null && !tags.isEmpty()) {
tags.entrySet().stream().forEach(entry -> {
metricBuilder.append(",").append(entry.getKey()).append("=").append(entry.getValue());
});
}
metricBuilder.append(" ").append(getKV(map, "runtimeMs")).append(",").append(getKV(map, "numResults")).append(" ").append(map.get("timestamp")).append('\n');
});
postRequest.setEntity(new GzipCompressingEntity(new ByteArrayEntity(metricBuilder.toString().getBytes(UTF_8))));
executeWithVerification(postRequest, builder);
}
Aggregations