Java Code Examples for org.springframework.web.reactive.function.server.HandlerFunction#handle()

The following examples show how to use org.springframework.web.reactive.function.server.HandlerFunction#handle() . 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: WingtipsSpringWebfluxComponentTest.java    From wingtips with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ServerResponse> filter(
    ServerRequest serverRequest,
    HandlerFunction<ServerResponse> handlerFunction
) {
    HttpHeaders httpHeaders = serverRequest.headers().asHttpHeaders();

    if ("true".equals(httpHeaders.getFirst("throw-handler-filter-function-exception"))) {
        ComponentTestController.sleepThread(SLEEP_TIME_MILLIS);
        throw new RuntimeException("Exception thrown from HandlerFilterFunction");
    }

    if ("true".equals(httpHeaders.getFirst("return-exception-in-handler-filter-function-mono"))) {
        return Mono
            .delay(Duration.ofMillis(SLEEP_TIME_MILLIS))
            .map(d -> {
                throw new RuntimeException("Exception returned from HandlerFilterFunction Mono");
            });
    }

    return handlerFunction.handle(serverRequest);
}
 
Example 2
Source File: ExplodingHandlerFilterFunction.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ServerResponse> filter(
    ServerRequest serverRequest,
    HandlerFunction<ServerResponse> handlerFunction
) {
    HttpHeaders httpHeaders = serverRequest.headers().asHttpHeaders();

    if ("true".equals(httpHeaders.getFirst("throw-handler-filter-function-exception"))) {
        throw ApiException
            .newBuilder()
            .withApiErrors(SampleProjectApiError.ERROR_THROWN_IN_HANDLER_FILTER_FUNCTION)
            .withExceptionMessage("Exception thrown from HandlerFilterFunction")
            .build();
    }

    if ("true".equals(httpHeaders.getFirst("return-exception-in-handler-filter-function-mono"))) {
        return Mono.error(
            ApiException
                .newBuilder()
                .withApiErrors(SampleProjectApiError.ERROR_RETURNED_IN_HANDLER_FILTER_FUNCTION_MONO)
                .withExceptionMessage("Exception returned from HandlerFilterFunction Mono")
                .build()
        );
    }

    return handlerFunction.handle(serverRequest);
}
 
Example 3
Source File: BackstopperSpringWebFluxComponentTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ServerResponse> filter(
    ServerRequest serverRequest,
    HandlerFunction<ServerResponse> handlerFunction
) {
    HttpHeaders httpHeaders = serverRequest.headers().asHttpHeaders();

    if ("true".equals(httpHeaders.getFirst("throw-handler-filter-function-exception"))) {
        throw ApiException
            .newBuilder()
            .withApiErrors(ERROR_THROWN_IN_HANDLER_FILTER_FUNCTION)
            .withExceptionMessage("Exception thrown from HandlerFilterFunction")
            .build();
    }

    if ("true".equals(httpHeaders.getFirst("return-exception-in-handler-filter-function-mono"))) {
        return Mono.error(
            ApiException
                .newBuilder()
                .withApiErrors(ERROR_RETURNED_IN_HANDLER_FILTER_FUNCTION_MONO)
                .withExceptionMessage("Exception returned from HandlerFilterFunction Mono")
                .build()
        );
    }

    return handlerFunction.handle(serverRequest);
}
 
Example 4
Source File: SampleSpringboot2WebFluxSpringConfig.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ServerResponse> filter(
    ServerRequest serverRequest,
    HandlerFunction<ServerResponse> handlerFunction
) {
    HttpHeaders httpHeaders = serverRequest.headers().asHttpHeaders();

    if ("true".equals(httpHeaders.getFirst("throw-handler-filter-function-exception"))) {
        throw ApiException
            .newBuilder()
            .withApiErrors(SampleProjectApiError.ERROR_THROWN_IN_HANDLER_FILTER_FUNCTION)
            .withExceptionMessage("Exception thrown from HandlerFilterFunction")
            .build();
    }

    if ("true".equals(httpHeaders.getFirst("return-exception-in-handler-filter-function-mono"))) {
        return Mono.error(
            ApiException
                .newBuilder()
                .withApiErrors(SampleProjectApiError.ERROR_RETURNED_IN_HANDLER_FILTER_FUNCTION_MONO)
                .withExceptionMessage("Exception returned from HandlerFilterFunction Mono")
                .build()
        );
    }

    return handlerFunction.handle(serverRequest);
}
 
Example 5
Source File: ExampleHandlerFilterFunction.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Mono<ServerResponse> filter(ServerRequest serverRequest, HandlerFunction<ServerResponse> handlerFunction) {
    if (serverRequest.pathVariable("name").equalsIgnoreCase("test")) {
        return ServerResponse.status(FORBIDDEN).build();
    }
    return handlerFunction.handle(serverRequest);
}