/** * Extracts the correlationId from the request or creates a new one, if it does not exist. * * @param inner the inner Route to provide with the correlationId * @return the new Route wrapping {@code inner} with the correlationId */ public static Route ensureCorrelationId(final Function<String, Route> inner) { return extractRequestContext(requestContext -> { final HttpRequest request = requestContext.getRequest(); final Optional<String> correlationIdOpt = extractCorrelationId(request); final String correlationId; if (correlationIdOpt.isPresent()) { correlationId = correlationIdOpt.get(); LOGGER.debug("CorrelationId already exists in request: {}", correlationId); } else { correlationId = UUID.randomUUID().toString(); LOGGER.debug("Created new CorrelationId: {}", correlationId); } return enhanceLogWithCorrelationId(correlationId, () -> inner.apply(correlationId)); }); }
/** * Depending on the request headers, one of the supported authentication mechanisms is applied. * * @param correlationId the correlationId which will be added to the log * @param inner the inner route which will be wrapped with the {@link AuthorizationContext} * @return the inner route wrapped with the {@link AuthorizationContext} */ public Route authenticate(final String correlationId, final Function<AuthorizationContext, Route> inner) { return extractRequestContext( requestContext -> DirectivesLoggingUtils.enhanceLogWithCorrelationId(correlationId, () -> { final Optional<AuthenticationProvider> applicableDirective = authenticationChain.stream() .filter(authenticationDirective -> authenticationDirective.isApplicable(requestContext)) .findFirst(); final Uri requestUri = requestContext.getRequest().getUri(); if (applicableDirective.isPresent()) { final AuthenticationProvider authenticationProvider = applicableDirective.get(); LOGGER.debug("Applying Authentication Directive '{}' to URI '{}'", authenticationProvider.getClass().getSimpleName(), requestUri); return authenticationProvider.authenticate(correlationId, inner); } else { LOGGER.debug("Missing Authentication for URI '{}'. Applying unauthorizedDirective '{}'", requestUri, unauthorizedDirective); return unauthorizedDirective.apply(correlationId); } })); }
return extractActorSystem(actorSystem -> extractRequestContext( requestContext -> enhanceLogWithCorrelationId(correlationId, () -> { final Config config = actorSystem.settings().config();
public static Route ensureEncoding(final String correlationId, final Supplier<Route> inner) { return extractRequestContext(requestContext -> enhanceLogWithCorrelationId(correlationId, () -> { final Uri uri = requestContext.getRequest().getUri(); try { // per default, Akka evaluates the query params "lazily" in the routes and throws an IllegalUriException // in case of error; we evaluate the query params explicitly here to be able to handle this error at // a central location uri.query(); } catch (final IllegalUriException e) { LOGGER.debug("URI parsing failed", e); final String rawRequestUri = HttpUtils.getRawRequestUri(requestContext.getRequest()); final String message = MessageFormat.format(URI_INVALID_TEMPLATE, rawRequestUri); return complete(StatusCodes.BAD_REQUEST, message); } return inner.get(); })); } }
public Route buildStatsRoute(final String correlationId) { return Directives.rawPathPrefix(CustomPathMatchers.mergeDoubleSlashes().concat(STATISTICS_PATH_PREFIX), () -> // /stats/* extractRequestContext(ctx -> get(() -> // GET buildSubRoutes(ctx, correlationId) ) ) ); }
return extractRequestContext(requestContext -> enhanceLogWithCorrelationId(correlationId, () -> { final String dummyAuth = getRequestHeader(requestContext, HttpHeader.X_DITTO_DUMMY_AUTH.getName())
return extractRequestContext(requestContext -> { final HttpRequest request = requestContext.getRequest(); final String requestMethod = request.method().name();
@Override public Route authenticate(final String correlationId, final Function<AuthorizationContext, Route> inner) { return extractRequestContext( requestContext -> DirectivesLoggingUtils.enhanceLogWithCorrelationId(correlationId, () -> { final Optional<String> authorization =
/** * Builds the {@code /} route. * * @return the {@code /} route. */ public Route buildRoute() { return wrapWithRootDirectives(correlationId -> extractRequestContext(ctx -> route( statsRoute.buildStatsRoute(correlationId), // /stats cachingHealthRoute.buildHealthRoute(), // /health api(ctx, correlationId), // /api ws(ctx, correlationId), // /ws ownStatusRoute.buildStatusRoute(), // /status overallStatusRoute.buildOverallStatusRoute(), // /overall devopsRoute.buildDevopsRoute(ctx) // /devops ) ) ); }
final Config config = actorSystem.settings().config(); return extractRequestContext(requestContext -> enhanceLogWithCorrelationId(correlationId, () -> {