001/*
002 * Copyright 2002-2017 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.messaging.handler.invocation;
018
019import org.springframework.core.MethodParameter;
020import org.springframework.messaging.Message;
021
022/**
023 * Strategy interface to handle the value returned from the invocation of a
024 * method handling a {@link Message}.
025 *
026 * @author Rossen Stoyanchev
027 * @since 4.0
028 */
029public interface HandlerMethodReturnValueHandler {
030
031        /**
032         * Whether the given {@linkplain MethodParameter method return type} is
033         * supported by this handler.
034         * @param returnType the method return type to check
035         * @return {@code true} if this handler supports the supplied return type;
036         * {@code false} otherwise
037         */
038        boolean supportsReturnType(MethodParameter returnType);
039
040        /**
041         * Handle the given return value.
042         * @param returnValue the value returned from the handler method
043         * @param returnType the type of the return value. This type must have previously
044         * been passed to {@link #supportsReturnType(org.springframework.core.MethodParameter)}
045         * and it must have returned {@code true}.
046         * @param message the message that caused this method to be called
047         * @throws Exception if the return value handling results in an error
048         */
049        void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message)
050                        throws Exception;
051
052}