Example usage for org.springframework.web.reactive.function.server HandlerStrategies localeContextResolver

List of usage examples for org.springframework.web.reactive.function.server HandlerStrategies localeContextResolver

Introduction

In this page you can find the example usage for org.springframework.web.reactive.function.server HandlerStrategies localeContextResolver.

Prototype

LocaleContextResolver localeContextResolver();

Source Link

Document

Return the LocaleContextResolver to be used for resolving locale context.

Usage

From source file:org.springframework.web.reactive.function.server.RouterFunctions.java

/**
 * Convert the given {@linkplain RouterFunction router function} into a {@link HttpHandler},
 * using the given strategies./*from w w w .j  av a  2  s. co  m*/
 * <p>The returned {@code HttpHandler} can be adapted to run in
 * <ul>
 * <li>Servlet 3.1+ using the
 * {@link org.springframework.http.server.reactive.ServletHttpHandlerAdapter},</li>
 * <li>Reactor using the
 * {@link org.springframework.http.server.reactive.ReactorHttpHandlerAdapter},</li>
 * <li>Undertow using the
 * {@link org.springframework.http.server.reactive.UndertowHttpHandlerAdapter}.</li>
 * </ul>
 * @param routerFunction the router function to convert
 * @param strategies the strategies to use
 * @return an http handler that handles HTTP request using the given router function
 */
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, HandlerStrategies strategies) {
    Assert.notNull(routerFunction, "RouterFunction must not be null");
    Assert.notNull(strategies, "HandlerStrategies must not be null");

    WebHandler webHandler = toWebHandler(routerFunction, strategies);
    return WebHttpHandlerBuilder.webHandler(webHandler)
            .filters(filters -> filters.addAll(strategies.webFilters()))
            .exceptionHandlers(handlers -> handlers.addAll(strategies.exceptionHandlers()))
            .localeContextResolver(strategies.localeContextResolver()).build();
}