Search in sources :

Example 1 with AggregatedHttpResponse

use of com.linecorp.armeria.common.AggregatedHttpResponse in project zipkin by openzipkin.

the class ITZipkinServerSsl method callHealthEndpoint.

void callHealthEndpoint(SessionProtocol http) {
    AggregatedHttpResponse response = WebClient.builder(baseUrl(server, http)).factory(clientFactory).build().get("/health").aggregate().join();
    assertThat(response.status()).isEqualTo(HttpStatus.OK);
}
Also used : AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse)

Example 2 with AggregatedHttpResponse

use of com.linecorp.armeria.common.AggregatedHttpResponse in project zipkin by openzipkin.

the class HttpCall method sendRequest.

CompletableFuture<AggregatedHttpResponse> sendRequest() {
    final HttpResponse response;
    try (SafeCloseable ignored = Clients.withContextCustomizer(ctx -> ctx.logBuilder().name(name))) {
        HttpRequestWriter httpRequest = HttpRequest.streaming(request.headers());
        response = httpClient.execute(httpRequest);
        request.writeBody(httpRequest::tryWrite);
        httpRequest.close();
    }
    CompletableFuture<AggregatedHttpResponse> responseFuture = RequestContext.mapCurrent(ctx -> response.aggregateWithPooledObjects(ctx.eventLoop(), ctx.alloc()), // This should never be used in practice since the module runs in an Armeria server.
    response::aggregate);
    responseFuture = responseFuture.exceptionally(t -> {
        if (t instanceof UnprocessedRequestException) {
            Throwable cause = t.getCause();
            // Go ahead and reduce the output in logs since this is usually a configuration or
            // infrastructure issue and the Armeria stack trace won't help debugging that.
            Exceptions.clearTrace(cause);
            String message = cause.getMessage();
            if (message == null)
                message = cause.getClass().getSimpleName();
            throw new RejectedExecutionException(message, cause);
        } else {
            Exceptions.throwUnsafely(t);
        }
        return null;
    });
    this.responseFuture = responseFuture;
    return responseFuture;
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) OBJECT_MAPPER(zipkin2.elasticsearch.internal.JsonSerializers.OBJECT_MAPPER) RequestHeaders(com.linecorp.armeria.common.RequestHeaders) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) HttpStatus(com.linecorp.armeria.common.HttpStatus) WebClient(com.linecorp.armeria.client.WebClient) Clients(com.linecorp.armeria.client.Clients) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) Callback(zipkin2.Callback) HttpRequestWriter(com.linecorp.armeria.common.HttpRequestWriter) Exceptions(com.linecorp.armeria.common.util.Exceptions) UnprocessedRequestException(com.linecorp.armeria.client.UnprocessedRequestException) SafeCloseable(com.linecorp.armeria.common.util.SafeCloseable) HttpData(com.linecorp.armeria.common.HttpData) HttpResponse(com.linecorp.armeria.common.HttpResponse) JsonParser(com.fasterxml.jackson.core.JsonParser) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) FileNotFoundException(java.io.FileNotFoundException) HttpStatusClass(com.linecorp.armeria.common.HttpStatusClass) RequestContext(com.linecorp.armeria.common.RequestContext) HttpRequest(com.linecorp.armeria.common.HttpRequest) HttpHeaders(com.linecorp.armeria.common.HttpHeaders) JSON_FACTORY(zipkin2.elasticsearch.internal.JsonSerializers.JSON_FACTORY) Call(zipkin2.Call) InputStream(java.io.InputStream) UnprocessedRequestException(com.linecorp.armeria.client.UnprocessedRequestException) HttpRequestWriter(com.linecorp.armeria.common.HttpRequestWriter) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) SafeCloseable(com.linecorp.armeria.common.util.SafeCloseable) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 3 with AggregatedHttpResponse

use of com.linecorp.armeria.common.AggregatedHttpResponse in project zipkin by openzipkin.

the class ITElasticsearchStorage method testUsageOfDeprecatedFeatures.

@Test
void testUsageOfDeprecatedFeatures() {
    WebClient webClient = WebClient.builder(elasticsearch().baseUrl()).factory(ClientFactory.builder().useHttp2Preface(false).build()).build();
    final AggregatedHttpResponse response = webClient.execute(HttpRequest.of(RequestHeaders.of(HttpMethod.GET, "/_migration/deprecations"))).aggregate().join();
    if (!response.contentAscii().isEmpty()) {
        LOGGER.warn("The ElasticSearch instance used during IT's is using deprecated features or " + "configuration. This is likely nothing to be really worried about (for example 'xpack.monitoring.enabled' " + "setting), but nevertheless it should be looked at to see if our docker image used during " + "integration tests needs updating for the next version of ElasticSearch. " + "See https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-deprecation.html" + "for more information. This is the deprecation warning we received:\n\n" + response.contentAscii());
    }
}
Also used : WebClient(com.linecorp.armeria.client.WebClient) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) Test(org.junit.jupiter.api.Test)

Example 4 with AggregatedHttpResponse

use of com.linecorp.armeria.common.AggregatedHttpResponse in project zipkin by openzipkin.

the class HttpCallTest method releasesAllReferencesToByteBuf.

@Test
void releasesAllReferencesToByteBuf() {
    // Force this to be a ref-counted response
    byte[] message = "{\"Message\":\"error\"}".getBytes(UTF_8);
    ByteBuf encodedBuf = PooledByteBufAllocator.DEFAULT.buffer(message.length);
    encodedBuf.writeBytes(message);
    AggregatedHttpResponse response = AggregatedHttpResponse.of(ResponseHeaders.of(HttpStatus.FORBIDDEN), HttpData.wrap(encodedBuf));
    HttpCall<Object> call = http.newCall(REQUEST, NULL, "test");
    // Invoke the parser directly because using the fake server will not result in ref-counted
    assertThatThrownBy(() -> call.parseResponse(response, NULL)).hasMessage("error");
    assertThat(encodedBuf.refCnt()).isEqualTo(0);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

AggregatedHttpResponse (com.linecorp.armeria.common.AggregatedHttpResponse)4 WebClient (com.linecorp.armeria.client.WebClient)2 Test (org.junit.jupiter.api.Test)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Clients (com.linecorp.armeria.client.Clients)1 UnprocessedRequestException (com.linecorp.armeria.client.UnprocessedRequestException)1 AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)1 HttpData (com.linecorp.armeria.common.HttpData)1 HttpHeaders (com.linecorp.armeria.common.HttpHeaders)1 HttpRequest (com.linecorp.armeria.common.HttpRequest)1 HttpRequestWriter (com.linecorp.armeria.common.HttpRequestWriter)1 HttpResponse (com.linecorp.armeria.common.HttpResponse)1 HttpStatus (com.linecorp.armeria.common.HttpStatus)1 HttpStatusClass (com.linecorp.armeria.common.HttpStatusClass)1 RequestContext (com.linecorp.armeria.common.RequestContext)1 RequestHeaders (com.linecorp.armeria.common.RequestHeaders)1 Exceptions (com.linecorp.armeria.common.util.Exceptions)1 SafeCloseable (com.linecorp.armeria.common.util.SafeCloseable)1 ByteBuf (io.netty.buffer.ByteBuf)1