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.support; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.springframework.http.codec.ClientCodecConfigurer; 023import org.springframework.http.codec.HttpMessageWriter; 024 025/** 026 * Default implementation of {@link ClientCodecConfigurer}. 027 * 028 * @author Rossen Stoyanchev 029 * @since 5.0 030 */ 031public class DefaultClientCodecConfigurer extends BaseCodecConfigurer implements ClientCodecConfigurer { 032 033 034 public DefaultClientCodecConfigurer() { 035 super(new ClientDefaultCodecsImpl()); 036 ((ClientDefaultCodecsImpl) defaultCodecs()).setPartWritersSupplier(this::getPartWriters); 037 } 038 039 private DefaultClientCodecConfigurer(DefaultClientCodecConfigurer other) { 040 super(other); 041 ((ClientDefaultCodecsImpl) defaultCodecs()).setPartWritersSupplier(this::getPartWriters); 042 } 043 044 045 @Override 046 public ClientDefaultCodecs defaultCodecs() { 047 return (ClientDefaultCodecs) super.defaultCodecs(); 048 } 049 050 @Override 051 public DefaultClientCodecConfigurer clone() { 052 return new DefaultClientCodecConfigurer(this); 053 } 054 055 @Override 056 protected BaseDefaultCodecs cloneDefaultCodecs() { 057 return new ClientDefaultCodecsImpl((ClientDefaultCodecsImpl) defaultCodecs()); 058 } 059 060 private List<HttpMessageWriter<?>> getPartWriters() { 061 List<HttpMessageWriter<?>> result = new ArrayList<>(); 062 result.addAll(this.customCodecs.getTypedWriters().keySet()); 063 result.addAll(this.defaultCodecs.getBaseTypedWriters()); 064 result.addAll(this.customCodecs.getObjectWriters().keySet()); 065 result.addAll(this.defaultCodecs.getBaseObjectWriters()); 066 result.addAll(this.defaultCodecs.getCatchAllWriters()); 067 return result; 068 } 069 070}