All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.web.reactive.function.BodyInserter Maven / Gradle / Ivy

/*
 * Copyright 2002-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.reactive.function;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import reactor.core.publisher.Mono;

import org.springframework.http.ReactiveHttpOutputMessage;
import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.server.reactive.ServerHttpRequest;

/**
 * A combination of functions that can populate a {@link ReactiveHttpOutputMessage} body.
 *
 * @author Arjen Poutsma
 * @since 5.0
 * @param  the type of data to insert
 * @param  the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to
 * @see BodyInserters
 */
@FunctionalInterface
public interface BodyInserter {

	/**
	 * Insert into the given output message.
	 * @param outputMessage the response to insert into
	 * @param context the context to use
	 * @return a {@code Mono} that indicates completion or error
	 */
	Mono insert(M outputMessage, Context context);


	/**
	 * Defines the context used during the insertion.
	 */
	interface Context {

		/**
		 * Return the {@link HttpMessageWriter}s to be used for response body conversion.
		 * @return the stream of message writers
		 */
		List> messageWriters();

		/**
		 * Optionally return the {@link ServerHttpRequest}, if present.
		 */
		Optional serverRequest();

		/**
		 * Return the map of hints to use for response body conversion.
		 */
		Map hints();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy