001/*
002 * Copyright 2002-2019 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.http.codec;
018
019import org.springframework.core.codec.Encoder;
020
021/**
022 * Extension of {@link CodecConfigurer} for HTTP message reader and writer
023 * options relevant on the server side.
024 *
025 * <p>HTTP message readers for the following are registered by default:
026 * <ul>{@code byte[]}
027 * <li>{@link java.nio.ByteBuffer}
028 * <li>{@link org.springframework.core.io.buffer.DataBuffer DataBuffer}
029 * <li>{@link org.springframework.core.io.Resource Resource}
030 * <li>{@link String}
031 * <li>{@link org.springframework.util.MultiValueMap
032 * MultiValueMap&lt;String,String&gt;} for form data
033 * <li>{@link org.springframework.util.MultiValueMap
034 * MultiValueMap&lt;String,Object&gt;} for multipart data
035 * <li>JSON and Smile, if Jackson is present
036 * <li>XML, if JAXB2 is present
037 * </ul>
038 *
039 * <p>HTTP message writers registered by default:
040 * <ul>{@code byte[]}
041 * <li>{@link java.nio.ByteBuffer}
042 * <li>{@link org.springframework.core.io.buffer.DataBuffer DataBuffer}
043 * <li>{@link org.springframework.core.io.Resource Resource}
044 * <li>{@link String}
045 * <li>{@link org.springframework.util.MultiValueMap
046 * MultiValueMap&lt;String,String&gt;} for form data
047 * <li>JSON and Smile, if Jackson is present
048 * <li>XML, if JAXB2 is present
049 * <li>Server-Sent Events
050 * </ul>
051 *
052 * @author Rossen Stoyanchev
053 * @since 5.0
054 */
055public interface ServerCodecConfigurer extends CodecConfigurer {
056
057        /**
058         * {@inheritDoc}
059         * <p>On the server side, built-in default also include customizations
060         * related to the encoder for SSE.
061         */
062        @Override
063        ServerDefaultCodecs defaultCodecs();
064
065        /**
066         * {@inheritDoc}.
067         */
068        @Override
069        ServerCodecConfigurer clone();
070
071
072        /**
073         * Static factory method for a {@code ServerCodecConfigurer}.
074         */
075        static ServerCodecConfigurer create() {
076                return CodecConfigurerFactory.create(ServerCodecConfigurer.class);
077        }
078
079
080        /**
081         * {@link CodecConfigurer.DefaultCodecs} extension with extra client-side options.
082         */
083        interface ServerDefaultCodecs extends DefaultCodecs {
084
085                /**
086                 * Configure the {@code HttpMessageReader} to use for multipart requests.
087                 * <p>By default, if
088                 * <a href="https://github.com/synchronoss/nio-multipart">Synchronoss NIO Multipart</a>
089                 * is present, this is set to
090                 * {@link org.springframework.http.codec.multipart.MultipartHttpMessageReader
091                 * MultipartHttpMessageReader} created with an instance of
092                 * {@link org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader
093                 * SynchronossPartHttpMessageReader}.
094                 * <p>Note that {@link #maxInMemorySize(int)} and/or
095                 * {@link #enableLoggingRequestDetails(boolean)}, if configured, will be
096                 * applied to the given reader, if applicable.
097                 * @param reader the message reader to use for multipart requests.
098                 * @since 5.1.11
099                 */
100                void multipartReader(HttpMessageReader<?> reader);
101
102                /**
103                 * Configure the {@code Encoder} to use for Server-Sent Events.
104                 * <p>By default if this is not set, and Jackson is available, the
105                 * {@link #jackson2JsonEncoder} override is used instead. Use this method
106                 * to customize the SSE encoder.
107                 */
108                void serverSentEventEncoder(Encoder<?> encoder);
109        }
110
111}