Java Code Examples for com.linecorp.armeria.server.HttpService#decorate()
The following examples show how to use
com.linecorp.armeria.server.HttpService#decorate() .
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: CentralDogma.java From centraldogma with Apache License 2.0 | 6 votes |
private void configureThriftService(ServerBuilder sb, ProjectManager pm, CommandExecutor executor, WatchService watchService, MetadataService mds) { final CentralDogmaServiceImpl service = new CentralDogmaServiceImpl(pm, executor, watchService, mds); HttpService thriftService = ThriftCallService.of(service) .decorate(CentralDogmaTimeoutScheduler::new) .decorate(CentralDogmaExceptionTranslator::new) .decorate(THttpService.newDecorator()); if (cfg.isCsrfTokenRequiredForThrift()) { thriftService = thriftService.decorate(AuthService.newDecorator(new CsrfTokenAuthorizer())); } else { thriftService = thriftService.decorate(TokenlessClientLogger::new); } // Enable content compression for API responses. thriftService = thriftService.decorate(contentEncodingDecorator()); sb.service("/cd/thrift/v1", thriftService); }
Example 2
Source File: ServerModule.java From curiostack with MIT License | 5 votes |
private static HttpService internalService( HttpService service, Optional<Function<HttpService, IpFilteringService>> ipFilter, ServerConfig config) { if (!ipFilter.isPresent() || !config.getIpFilterInternalOnly()) { return service; } return service.decorate(ipFilter.get()); }
Example 3
Source File: ArmeriaConfigurationUtil.java From armeria with Apache License 2.0 | 5 votes |
private static HttpService setupMetricCollectingService( HttpService service, AbstractServiceRegistrationBean<?, ?, ?, ?> bean, @Nullable MeterIdPrefixFunctionFactory meterIdPrefixFunctionFactory) { requireNonNull(service, "service"); requireNonNull(bean, "bean"); if (meterIdPrefixFunctionFactory == null) { return service; } return service.decorate(metricCollectingServiceDecorator(bean, meterIdPrefixFunctionFactory)); }
Example 4
Source File: AnnotatedServiceElement.java From armeria with Apache License 2.0 | 5 votes |
/** * Builds a safe decorated {@link HttpService} by wrapping the localDecorator with * exceptionHandlingDecorators. * * @param localDecorator a decorator to decorate the service with. */ public HttpService buildSafeDecoratedService( Function<? super HttpService, ? extends HttpService> localDecorator) { // Apply decorators which are specified in the service class. HttpService decoratedService = decorator.apply(service); // Apply localDecorator passed in through method parameter decoratedService = decoratedService.decorate(localDecorator); // If there is a decorator, we should add one more decorator which handles an exception // raised from decorators. if (decoratedService != service) { decoratedService = service.exceptionHandlingDecorator().apply(decoratedService); } return decoratedService; }
Example 5
Source File: SamlAuthProvider.java From centraldogma with Apache License 2.0 | 4 votes |
@Override public HttpService webLoginService() { // Should always redirect to the IdP because the browser cannot set a token to the request. final HttpService service = (ctx, req) -> HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR); return service.decorate(sp.newSamlDecorator()); }
Example 6
Source File: ServerModule.java From curiostack with MIT License | 4 votes |
private static HttpService decorateService( HttpService service, Tracing tracing, Lazy<FirebaseAuthorizer> firebaseAuthorizer, Lazy<JwtAuthorizer.Factory> jwtAuthorizer, Optional<SslCommonNamesProvider> sslCommonNamesProvider, ServerConfig serverConfig, FirebaseAuthConfig authConfig) { if (sslCommonNamesProvider.isPresent() && !serverConfig.isDisableSslAuthorization()) { AuthServiceBuilder authServiceBuilder = AuthService.builder(); authServiceBuilder.add(new SslAuthorizer(sslCommonNamesProvider.get())); service = service.decorate(authServiceBuilder.newDecorator()); } if (serverConfig.isEnableIapAuthorization()) { service = service .decorate( (delegate, ctx, req) -> { DecodedJWT jwt = ctx.attr(JwtAuthorizer.DECODED_JWT); String loggedInUserEmail = jwt != null ? jwt.getClaim("email").asString() : "unknown"; RequestLoggingContext.put(ctx, "logged_in_user", loggedInUserEmail); return delegate.serve(ctx, req); }) .decorate( AuthService.builder() .addTokenAuthorizer( headers -> OAuth2Token.of( headers.get(HttpHeaderNames.of("x-goog-iap-jwt-assertion"))), jwtAuthorizer .get() .create( Algorithm.ES256, "https://www.gstatic.com/iap/verify/public_key")) .newDecorator()); } if (!authConfig.getServiceAccountBase64().isEmpty()) { FirebaseAuthorizer authorizer = firebaseAuthorizer.get(); service = service.decorate( AuthService.builder().addOAuth2(authorizer).onFailure(authorizer).newDecorator()); } service = service .decorate( MetricCollectingService.newDecorator( RpcMetricLabels.grpcRequestLabeler("grpc_services"))) .decorate(BraveService.newDecorator(tracing)) .decorate( (delegate, ctx, req) -> { TraceContext traceCtx = tracing.currentTraceContext().get(); if (traceCtx != null) { RequestLoggingContext.put(ctx, "traceId", traceCtx.traceIdString()); RequestLoggingContext.put(ctx, "spanId", traceCtx.spanIdString()); } return delegate.serve(ctx, req); }); return service; }