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.Decoder; 020import org.springframework.core.codec.Encoder; 021 022/** 023 * Extension of {@link CodecConfigurer} for HTTP message reader and writer 024 * options relevant on the client side. 025 * 026 * <p>HTTP message readers for the following are registered by default: 027 * <ul>{@code byte[]} 028 * <li>{@link java.nio.ByteBuffer} 029 * <li>{@link org.springframework.core.io.buffer.DataBuffer DataBuffer} 030 * <li>{@link org.springframework.core.io.Resource Resource} 031 * <li>{@link String} 032 * <li>{@link org.springframework.util.MultiValueMap 033 * MultiValueMap<String,String>} for form data 034 * <li>JSON and Smile, if Jackson is present 035 * <li>XML, if JAXB2 is present 036 * <li>Server-Sent Events 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<String,String>} for form data 047 * <li>{@link org.springframework.util.MultiValueMap 048 * MultiValueMap<String,Object>} for multipart data 049 * <li>JSON and Smile, if Jackson is present 050 * <li>XML, if JAXB2 is present 051 * </ul> 052 * 053 * @author Rossen Stoyanchev 054 * @since 5.0 055 */ 056public interface ClientCodecConfigurer extends CodecConfigurer { 057 058 /** 059 * {@inheritDoc} 060 * <p>On the client side, built-in default also include customizations related 061 * to multipart readers and writers, as well as the decoder for SSE. 062 */ 063 @Override 064 ClientDefaultCodecs defaultCodecs(); 065 066 /** 067 * {@inheritDoc}. 068 */ 069 @Override 070 ClientCodecConfigurer clone(); 071 072 073 /** 074 * Static factory method for a {@code ClientCodecConfigurer}. 075 */ 076 static ClientCodecConfigurer create() { 077 return CodecConfigurerFactory.create(ClientCodecConfigurer.class); 078 } 079 080 081 /** 082 * {@link CodecConfigurer.DefaultCodecs} extension with extra client-side options. 083 */ 084 interface ClientDefaultCodecs extends DefaultCodecs { 085 086 /** 087 * Configure encoders or writers for use with 088 * {@link org.springframework.http.codec.multipart.MultipartHttpMessageWriter 089 * MultipartHttpMessageWriter}. 090 */ 091 MultipartCodecs multipartCodecs(); 092 093 /** 094 * Configure the {@code Decoder} to use for Server-Sent Events. 095 * <p>By default if this is not set, and Jackson is available, the 096 * {@link #jackson2JsonDecoder} override is used instead. Use this property 097 * if you want to further customize the SSE decoder. 098 * <p>Note that {@link #maxInMemorySize(int)}, if configured, will be 099 * applied to the given decoder. 100 * @param decoder the decoder to use 101 */ 102 void serverSentEventDecoder(Decoder<?> decoder); 103 } 104 105 106 /** 107 * Registry and container for multipart HTTP message writers. 108 */ 109 interface MultipartCodecs { 110 111 /** 112 * Add a Part {@code Encoder}, internally wrapped with 113 * {@link EncoderHttpMessageWriter}. 114 * @param encoder the encoder to add 115 */ 116 MultipartCodecs encoder(Encoder<?> encoder); 117 118 /** 119 * Add a Part {@link HttpMessageWriter}. For writers of type 120 * {@link EncoderHttpMessageWriter} consider using the shortcut 121 * {@link #encoder(Encoder)} instead. 122 * @param writer the writer to add 123 */ 124 MultipartCodecs writer(HttpMessageWriter<?> writer); 125 } 126 127}