APISonar


com.linecorp.armeria.server.ServiceRequestContext.log

> com > linecorp > armeria > server > ServiceRequestContext > log
com APIs linecorp APIs armeria APIs server APIs ServiceRequestContext APIs log APIs

Example 1
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
        ctx.log().addListener(log -> {
            final L structuredLog = logBuilder.build(log);
            if (structuredLog != null) {
                writeLog(log, structuredLog);
            }
        }, RequestLogAvailability.COMPLETE);
        return delegate().serve(ctx, req);
    }
Example 2
void requestLogWithEmptyCause() {
        final ServiceRequestContext ctx = ServiceRequestContext.of(HttpRequest.of(HttpMethod.GET, "/"));

        final RequestLog log = ctx.log();
        final RequestLogBuilder logBuilder = ctx.logBuilder();

        final List<AccessLogComponent> format =
                AccessLogFormats.parseCustom("%{requestCause}L %{responseCause}L");

        logBuilder.endRequest();
        logBuilder.endResponse();

        assertThat(AccessLogger.format(format, log)).isEqualTo("- -");
    }
Example 3
public void testId_Assign() {
        final RequestHeaders reqHeaders =
                RequestHeaders.of(HttpMethod.POST, "/armeria/id",
                                  HttpHeaderNames.CONTENT_LENGTH, VERY_LONG_STRING.length());
        final HttpRequest req = AggregatedHttpRequest.of(reqHeaders, HttpData.ofUtf8(VERY_LONG_STRING))
                                                     .toHttpRequest();
        final ClientRequestContext cctx = ClientRequestContext.builder(req).build();
        assertThat(cctx.log().id()).isNotNull();
        assertThat(cctx.log().id()).isEqualTo(cctx.id());

        final ServiceRequestContext sctx = ServiceRequestContext.of(req);
        assertThat(sctx.log().id()).isNotNull();
        assertThat(sctx.log().id()).isEqualTo(sctx.id());
    }
Example 4
private final ServiceRequestContext ctx;

    public void endOfStream() {
        setClientStreamClosed();
        if (!closeCalled) {
            if (!ctx.log().isAvailable(RequestLogAvailability.REQUEST_CONTENT)) {
                ctx.logBuilder().requestContent(GrpcLogUtil.rpcRequest(method), null);
            }

            if (blockingExecutor != null) {
                blockingExecutor.execute(this::invokeHalfClose);
            } else {
                invokeHalfClose();
            }
        }
    }
Example 5
private ServiceRequestContext ctx;

    void statusCode_notAvailable() {
        when(ctx.log()).thenReturn(requestLog);
        when(requestLog.isAvailable(RequestLogAvailability.RESPONSE_HEADERS)).thenReturn(false);
        assertThat(response.statusCode()).isEqualTo(0);
    }
Example 6
private ServiceRequestContext ctx;

    void requestHeader() {
        when(ctx.log()).thenReturn(requestLog);
        when(requestLog.isAvailable(RequestLogAvailability.REQUEST_HEADERS)).thenReturn(true);
        final RequestHeaders requestHeaders = mock(RequestHeaders.class);
        when(requestLog.requestHeaders()).thenReturn(requestHeaders);
        when(requestHeaders.get("foo")).thenReturn("bar");
        assertThat(request.header("foo")).isEqualTo("bar");
    }