Example usage for org.springframework.web.reactive.result.method.annotation InitBinderBindingContext saveModel

List of usage examples for org.springframework.web.reactive.result.method.annotation InitBinderBindingContext saveModel

Introduction

In this page you can find the example usage for org.springframework.web.reactive.result.method.annotation InitBinderBindingContext saveModel.

Prototype

public void saveModel() 

Source Link

Document

Save model attributes in the session based on a type-level declarations in an @SessionAttributes annotation.

Usage

From source file:org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter.java

@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Assert.state(this.methodResolver != null && this.modelInitializer != null, "Not initialized");

    InitBinderBindingContext bindingContext = new InitBinderBindingContext(getWebBindingInitializer(),
            this.methodResolver.getInitBinderMethods(handlerMethod));

    InvocableHandlerMethod invocableMethod = this.methodResolver.getRequestMappingMethod(handlerMethod);

    Function<Throwable, Mono<HandlerResult>> exceptionHandler = ex -> handleException(ex, handlerMethod,
            bindingContext, exchange);/*w  w w  .j  av a 2  s .c om*/

    return this.modelInitializer.initModel(handlerMethod, bindingContext, exchange)
            .then(Mono.defer(() -> invocableMethod.invoke(exchange, bindingContext)))
            .doOnNext(result -> result.setExceptionHandler(exceptionHandler))
            .doOnNext(result -> bindingContext.saveModel()).onErrorResume(exceptionHandler);
}