Move spring.http.* config properties namespace

Closes gh-18827
pull/19711/head
Brian Clozel 5 years ago
parent 7f6b01c3d2
commit 711391cf2f

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,6 +28,11 @@ import org.springframework.util.unit.DataSize;
@ConfigurationProperties(prefix = "spring.codec") @ConfigurationProperties(prefix = "spring.codec")
public class CodecProperties { public class CodecProperties {
/**
* Whether to log form data at DEBUG level, and headers at TRACE level.
*/
private boolean logRequestDetails;
/** /**
* Limit on the number of bytes that can be buffered whenever the input stream needs * Limit on the number of bytes that can be buffered whenever the input stream needs
* to be aggregated. By default this is not set, in which case individual codec * to be aggregated. By default this is not set, in which case individual codec
@ -35,6 +40,14 @@ public class CodecProperties {
*/ */
private DataSize maxInMemorySize; private DataSize maxInMemorySize;
public boolean isLogRequestDetails() {
return this.logRequestDetails;
}
public void setLogRequestDetails(boolean logRequestDetails) {
this.logRequestDetails = logRequestDetails;
}
public DataSize getMaxInMemorySize() { public DataSize getMaxInMemorySize() {
return this.maxInMemorySize; return this.maxInMemorySize;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration.NotReactiveWebApplicationCondition; import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration.NotReactiveWebApplicationCondition;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration; import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Conditional;
@ -60,7 +61,7 @@ import org.springframework.http.converter.StringHttpMessageConverter;
JsonbHttpMessageConvertersConfiguration.class }) JsonbHttpMessageConvertersConfiguration.class })
public class HttpMessageConvertersAutoConfiguration { public class HttpMessageConvertersAutoConfiguration {
static final String PREFERRED_MAPPER_PROPERTY = "spring.http.converters.preferred-json-mapper"; static final String PREFERRED_MAPPER_PROPERTY = "spring.mvc.converters.preferred-json-mapper";
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ -70,14 +71,14 @@ public class HttpMessageConvertersAutoConfiguration {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(StringHttpMessageConverter.class) @ConditionalOnClass(StringHttpMessageConverter.class)
@EnableConfigurationProperties(HttpProperties.class) @EnableConfigurationProperties(ServerProperties.class)
protected static class StringHttpMessageConverterConfiguration { protected static class StringHttpMessageConverterConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public StringHttpMessageConverter stringHttpMessageConverter(HttpProperties httpProperties) { public StringHttpMessageConverter stringHttpMessageConverter(ServerProperties serverProperties) {
StringHttpMessageConverter converter = new StringHttpMessageConverter( StringHttpMessageConverter converter = new StringHttpMessageConverter(
httpProperties.getEncoding().getCharset()); serverProperties.getServlet().getEncoding().getCharset());
converter.setWriteAcceptCharset(false); converter.setWriteAcceptCharset(false);
return converter; return converter;
} }

@ -1,154 +0,0 @@
/*
* Copyright 2012-2019 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
*
* https://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.boot.autoconfigure.http;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* HTTP properties.
*
* @author Phillip Webb
* @author Stephane Nicoll
* @author Brian Clozel
* @since 2.1.0
*/
@ConfigurationProperties(prefix = "spring.http")
public class HttpProperties {
/**
* Whether logging of (potentially sensitive) request details at DEBUG and TRACE level
* is allowed.
*/
private boolean logRequestDetails;
/**
* HTTP encoding properties.
*/
private final Encoding encoding = new Encoding();
public boolean isLogRequestDetails() {
return this.logRequestDetails;
}
public void setLogRequestDetails(boolean logRequestDetails) {
this.logRequestDetails = logRequestDetails;
}
public Encoding getEncoding() {
return this.encoding;
}
/**
* Configuration properties for http encoding.
*/
public static class Encoding {
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
/**
* Charset of HTTP requests and responses. Added to the "Content-Type" header if
* not set explicitly.
*/
private Charset charset = DEFAULT_CHARSET;
/**
* Whether to force the encoding to the configured charset on HTTP requests and
* responses.
*/
private Boolean force;
/**
* Whether to force the encoding to the configured charset on HTTP requests.
* Defaults to true when "force" has not been specified.
*/
private Boolean forceRequest;
/**
* Whether to force the encoding to the configured charset on HTTP responses.
*/
private Boolean forceResponse;
/**
* Locale in which to encode mapping.
*/
private Map<Locale, Charset> mapping;
public Charset getCharset() {
return this.charset;
}
public void setCharset(Charset charset) {
this.charset = charset;
}
public boolean isForce() {
return Boolean.TRUE.equals(this.force);
}
public void setForce(boolean force) {
this.force = force;
}
public boolean isForceRequest() {
return Boolean.TRUE.equals(this.forceRequest);
}
public void setForceRequest(boolean forceRequest) {
this.forceRequest = forceRequest;
}
public boolean isForceResponse() {
return Boolean.TRUE.equals(this.forceResponse);
}
public void setForceResponse(boolean forceResponse) {
this.forceResponse = forceResponse;
}
public Map<Locale, Charset> getMapping() {
return this.mapping;
}
public void setMapping(Map<Locale, Charset> mapping) {
this.mapping = mapping;
}
public boolean shouldForce(Type type) {
Boolean force = (type != Type.REQUEST) ? this.forceResponse : this.forceRequest;
if (force == null) {
force = this.force;
}
if (force == null) {
force = (type == Type.REQUEST);
}
return force;
}
public enum Type {
REQUEST, RESPONSE
}
}
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.codec.CodecProperties; import org.springframework.boot.autoconfigure.codec.CodecProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.http.HttpProperties;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.PropertyMapper;
@ -49,7 +48,7 @@ import org.springframework.web.reactive.function.client.WebClient;
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ CodecConfigurer.class, WebClient.class }) @ConditionalOnClass({ CodecConfigurer.class, WebClient.class })
@AutoConfigureAfter(JacksonAutoConfiguration.class) @AutoConfigureAfter(JacksonAutoConfiguration.class)
@EnableConfigurationProperties({ HttpProperties.class, CodecProperties.class }) @EnableConfigurationProperties(CodecProperties.class)
public class CodecsAutoConfiguration { public class CodecsAutoConfiguration {
private static final MimeType[] EMPTY_MIME_TYPES = {}; private static final MimeType[] EMPTY_MIME_TYPES = {};
@ -76,11 +75,11 @@ public class CodecsAutoConfiguration {
@Bean @Bean
@Order(0) @Order(0)
CodecCustomizer defaultCodecCustomizer(HttpProperties httpProperties, CodecProperties codecProperties) { CodecCustomizer defaultCodecCustomizer(CodecProperties codecProperties) {
return (configurer) -> { return (configurer) -> {
PropertyMapper map = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get();
CodecConfigurer.DefaultCodecs defaultCodecs = configurer.defaultCodecs(); CodecConfigurer.DefaultCodecs defaultCodecs = configurer.defaultCodecs();
defaultCodecs.enableLoggingRequestDetails(httpProperties.isLogRequestDetails()); defaultCodecs.enableLoggingRequestDetails(codecProperties.isLogRequestDetails());
map.from(codecProperties.getMaxInMemorySize()).whenNonNull().asInt(DataSize::toBytes) map.from(codecProperties.getMaxInMemorySize()).whenNonNull().asInt(DataSize::toBytes)
.to(defaultCodecs::maxInMemorySize); .to(defaultCodecs::maxInMemorySize);
}; };

@ -37,6 +37,7 @@ import org.springframework.boot.convert.DurationUnit;
import org.springframework.boot.web.server.Compression; import org.springframework.boot.web.server.Compression;
import org.springframework.boot.web.server.Http2; import org.springframework.boot.web.server.Http2;
import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.servlet.server.Encoding;
import org.springframework.boot.web.servlet.server.Jsp; import org.springframework.boot.web.servlet.server.Jsp;
import org.springframework.boot.web.servlet.server.Session; import org.springframework.boot.web.servlet.server.Session;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -246,6 +247,9 @@ public class ServerProperties {
*/ */
private String applicationDisplayName = "application"; private String applicationDisplayName = "application";
@NestedConfigurationProperty
private final Encoding encoding = new Encoding();
@NestedConfigurationProperty @NestedConfigurationProperty
private final Jsp jsp = new Jsp(); private final Jsp jsp = new Jsp();
@ -280,6 +284,10 @@ public class ServerProperties {
return this.contextParameters; return this.contextParameters;
} }
public Encoding getEncoding() {
return this.encoding;
}
public Jsp getJsp() { public Jsp getJsp() {
return this.jsp; return this.jsp;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.http.HttpProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@ -83,17 +82,17 @@ public class DispatcherServletAutoConfiguration {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@Conditional(DefaultDispatcherServletCondition.class) @Conditional(DefaultDispatcherServletCondition.class)
@ConditionalOnClass(ServletRegistration.class) @ConditionalOnClass(ServletRegistration.class)
@EnableConfigurationProperties({ HttpProperties.class, WebMvcProperties.class }) @EnableConfigurationProperties(WebMvcProperties.class)
protected static class DispatcherServletConfiguration { protected static class DispatcherServletConfiguration {
@Bean(name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME) @Bean(name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
public DispatcherServlet dispatcherServlet(HttpProperties httpProperties, WebMvcProperties webMvcProperties) { public DispatcherServlet dispatcherServlet(WebMvcProperties webMvcProperties) {
DispatcherServlet dispatcherServlet = new DispatcherServlet(); DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setDispatchOptionsRequest(webMvcProperties.isDispatchOptionsRequest()); dispatcherServlet.setDispatchOptionsRequest(webMvcProperties.isDispatchOptionsRequest());
dispatcherServlet.setDispatchTraceRequest(webMvcProperties.isDispatchTraceRequest()); dispatcherServlet.setDispatchTraceRequest(webMvcProperties.isDispatchTraceRequest());
dispatcherServlet.setThrowExceptionIfNoHandlerFound(webMvcProperties.isThrowExceptionIfNoHandlerFound()); dispatcherServlet.setThrowExceptionIfNoHandlerFound(webMvcProperties.isThrowExceptionIfNoHandlerFound());
dispatcherServlet.setPublishEvents(webMvcProperties.isPublishRequestHandledEvents()); dispatcherServlet.setPublishEvents(webMvcProperties.isPublishRequestHandledEvents());
dispatcherServlet.setEnableLoggingRequestDetails(httpProperties.isLogRequestDetails()); dispatcherServlet.setEnableLoggingRequestDetails(webMvcProperties.isLogRequestDetails());
return dispatcherServlet; return dispatcherServlet;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,12 +21,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.http.HttpProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.http.HttpProperties.Encoding.Type;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.server.Encoding;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
@ -41,16 +41,16 @@ import org.springframework.web.filter.CharacterEncodingFilter;
* @since 2.0.0 * @since 2.0.0
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(HttpProperties.class) @EnableConfigurationProperties(ServerProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass(CharacterEncodingFilter.class) @ConditionalOnClass(CharacterEncodingFilter.class)
@ConditionalOnProperty(prefix = "spring.http.encoding", value = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "server.servlet.encoding", value = "enabled", matchIfMissing = true)
public class HttpEncodingAutoConfiguration { public class HttpEncodingAutoConfiguration {
private final HttpProperties.Encoding properties; private final Encoding properties;
public HttpEncodingAutoConfiguration(HttpProperties properties) { public HttpEncodingAutoConfiguration(ServerProperties properties) {
this.properties = properties.getEncoding(); this.properties = properties.getServlet().getEncoding();
} }
@Bean @Bean
@ -58,8 +58,8 @@ public class HttpEncodingAutoConfiguration {
public CharacterEncodingFilter characterEncodingFilter() { public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter(); CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
filter.setEncoding(this.properties.getCharset().name()); filter.setEncoding(this.properties.getCharset().name());
filter.setForceRequestEncoding(this.properties.shouldForce(Type.REQUEST)); filter.setForceRequestEncoding(this.properties.shouldForce(Encoding.Type.REQUEST));
filter.setForceResponseEncoding(this.properties.shouldForce(Type.RESPONSE)); filter.setForceResponseEncoding(this.properties.shouldForce(Encoding.Type.RESPONSE));
return filter; return filter;
} }
@ -71,9 +71,9 @@ public class HttpEncodingAutoConfiguration {
static class LocaleCharsetMappingsCustomizer static class LocaleCharsetMappingsCustomizer
implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>, Ordered { implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>, Ordered {
private final HttpProperties.Encoding properties; private final Encoding properties;
LocaleCharsetMappingsCustomizer(HttpProperties.Encoding properties) { LocaleCharsetMappingsCustomizer(Encoding properties) {
this.properties = properties; this.properties = properties;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -87,6 +87,12 @@ public class WebMvcProperties {
*/ */
private boolean throwExceptionIfNoHandlerFound = false; private boolean throwExceptionIfNoHandlerFound = false;
/**
* Whether logging of (potentially sensitive) request details at DEBUG and TRACE level
* is allowed.
*/
private boolean logRequestDetails;
/** /**
* Whether to enable warn logging of exceptions resolved by a * Whether to enable warn logging of exceptions resolved by a
* "HandlerExceptionResolver", except for "DefaultHandlerExceptionResolver". * "HandlerExceptionResolver", except for "DefaultHandlerExceptionResolver".
@ -164,6 +170,14 @@ public class WebMvcProperties {
this.throwExceptionIfNoHandlerFound = throwExceptionIfNoHandlerFound; this.throwExceptionIfNoHandlerFound = throwExceptionIfNoHandlerFound;
} }
public boolean isLogRequestDetails() {
return this.logRequestDetails;
}
public void setLogRequestDetails(boolean logRequestDetails) {
this.logRequestDetails = logRequestDetails;
}
public boolean isLogResolvedException() { public boolean isLogResolvedException() {
return this.logResolvedException; return this.logResolvedException;
} }

@ -473,16 +473,94 @@
"defaultValue": ".tpl" "defaultValue": ".tpl"
}, },
{ {
"name": "spring.http.encoding.enabled", "name": "server.servlet.encoding.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Whether to enable http encoding support.", "description": "Whether to enable http encoding support.",
"defaultValue": true "defaultValue": true
}, },
{ {
"name": "spring.http.converters.preferred-json-mapper", "name": "spring.http.encoding.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable http encoding support.",
"defaultValue": true,
"deprecation" : {
"replacement" : "server.servlet.encoding.enabled",
"level" : "error"
}
},
{
"name" : "spring.http.encoding.charset",
"type": "java.nio.charset.Charset",
"description" : "Charset of HTTP requests and responses. Added to the Content-Type header if not set explicitly.",
"deprecation" : {
"replacement" : "server.servlet.encoding.charset",
"level" : "error"
}
},
{
"name": "spring.http.encoding.force",
"type": "java.lang.Boolean",
"description": "Whether to force the encoding to the configured charset on HTTP requests and responses.",
"defaultValue": false,
"deprecation" : {
"replacement" : "server.servlet.encoding.force",
"level" : "error"
}
},
{
"name": "spring.http.encoding.force-request",
"type": "java.lang.Boolean",
"description": "Whether to force the encoding to the configured charset on HTTP requests. Defaults to true when force has not been specified.",
"defaultValue": true,
"deprecation" : {
"replacement" : "server.servlet.encoding.force-request",
"level" : "error"
}
},
{
"name": "spring.http.encoding.force-response",
"type": "java.lang.Boolean",
"description": "Whether to force the encoding to the configured charset on HTTP responses.",
"defaultValue": false,
"deprecation" : {
"replacement" : "server.servlet.encoding.force-response",
"level" : "error"
}
},
{
"name" : "spring.http.encoding.mapping",
"type" : "java.util.Map<java.util.Locale,java.nio.charset.Charset>",
"description" : "Locale in which to encode mapping.",
"deprecation" : {
"replacement" : "server.servlet.encoding.mapping",
"level" : "error"
}
},
{
"name": "spring.http.log-request-details",
"type": "java.lang.Boolean",
"description": "Whether logging of (potentially sensitive) request details at DEBUG and TRACE level is allowed.",
"defaultValue": false,
"deprecation" : {
"replacement" : "spring.mvc.log-request-details",
"level" : "error"
}
},
{
"name": "spring.mvc.converters.preferred-json-mapper",
"type": "java.lang.String", "type": "java.lang.String",
"description": "Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment." "description": "Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment."
}, },
{
"name": "spring.http.converters.preferred-json-mapper",
"type": "java.lang.String",
"description": "Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment.",
"deprecation" : {
"replacement" : "spring.mvc.converters.preferred-json-mapper",
"level" : "error"
}
},
{ {
"name": "spring.integration.jdbc.initialize-schema", "name": "spring.integration.jdbc.initialize-schema",
"defaultValue": "embedded" "defaultValue": "embedded"
@ -2356,7 +2434,7 @@
] ]
}, },
{ {
"name": "spring.http.converters.preferred-json-mapper", "name": "spring.mvc.converters.preferred-json-mapper",
"values": [ "values": [
{ {
"value": "gson" "value": "gson"

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -121,7 +121,7 @@ class HttpMessageConvertersAutoConfigurationTests {
@Test @Test
void gsonCanBePreferred() { void gsonCanBePreferred() {
allOptionsRunner().withPropertyValues("spring.http.converters.preferred-json-mapper:gson").run((context) -> { allOptionsRunner().withPropertyValues("spring.mvc.converters.preferred-json-mapper:gson").run((context) -> {
assertConverterBeanExists(context, GsonHttpMessageConverter.class, "gsonHttpMessageConverter"); assertConverterBeanExists(context, GsonHttpMessageConverter.class, "gsonHttpMessageConverter");
assertConverterBeanRegisteredWithHttpMessageConverters(context, GsonHttpMessageConverter.class); assertConverterBeanRegisteredWithHttpMessageConverters(context, GsonHttpMessageConverter.class);
assertThat(context).doesNotHaveBean(JsonbHttpMessageConverter.class); assertThat(context).doesNotHaveBean(JsonbHttpMessageConverter.class);
@ -152,7 +152,7 @@ class HttpMessageConvertersAutoConfigurationTests {
@Test @Test
void jsonbCanBePreferred() { void jsonbCanBePreferred() {
allOptionsRunner().withPropertyValues("spring.http.converters.preferred-json-mapper:jsonb").run((context) -> { allOptionsRunner().withPropertyValues("spring.mvc.converters.preferred-json-mapper:jsonb").run((context) -> {
assertConverterBeanExists(context, JsonbHttpMessageConverter.class, "jsonbHttpMessageConverter"); assertConverterBeanExists(context, JsonbHttpMessageConverter.class, "jsonbHttpMessageConverter");
assertConverterBeanRegisteredWithHttpMessageConverters(context, JsonbHttpMessageConverter.class); assertConverterBeanRegisteredWithHttpMessageConverters(context, JsonbHttpMessageConverter.class);
assertThat(context).doesNotHaveBean(GsonHttpMessageConverter.class); assertThat(context).doesNotHaveBean(GsonHttpMessageConverter.class);

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,7 +23,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.codec.CodecProperties; import org.springframework.boot.autoconfigure.codec.CodecProperties;
import org.springframework.boot.autoconfigure.http.HttpProperties;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.codec.CodecCustomizer; import org.springframework.boot.web.codec.CodecCustomizer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -59,7 +58,7 @@ class CodecsAutoConfigurationTests {
@Test @Test
void loggingRequestDetailsCustomizerShouldUseHttpProperties() { void loggingRequestDetailsCustomizerShouldUseHttpProperties() {
this.contextRunner.withPropertyValues("spring.http.log-request-details=true").run((context) -> { this.contextRunner.withPropertyValues("spring.codec.log-request-details=true").run((context) -> {
CodecCustomizer customizer = context.getBean(CodecCustomizer.class); CodecCustomizer customizer = context.getBean(CodecCustomizer.class);
CodecConfigurer configurer = new DefaultClientCodecConfigurer(); CodecConfigurer configurer = new DefaultClientCodecConfigurer();
customizer.customize(configurer); customizer.customize(configurer);
@ -72,7 +71,7 @@ class CodecsAutoConfigurationTests {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
Method customizerMethod = ReflectionUtils.findMethod( Method customizerMethod = ReflectionUtils.findMethod(
CodecsAutoConfiguration.DefaultCodecsConfiguration.class, "defaultCodecCustomizer", CodecsAutoConfiguration.DefaultCodecsConfiguration.class, "defaultCodecCustomizer",
HttpProperties.class, CodecProperties.class); CodecProperties.class);
Integer order = new TestAnnotationAwareOrderComparator().findOrder(customizerMethod); Integer order = new TestAnnotationAwareOrderComparator().findOrder(customizerMethod);
assertThat(order).isEqualTo(0); assertThat(order).isEqualTo(0);
}); });

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,49 +69,53 @@ class HttpEncodingAutoConfigurationTests {
@Test @Test
void disableConfiguration() { void disableConfiguration() {
load(EmptyConfiguration.class, "spring.http.encoding.enabled:false"); load(EmptyConfiguration.class, "server.servlet.encoding.enabled:false");
assertThatExceptionOfType(NoSuchBeanDefinitionException.class) assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(CharacterEncodingFilter.class)); .isThrownBy(() -> this.context.getBean(CharacterEncodingFilter.class));
} }
@Test @Test
void customConfiguration() { void customConfiguration() {
load(EmptyConfiguration.class, "spring.http.encoding.charset:ISO-8859-15", "spring.http.encoding.force:false"); load(EmptyConfiguration.class, "server.servlet.encoding.charset:ISO-8859-15",
"server.servlet.encoding.force:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class); CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "ISO-8859-15", false, false); assertCharacterEncodingFilter(filter, "ISO-8859-15", false, false);
} }
@Test @Test
void customFilterConfiguration() { void customFilterConfiguration() {
load(FilterConfiguration.class, "spring.http.encoding.charset:ISO-8859-15", "spring.http.encoding.force:false"); load(FilterConfiguration.class, "server.servlet.encoding.charset:ISO-8859-15",
"server.servlet.encoding.force:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class); CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "US-ASCII", false, false); assertCharacterEncodingFilter(filter, "US-ASCII", false, false);
} }
@Test @Test
void forceRequest() { void forceRequest() {
load(EmptyConfiguration.class, "spring.http.encoding.force-request:false"); load(EmptyConfiguration.class, "server.servlet.encoding.force-request:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class); CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", false, false); assertCharacterEncodingFilter(filter, "UTF-8", false, false);
} }
@Test @Test
void forceResponse() { void forceResponse() {
load(EmptyConfiguration.class, "spring.http.encoding.force-response:true"); load(EmptyConfiguration.class, "server.servlet.encoding.force-response:true");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class); CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", true, true); assertCharacterEncodingFilter(filter, "UTF-8", true, true);
} }
@Test @Test
void forceRequestOverridesForce() { void forceRequestOverridesForce() {
load(EmptyConfiguration.class, "spring.http.encoding.force:true", "spring.http.encoding.force-request:false"); load(EmptyConfiguration.class, "server.servlet.encoding.force:true",
"server.servlet.encoding.force-request:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class); CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", false, true); assertCharacterEncodingFilter(filter, "UTF-8", false, true);
} }
@Test @Test
void forceResponseOverridesForce() { void forceResponseOverridesForce() {
load(EmptyConfiguration.class, "spring.http.encoding.force:true", "spring.http.encoding.force-response:false"); load(EmptyConfiguration.class, "server.servlet.encoding.force:true",
"server.servlet.encoding.force-response:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class); CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", true, false); assertCharacterEncodingFilter(filter, "UTF-8", true, false);
} }
@ -135,8 +139,8 @@ class HttpEncodingAutoConfigurationTests {
@Test @Test
void customLocaleCharsetMappings() { void customLocaleCharsetMappings() {
load(EmptyConfiguration.class, "spring.http.encoding.mapping.en:UTF-8", load(EmptyConfiguration.class, "server.servlet.encoding.mapping.en:UTF-8",
"spring.http.encoding.mapping.fr_FR:UTF-8"); "server.servlet.encoding.mapping.fr_FR:UTF-8");
Map<String, WebServerFactoryCustomizer<?>> beans = getWebServerFactoryCustomizerBeans(); Map<String, WebServerFactoryCustomizer<?>> beans = getWebServerFactoryCustomizerBeans();
assertThat(beans.size()).isEqualTo(1); assertThat(beans.size()).isEqualTo(1);
assertThat(this.context.getBean(MockServletWebServerFactory.class).getLocaleCharsetMappings().size()) assertThat(this.context.getBean(MockServletWebServerFactory.class).getLocaleCharsetMappings().size())

@ -689,7 +689,7 @@ Rather than needing to set these properties manually, the `spring-boot-devtools`
Because you need more information about web requests while developing Spring MVC and Spring WebFlux applications, developer tools will enable `DEBUG` logging for the `web` logging group. Because you need more information about web requests while developing Spring MVC and Spring WebFlux applications, developer tools will enable `DEBUG` logging for the `web` logging group.
This will give you information about the incoming request, which handler is processing it, the response outcome, etc. This will give you information about the incoming request, which handler is processing it, the response outcome, etc.
If you wish to log all request details (including potentially sensitive information), you can turn on the configprop:spring.http.log-request-details[] configuration property. If you wish to log all request details (including potentially sensitive information), you can turn on the configprop:spring.mvc.log-request-details[] or configprop:spring.codec.log-request-details[] configuration properties.
NOTE: If you don't want property defaults to be applied you can set configprop:spring.devtools.add-properties[] to `false` in your `application.properties`. NOTE: If you don't want property defaults to be applied you can set configprop:spring.devtools.add-properties[] to `false` in your `application.properties`.

@ -36,7 +36,7 @@ def generateConfigMetadataDocumentation() {
.withKeyPrefixes("server") .withKeyPrefixes("server")
.addSection("web") .addSection("web")
.withKeyPrefixes("spring.hateoas", .withKeyPrefixes("spring.hateoas",
"spring.http", "spring.servlet", "spring.jersey", "spring.servlet", "spring.jersey",
"spring.mvc", "spring.resources", "spring.webflux") "spring.mvc", "spring.resources", "spring.webflux")
.addSection("json") .addSection("json")
.withKeyPrefixes("spring.jackson", "spring.gson") .withKeyPrefixes("spring.jackson", "spring.gson")

@ -0,0 +1,134 @@
/*
* Copyright 2012-2020 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
*
* https://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.boot.web.servlet.server;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
/**
* Configuration properties for server HTTP encoding.
*
* @author Phillip Webb
* @author Stephane Nicoll
* @author Brian Clozel
* @since 2.3.0
*/
public class Encoding {
/**
* Default HTTP encoding for Servlet applications.
*/
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
/**
* Charset of HTTP requests and responses. Added to the "Content-Type" header if not
* set explicitly.
*/
private Charset charset = DEFAULT_CHARSET;
/**
* Whether to force the encoding to the configured charset on HTTP requests and
* responses.
*/
private Boolean force;
/**
* Whether to force the encoding to the configured charset on HTTP requests. Defaults
* to true when "force" has not been specified.
*/
private Boolean forceRequest;
/**
* Whether to force the encoding to the configured charset on HTTP responses.
*/
private Boolean forceResponse;
/**
* Locale in which to encode mapping.
*/
private Map<Locale, Charset> mapping;
public Charset getCharset() {
return this.charset;
}
public void setCharset(Charset charset) {
this.charset = charset;
}
public boolean isForce() {
return Boolean.TRUE.equals(this.force);
}
public void setForce(boolean force) {
this.force = force;
}
public boolean isForceRequest() {
return Boolean.TRUE.equals(this.forceRequest);
}
public void setForceRequest(boolean forceRequest) {
this.forceRequest = forceRequest;
}
public boolean isForceResponse() {
return Boolean.TRUE.equals(this.forceResponse);
}
public void setForceResponse(boolean forceResponse) {
this.forceResponse = forceResponse;
}
public Map<Locale, Charset> getMapping() {
return this.mapping;
}
public void setMapping(Map<Locale, Charset> mapping) {
this.mapping = mapping;
}
public boolean shouldForce(Type type) {
Boolean force = (type != Type.REQUEST) ? this.forceResponse : this.forceRequest;
if (force == null) {
force = this.force;
}
if (force == null) {
force = (type == Type.REQUEST);
}
return force;
}
/**
* Type of HTTP message to consider for encoding configuration.
*/
public enum Type {
/**
* HTTP request message.
*/
REQUEST,
/**
* HTTP response message.
*/
RESPONSE
}
}
Loading…
Cancel
Save