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