/** * Creates a new instance of {@link akka.http.javadsl.server.RejectionHandler} with custom behaviour. * * @return The new instance. */ public static RejectionHandler createInstance() { return RejectionHandler.newBuilder() .handle(MissingQueryParamRejection.class, DittoRejectionHandlerFactory::handleMissingQueryParam) .build() .withFallback(RejectionHandler.defaultHandler()); }
/** * PatchMather which matches double slashes in the path as well as single slashes. * * @return a PathMatcher0 merging double slashes in an unmatched path. */ public static PathMatcher0 mergeDoubleSlashes() { return PathMatchers.slash().concat(PathMatchers.slash()) // match 2 slashes, e.g. //foo .orElse(PathMatchers.slash()); // as fallback match one slash, e.g. /foo }
@Override public Route route(Route first, Route... others) { return createRoute(first, others); }
/** * Builds the {@code /{inbox|outbox}} sub route for the features route. * * @return the {@code /{inbox|outbox}} route. */ public Route buildFeaturesInboxOutboxRoute(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId, final String featureId) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment(INBOX_OUTBOX_PATTERN)), inboxOutbox -> // /<inbox|outbox> post(() -> featureMessages(ctx, dittoHeaders, thingId, featureId, inboxOutbox)) ); }
/** * Builds the {@code /health} route. * * @return the {@code /health} route. */ public Route buildHealthRoute() { return path(PATH_HEALTH, () -> // /health get(() -> // GET completeWithFuture(createOverallHealthResponse()) ) ); }
public Route buildStatsRoute(final String correlationId) { return Directives.rawPathPrefix(CustomPathMatchers.mergeDoubleSlashes().concat(STATISTICS_PATH_PREFIX), () -> // /stats/* extractRequestContext(ctx -> get(() -> // GET buildSubRoutes(ctx, correlationId) ) ) ); }
/** * Start a server on the specified host and port, using the provided settings and [[ActorSystem]]. * Note that this method is blocking. * * @param system ActorSystem to use for starting the app, * if null is passed in a new default ActorSystem will be created instead, which will * be terminated when the server is stopped. */ public void startServer(String host, int port, ServerSettings settings, ActorSystem system) throws ExecutionException, InterruptedException { startServer(host, port, settings, Optional.ofNullable(system)); }
private static Route handleMissingQueryParam(MissingQueryParamRejection missingQueryParamRejection) { // return status code 400 instead of the akka default 404 return complete(StatusCodes.BAD_REQUEST, MessageFormat.format(MISSING_QUERY_PARAM_TEMPLATE, missingQueryParamRejection.parameterName())); } }
private Route featuresEntryInboxOutbox(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), featureId -> // POST /features/{featureId}/<inbox|outbox> messagesRoute.buildFeaturesInboxOutboxRoute(ctx, dittoHeaders, thingId, featureId) ); } }
@Override public Route unauthorized(final String correlationId) { return Directives.complete(StatusCodes.UNAUTHORIZED); }
private Route policyEntryEntries(final RequestContext ctx, final DittoHeaders dittoHeaders, final String policyId) { return rawPathPrefix(mergeDoubleSlashes().concat(PATH_ENTRIES), () -> // /policies/<policyId>/entries policyEntriesRoute.buildPolicyEntriesRoute(ctx, dittoHeaders, policyId) ); }
/** * Builds the {@code /{inbox|outbox}} sub route for the things route. * * @return the {@code /{inbox|outbox}} route. */ public Route buildThingsInboxOutboxRoute(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return route( claimMessages(ctx, dittoHeaders, thingId), // /inbox/claim rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment(INBOX_OUTBOX_PATTERN)), inboxOutbox -> // /<inbox|outbox> post(() -> thingMessages(ctx, dittoHeaders, thingId, inboxOutbox)) ) ); }
/** * Start a server on the specified host and port, using the provided settings and [[ActorSystem]]. * Note that this method is blocking. * * @param system ActorSystem to use for starting the app, * if null is passed in a new default ActorSystem will be created instead, which will * be terminated when the server is stopped. */ public void startServer(String host, int port, ServerSettings settings, ActorSystem system) throws ExecutionException, InterruptedException { startServer(host, port, settings, Optional.ofNullable(system)); }
private static Route buildRouteWithServiceNameAndInstance(final RequestContext ctx, final String serviceName, final DittoHeaders dittoHeaders, final RouteBuilderWithOptionalServiceNameAndInstance routeBuilder) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), instance -> // /devops/<logging|piggyback>/<serviceName>/<instance> routeBuilder.build(ctx, serviceName, Integer.parseInt(instance), dittoHeaders) ); }
/** * Builds the {@code /policies} route. * * @return the {@code /policies} route. */ public Route buildPoliciesRoute(final RequestContext ctx, final DittoHeaders dittoHeaders) { return rawPathPrefix(mergeDoubleSlashes().concat(PATH_POLICIES), () -> rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), policyId -> // /policies/<policyId> route( policyEntry(ctx, dittoHeaders, policyId), policyEntryEntries(ctx, dittoHeaders, policyId) ) ) ); }
/** * Start a server on the specified host and port, using the provided settings and [[ActorSystem]]. * Note that this method is blocking. * * @param system ActorSystem to use for starting the app, * if null is passed in a new default ActorSystem will be created instead, which will * be terminated when the server is stopped. */ public void startServer(String host, int port, ServerSettings settings, ActorSystem system) throws ExecutionException, InterruptedException { startServer(host, port, settings, Optional.ofNullable(system)); }
private static Route buildRouteWithServiceNameAndOptionalInstance(final RequestContext ctx, final DittoHeaders dittoHeaders, final RouteBuilderWithOptionalServiceNameAndInstance routeBuilder) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), serviceName -> route( // /devops/<logging|piggyback>/<serviceName>/<instance> buildRouteWithServiceNameAndInstance(ctx, serviceName, dittoHeaders, routeBuilder), // /devops/<logging|piggyback>/<serviceName> routeBuilder.build(ctx, serviceName, null, dittoHeaders) ) ); }
/** * Start a server on the specified host and port, using the provided settings. * Note that this method is blocking. */ public void startServer(String host, int port, ServerSettings settings) throws ExecutionException, InterruptedException { startServer(host, port, settings, Optional.empty()); }
/** * Start a server on the specified host and port, using the provided settings. * Note that this method is blocking. */ public void startServer(String host, int port, ServerSettings settings) throws ExecutionException, InterruptedException { startServer(host, port, settings, Optional.empty()); }
/** * Start a server on the specified host and port, using the provided settings. * Note that this method is blocking. */ public void startServer(String host, int port, ServerSettings settings) throws ExecutionException, InterruptedException { startServer(host, port, settings, Optional.empty()); }