001/* 002 * Copyright 2002-2018 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.web.reactive.function; 018 019import java.util.List; 020import java.util.Map; 021import java.util.Optional; 022 023import org.springframework.http.ReactiveHttpInputMessage; 024import org.springframework.http.codec.HttpMessageReader; 025import org.springframework.http.server.reactive.ServerHttpResponse; 026 027/** 028 * A function that can extract data from a {@link ReactiveHttpInputMessage} body. 029 * 030 * @author Arjen Poutsma 031 * @since 5.0 032 * @param <T> the type of data to extract 033 * @param <M> the type of {@link ReactiveHttpInputMessage} this extractor can be applied to 034 * @see BodyExtractors 035 */ 036@FunctionalInterface 037public interface BodyExtractor<T, M extends ReactiveHttpInputMessage> { 038 039 /** 040 * Extract from the given input message. 041 * @param inputMessage the request to extract from 042 * @param context the configuration to use 043 * @return the extracted data 044 */ 045 T extract(M inputMessage, Context context); 046 047 048 /** 049 * Defines the context used during the extraction. 050 */ 051 interface Context { 052 053 /** 054 * Return the {@link HttpMessageReader HttpMessageReaders} to be used for body extraction. 055 * @return the stream of message readers 056 */ 057 List<HttpMessageReader<?>> messageReaders(); 058 059 /** 060 * Optionally return the {@link ServerHttpResponse}, if present. 061 */ 062 Optional<ServerHttpResponse> serverResponse(); 063 064 /** 065 * Return the map of hints to use to customize body extraction. 066 */ 067 Map<String, Object> hints(); 068 } 069 070}