HandlerAdapter.java 2.2 KB
Newer Older
1
/*
2
 * Copyright 2002-2016 the original author or authors.
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
A
Arjen Poutsma 已提交
16

17
package org.springframework.web.reactive;
18

R
Rossen Stoyanchev 已提交
19 20
import java.util.function.Function;

21
import reactor.core.publisher.Mono;
22

23
import org.springframework.web.server.ServerWebExchange;
R
Rossen Stoyanchev 已提交
24

25
/**
R
Rossen Stoyanchev 已提交
26 27
 * Contract that decouples the {@link DispatcherHandler} from the details of
 * invoking a handler and makes it possible to support any handler type.
28
 *
29
 * @author Rossen Stoyanchev
30
 * @author Sebastien Deleuze
31
 * @since 5.0
32 33 34
 */
public interface HandlerAdapter {

35
	/**
R
Rossen Stoyanchev 已提交
36
	 * Whether this {@code HandlerAdapter} supports the given {@code handler}.
37
	 * @param handler handler object to check
R
Rossen Stoyanchev 已提交
38
	 * @return whether or not the handler is supported
39
	 */
40 41
	boolean supports(Object handler);

42
	/**
R
Rossen Stoyanchev 已提交
43 44 45 46 47 48 49 50 51
	 * Handle the request with the given handler.
	 * <p>Implementations are encouraged to handle exceptions resulting from the
	 * invocation of a handler in order and if necessary to return an alternate
	 * result that represents an error response.
	 * <p>Furthermore since an async {@code HandlerResult} may produce an error
	 * later during result handling implementations are also encouraged to
	 * {@link HandlerResult#setExceptionHandler(Function) set an exception
	 * handler} on the {@code HandlerResult} so that may also be applied later
	 * after result handling.
R
Rossen Stoyanchev 已提交
52
	 * @param exchange current server exchange
R
Rossen Stoyanchev 已提交
53 54 55 56
	 * @param handler the selected handler which must have been previously
	 * checked via {@link #supports(Object)}
	 * @return {@link Mono} that emits a single {@code HandlerResult} or none if
	 * the request has been fully handled and doesn't require further handling.
57
	 */
58
	Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler);
59 60

}