Search in sources :

Example 6 with ExceptionHandler

use of akka.http.javadsl.server.ExceptionHandler in project mantis by Netflix.

the class JobStatusRoute method createRoute.

public Route createRoute(Function<Route, Route> routeFilter) {
    logger.info("creating routes");
    final ExceptionHandler jsonExceptionHandler = ExceptionHandler.newBuilder().match(IOException.class, x -> {
        logger.error("got exception", x);
        return complete(StatusCodes.BAD_REQUEST, "caught exception " + x.getMessage());
    }).build();
    return respondWithHeaders(DEFAULT_RESPONSE_HEADERS, () -> handleExceptions(jsonExceptionHandler, () -> routeFilter.apply(getJobStatusRoutes())));
}
Also used : ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) JobStatusRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobStatusRouteHandler) HttpHeader(akka.http.javadsl.model.HttpHeader) Route(akka.http.javadsl.server.Route) Flow(akka.stream.javadsl.Flow) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) StatusCodes(akka.http.javadsl.model.StatusCodes) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) Function(java.util.function.Function) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) PathMatchers(akka.http.javadsl.server.PathMatchers) NotUsed(akka.NotUsed) Message(akka.http.javadsl.model.ws.Message) IOException(java.io.IOException)

Example 7 with ExceptionHandler

use of akka.http.javadsl.server.ExceptionHandler in project mantis by Netflix.

the class AgentClusterRoute method createRoute.

public Route createRoute(Function<Route, Route> routeFilter) {
    logger.info("creating routes");
    final ExceptionHandler jsonExceptionHandler = ExceptionHandler.newBuilder().match(Exception.class, x -> {
        logger.error("got exception", x);
        return complete(StatusCodes.INTERNAL_SERVER_ERROR, "{\"error\": \"" + x.getMessage() + "\"}");
    }).build();
    return respondWithHeaders(DEFAULT_RESPONSE_HEADERS, () -> handleExceptions(jsonExceptionHandler, () -> routeFilter.apply(agentClusterRoutes())));
}
Also used : ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) Uri(akka.http.javadsl.model.Uri) MasterConfiguration(io.mantisrx.server.master.config.MasterConfiguration) Arrays(java.util.Arrays) JavaPartialFunction(akka.japi.JavaPartialFunction) Route(akka.http.javadsl.server.Route) Cache(akka.http.caching.javadsl.Cache) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) LoggerFactory(org.slf4j.LoggerFactory) RequestContext(akka.http.javadsl.server.RequestContext) StatusCodes(akka.http.javadsl.model.StatusCodes) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) Function(java.util.function.Function) PathMatcher0(akka.http.javadsl.server.PathMatcher0) Unmarshaller(akka.http.javadsl.unmarshalling.Unmarshaller) Metrics(io.mantisrx.common.metrics.Metrics) Counter(io.mantisrx.common.metrics.Counter) VisibleForTesting(io.mantisrx.shaded.com.google.common.annotations.VisibleForTesting) Logger(org.slf4j.Logger) RouteResult(akka.http.javadsl.server.RouteResult) Preconditions(com.netflix.spectator.impl.Preconditions) HttpHeader(akka.http.javadsl.model.HttpHeader) Jackson(io.mantisrx.master.api.akka.route.Jackson) HttpRequest(akka.http.javadsl.model.HttpRequest) IOException(java.io.IOException) HttpMethods(akka.http.javadsl.model.HttpMethods) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) List(java.util.List) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) CachingDirectives.alwaysCache(akka.http.javadsl.server.directives.CachingDirectives.alwaysCache) ActorSystem(akka.actor.ActorSystem) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) IOException(java.io.IOException)

Aggregations

StatusCodes (akka.http.javadsl.model.StatusCodes)7 ExceptionHandler (akka.http.javadsl.server.ExceptionHandler)7 Route (akka.http.javadsl.server.Route)7 Function (java.util.function.Function)7 HttpHeader (akka.http.javadsl.model.HttpHeader)6 PathMatchers.segment (akka.http.javadsl.server.PathMatchers.segment)6 Arrays (java.util.Arrays)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 IOException (java.io.IOException)5 PathMatchers (akka.http.javadsl.server.PathMatchers)4 Counter (io.mantisrx.common.metrics.Counter)4 Metrics (io.mantisrx.common.metrics.Metrics)4 Jackson (io.mantisrx.master.api.akka.route.Jackson)4 ConfigurationProvider (io.mantisrx.server.master.config.ConfigurationProvider)4 MasterConfiguration (io.mantisrx.server.master.config.MasterConfiguration)4 Optional (java.util.Optional)4 ActorSystem (akka.actor.ActorSystem)3 Cache (akka.http.caching.javadsl.Cache)3 HttpMethods (akka.http.javadsl.model.HttpMethods)3