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