Search in sources :

Example 1 with GzipCompressingEntity

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GzipCompressingEntity(org.apache.http.client.entity.GzipCompressingEntity) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) StatusLine(org.apache.http.StatusLine) HttpClient(org.apache.http.client.HttpClient) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GzipCompressingEntity

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) GzipCompressingEntity(org.apache.http.client.entity.GzipCompressingEntity) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) RuntimeMXBean(java.lang.management.RuntimeMXBean) MemoryUsage(java.lang.management.MemoryUsage) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GzipCompressingEntity

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GzipCompressingEntity(org.apache.http.client.entity.GzipCompressingEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder)

Aggregations

GzipCompressingEntity (org.apache.http.client.entity.GzipCompressingEntity)3 HttpPost (org.apache.http.client.methods.HttpPost)3 NotNull (org.jetbrains.annotations.NotNull)2 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)1 IOException (java.io.IOException)1 MemoryUsage (java.lang.management.MemoryUsage)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 HttpClient (org.apache.http.client.HttpClient)1 HttpResponseException (org.apache.http.client.HttpResponseException)1 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)1 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1