Example usage for org.springframework.web.reactive.function BodyInserters fromResource

List of usage examples for org.springframework.web.reactive.function BodyInserters fromResource

Introduction

In this page you can find the example usage for org.springframework.web.reactive.function BodyInserters fromResource.

Prototype

public static <T extends Resource> BodyInserter<T, ReactiveHttpOutputMessage> fromResource(T resource) 

Source Link

Document

Inserter to write the given Resource .

Usage

From source file:org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler.java

/**
 * Render the given error data as a view, using a template view if available or a
 * static HTML file if available otherwise. This will return an empty
 * {@code Publisher} if none of the above are available.
 * @param viewName the view name/*from w  w w .  ja v  a 2  s.com*/
 * @param responseBody the error response being built
 * @param error the error data as a map
 * @return a Publisher of the {@link ServerResponse}
 */
protected Mono<ServerResponse> renderErrorView(String viewName, ServerResponse.BodyBuilder responseBody,
        Map<String, Object> error) {
    if (isTemplateAvailable(viewName)) {
        return responseBody.render(viewName, error);
    }
    Resource resource = resolveResource(viewName);
    if (resource != null) {
        return responseBody.body(BodyInserters.fromResource(resource));
    }
    return Mono.empty();
}