001/*
002 * Copyright 2002-2016 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;
018
019import reactor.core.publisher.Mono;
020
021import org.springframework.web.server.ServerWebExchange;
022
023/**
024 * Interface to be implemented by objects that define a mapping between
025 * requests and handler objects.
026 *
027 * @author Rossen Stoyanchev
028 * @author Sebastien Deleuze
029 * @since 5.0
030 */
031public interface HandlerMapping {
032
033        /**
034         * Name of the {@link ServerWebExchange#getAttributes() attribute} that
035         * contains the mapped handler for the best matching pattern.
036         */
037        String BEST_MATCHING_HANDLER_ATTRIBUTE = HandlerMapping.class.getName() + ".bestMatchingHandler";
038
039        /**
040         * Name of the {@link ServerWebExchange#getAttributes() attribute} that
041         * contains the best matching pattern within the handler mapping.
042         */
043        String BEST_MATCHING_PATTERN_ATTRIBUTE = HandlerMapping.class.getName() + ".bestMatchingPattern";
044
045        /**
046         * Name of the {@link ServerWebExchange#getAttributes() attribute} that
047         * contains the path within the handler mapping, in case of a pattern match
048         * such as {@code "/static/**"} or the full relevant URI otherwise.
049         * <p>Note: This attribute is not required to be supported by all
050         * HandlerMapping implementations. URL-based HandlerMappings will
051         * typically support it but handlers should not necessarily expect
052         * this request attribute to be present in all scenarios.
053         */
054        String PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE = HandlerMapping.class.getName() + ".pathWithinHandlerMapping";
055
056        /**
057         * Name of the {@link ServerWebExchange#getAttributes() attribute} that
058         * contains the URI templates map mapping variable names to values.
059         * <p>Note: This attribute is not required to be supported by all
060         * HandlerMapping implementations. URL-based HandlerMappings will
061         * typically support it, but handlers should not necessarily expect
062         * this request attribute to be present in all scenarios.
063         */
064        String URI_TEMPLATE_VARIABLES_ATTRIBUTE = HandlerMapping.class.getName() + ".uriTemplateVariables";
065
066        /**
067         * Name of the {@link ServerWebExchange#getAttributes() attribute} that
068         * contains a map with URI variable names and a corresponding MultiValueMap
069         * of URI matrix variables for each.
070         * <p>Note: This attribute is not required to be supported by all
071         * HandlerMapping implementations and may also not be present depending on
072         * whether the HandlerMapping is configured to keep matrix variable content
073         * in the request URI.
074         */
075        String MATRIX_VARIABLES_ATTRIBUTE = HandlerMapping.class.getName() + ".matrixVariables";
076
077        /**
078         * Name of the {@link ServerWebExchange#getAttributes() attribute} containing
079         * the set of producible MediaType's applicable to the mapped handler.
080         * <p>Note: This attribute is not required to be supported by all
081         * HandlerMapping implementations. Handlers should not necessarily expect
082         * this request attribute to be present in all scenarios.
083         */
084        String PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE = HandlerMapping.class.getName() + ".producibleMediaTypes";
085
086
087        /**
088         * Return a handler for this request.
089         * @param exchange current server exchange
090         * @return a {@link Mono} that emits one value or none in case the request
091         * cannot be resolved to a handler
092         */
093        Mono<Object> getHandler(ServerWebExchange exchange);
094
095}