001/* 002 * Copyright 2002-2015 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 */ 016package org.springframework.web.servlet.mvc.method.annotation; 017 018import java.io.IOException; 019import java.lang.reflect.Type; 020 021import org.springframework.core.MethodParameter; 022import org.springframework.http.HttpInputMessage; 023import org.springframework.http.converter.HttpMessageConverter; 024 025/** 026 * A convenient starting point for implementing 027 * {@link org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice 028 * ResponseBodyAdvice} with default method implementations. 029 * 030 * <p>Sub-classes are required to implement {@link #supports} to return true 031 * depending on when the advice applies. 032 * 033 * @author Rossen Stoyanchev 034 * @since 4.2 035 */ 036public abstract class RequestBodyAdviceAdapter implements RequestBodyAdvice { 037 038 /** 039 * The default implementation returns the body that was passed in. 040 */ 041 @Override 042 public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, 043 MethodParameter parameter, Type targetType, 044 Class<? extends HttpMessageConverter<?>> converterType) { 045 046 return body; 047 } 048 049 /** 050 * The default implementation returns the InputMessage that was passed in. 051 */ 052 @Override 053 public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, 054 Type targetType, Class<? extends HttpMessageConverter<?>> converterType) 055 throws IOException { 056 057 return inputMessage; 058 } 059 060 /** 061 * The default implementation returns the body that was passed in. 062 */ 063 @Override 064 public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, 065 Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { 066 067 return body; 068 } 069 070}