Java Code Examples for com.linecorp.armeria.server.ServerBuilder#accessLogWriter()

The following examples show how to use com.linecorp.armeria.server.ServerBuilder#accessLogWriter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServiceLogNameTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.accessLogWriter(AccessLogWriter.combined(), true);
    sb.service("/no-default", new MyHttpService());
    sb.service("/no-default/:id", new MyHttpService().decorate(LoggingService.newDecorator()));
    sb.route()
      .get("/users/:id")
      .defaultServiceName("userService")
      .defaultLogName("profile")
      .build((ctx, req) -> HttpResponse.of(HttpStatus.OK));

    sb.annotatedService("/annotated", new MyAnnotatedService());
    sb.decorator((delegate, ctx, req) -> {
       capturedCtx = ctx;
       return delegate.serve(ctx, req);
    });
}
 
Example 2
Source File: ArmeriaConfigurationUtil.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static void configureAccessLog(ServerBuilder serverBuilder, AccessLog accessLog) {
    if ("common".equals(accessLog.getType())) {
        serverBuilder.accessLogWriter(AccessLogWriter.common(), true);
    } else if ("combined".equals(accessLog.getType())) {
        serverBuilder.accessLogWriter(AccessLogWriter.combined(), true);
    } else if ("custom".equals(accessLog.getType())) {
        serverBuilder
                .accessLogWriter(AccessLogWriter.custom(accessLog.getFormat()), true);
    }
}
 
Example 3
Source File: GrpcServiceLogNameTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.accessLogWriter(AccessLogWriter.combined(), true);
    sb.service(GrpcService.builder()
                          .addService(new TestServiceImpl(Executors.newSingleThreadScheduledExecutor()))
                          .build());
    sb.decorator((delegate, ctx, req) -> {
        capturedCtx = ctx;
        return delegate.serve(ctx, req);
    });
}
 
Example 4
Source File: ThriftServiceLogNameTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.accessLogWriter(AccessLogWriter.combined(), true);
    sb.service("/thrift", THttpService.builder()
                                      .addService(HELLO_SERVICE_HANDLER)
                                      .build());
}
 
Example 5
Source File: CentralDogma.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
private Server startServer(ProjectManager pm, CommandExecutor executor,
                           PrometheusMeterRegistry meterRegistry, @Nullable SessionManager sessionManager) {
    final ServerBuilder sb = Server.builder();
    sb.verboseResponses(true);
    cfg.ports().forEach(sb::port);

    if (cfg.ports().stream().anyMatch(ServerPort::hasTls)) {
        try {
            final TlsConfig tlsConfig = cfg.tls();
            if (tlsConfig != null) {
                sb.tls(tlsConfig.keyCertChainFile(), tlsConfig.keyFile(), tlsConfig.keyPassword());
            } else {
                logger.warn(
                        "Missing TLS configuration. Generating a self-signed certificate for TLS support.");
                sb.tlsSelfSigned();
            }
        } catch (Exception e) {
            Exceptions.throwUnsafely(e);
        }
    }

    sb.clientAddressSources(cfg.clientAddressSourceList());
    sb.clientAddressTrustedProxyFilter(cfg.trustedProxyAddressPredicate());

    cfg.numWorkers().ifPresent(
            numWorkers -> sb.workerGroup(EventLoopGroups.newEventLoopGroup(numWorkers), true));
    cfg.maxNumConnections().ifPresent(sb::maxNumConnections);
    cfg.idleTimeoutMillis().ifPresent(sb::idleTimeoutMillis);
    cfg.requestTimeoutMillis().ifPresent(sb::requestTimeoutMillis);
    cfg.maxFrameLength().ifPresent(sb::maxRequestLength);
    cfg.gracefulShutdownTimeout().ifPresent(
            t -> sb.gracefulShutdownTimeoutMillis(t.quietPeriodMillis(), t.timeoutMillis()));

    final MetadataService mds = new MetadataService(pm, executor);
    final WatchService watchService = new WatchService(meterRegistry);
    final AuthProvider authProvider = createAuthProvider(executor, sessionManager, mds);

    configureThriftService(sb, pm, executor, watchService, mds);

    sb.service("/title", webAppTitleFile(cfg.webAppTitle(), SystemInfo.hostname()).asService());

    sb.service(HEALTH_CHECK_PATH, HealthCheckService.of());

    // TODO(hyangtack): This service is temporarily added to support redirection from '/docs' to '/docs/'.
    //                  It would be removed if this kind of redirection is handled by Armeria.
    sb.service("/docs", new AbstractHttpService() {
        @Override
        protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req)
                throws Exception {
            return HttpResponse.of(
                    ResponseHeaders.of(HttpStatus.TEMPORARY_REDIRECT, HttpHeaderNames.LOCATION, "/docs/"));
        }
    });
    sb.serviceUnder("/docs/",
                    DocService.builder()
                              .exampleHttpHeaders(CentralDogmaService.class,
                                                  HttpHeaders.of(HttpHeaderNames.AUTHORIZATION,
                                                                 "Bearer " + CsrfToken.ANONYMOUS))
                              .build());

    configureHttpApi(sb, pm, executor, watchService, mds, authProvider, sessionManager);

    configureMetrics(sb, meterRegistry);

    // Configure access log format.
    final String accessLogFormat = cfg.accessLogFormat();
    if (isNullOrEmpty(accessLogFormat)) {
        sb.accessLogWriter(AccessLogWriter.disabled(), true);
    } else if ("common".equals(accessLogFormat)) {
        sb.accessLogWriter(AccessLogWriter.common(), true);
    } else if ("combined".equals(accessLogFormat)) {
        sb.accessLogWriter(AccessLogWriter.combined(), true);
    } else {
        sb.accessLogFormat(accessLogFormat);
    }

    final Server s = sb.build();
    s.start().join();
    return s;
}