001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.reactive.resource; 018 019import java.util.List; 020 021import reactor.core.publisher.Mono; 022 023import org.springframework.core.io.Resource; 024import org.springframework.http.server.RequestPath; 025import org.springframework.lang.Nullable; 026import org.springframework.web.server.ServerWebExchange; 027 028/** 029 * A strategy for resolving a request to a server-side resource. 030 * 031 * <p>Provides mechanisms for resolving an incoming request to an actual 032 * {@link Resource} and for obtaining the 033 * public URL path that clients should use when requesting the resource. 034 * 035 * @author Rossen Stoyanchev 036 * @since 5.0 037 */ 038public interface ResourceResolver { 039 040 /** 041 * Resolve the supplied request and request path to a {@link Resource} that 042 * exists under one of the given resource locations. 043 * @param exchange the current exchange 044 * @param requestPath the portion of the request path to use. This is 045 * expected to be the encoded path, i.e. {@link RequestPath#value()}. 046 * @param locations the locations to search in when looking up resources 047 * @param chain the chain of remaining resolvers to delegate to 048 * @return the resolved resource or an empty {@code Mono} if unresolved 049 */ 050 Mono<Resource> resolveResource(@Nullable ServerWebExchange exchange, String requestPath, 051 List<? extends Resource> locations, ResourceResolverChain chain); 052 053 /** 054 * Resolve the externally facing <em>public</em> URL path for clients to use 055 * to access the resource that is located at the given <em>internal</em> 056 * resource path. 057 * <p>This is useful when rendering URL links to clients. 058 * @param resourcePath the "internal" resource path to resolve a path for 059 * public use. This is expected to be the encoded path. 060 * @param locations the locations to search in when looking up resources 061 * @param chain the chain of resolvers to delegate to 062 * @return the resolved public URL path or an empty {@code Mono} if unresolved 063 */ 064 Mono<String> resolveUrlPath(String resourcePath, List<? extends Resource> locations, 065 ResourceResolverChain chain); 066 067}