Merge branch '1.2.x'
This commit is contained in:
commit
d87f2713af
|
@ -183,7 +183,7 @@ public class AuthenticationManagerConfiguration {
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
ReflectionUtils.setField(field, target, value);
|
ReflectionUtils.setField(field, target, value);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
logger.info("Could not set " + name);
|
logger.info("Could not set " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 the original author or authors.
|
* Copyright 2012-2015 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.
|
||||||
|
@ -50,6 +50,11 @@ import org.springframework.util.StringUtils;
|
||||||
@ConfigurationProperties(prefix = "multipart", ignoreUnknownFields = false)
|
@ConfigurationProperties(prefix = "multipart", ignoreUnknownFields = false)
|
||||||
public class MultipartProperties {
|
public class MultipartProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable multipart upload handling.
|
||||||
|
*/
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intermediate location of uploaded files.
|
* Intermediate location of uploaded files.
|
||||||
*/
|
*/
|
||||||
|
@ -73,32 +78,40 @@ public class MultipartProperties {
|
||||||
*/
|
*/
|
||||||
private String fileSizeThreshold = "0";
|
private String fileSizeThreshold = "0";
|
||||||
|
|
||||||
public String getMaxFileSize() {
|
public boolean getEnabled() {
|
||||||
return this.maxFileSize;
|
return this.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMaxRequestSize() {
|
public void setEnabled(boolean enabled) {
|
||||||
return this.maxRequestSize;
|
this.enabled = enabled;
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileSizeThreshold() {
|
|
||||||
return this.fileSizeThreshold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocation() {
|
public String getLocation() {
|
||||||
return this.location;
|
return this.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaxFileSize() {
|
||||||
|
return this.maxFileSize;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMaxFileSize(String maxFileSize) {
|
public void setMaxFileSize(String maxFileSize) {
|
||||||
this.maxFileSize = maxFileSize;
|
this.maxFileSize = maxFileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMaxRequestSize() {
|
||||||
|
return this.maxRequestSize;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMaxRequestSize(String maxRequestSize) {
|
public void setMaxRequestSize(String maxRequestSize) {
|
||||||
this.maxRequestSize = maxRequestSize;
|
this.maxRequestSize = maxRequestSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(String location) {
|
public String getFileSizeThreshold() {
|
||||||
this.location = location;
|
return this.fileSizeThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFileSizeThreshold(String fileSizeThreshold) {
|
public void setFileSizeThreshold(String fileSizeThreshold) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 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.
|
||||||
|
@ -17,6 +17,8 @@
|
||||||
package org.springframework.boot.autoconfigure.web;
|
package org.springframework.boot.autoconfigure.web;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.MultipartConfigElement;
|
import javax.servlet.MultipartConfigElement;
|
||||||
|
|
||||||
|
@ -24,14 +26,16 @@ import org.junit.After;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||||
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
|
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
|
||||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||||
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
|
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
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.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.client.ClientHttpRequest;
|
import org.springframework.http.client.ClientHttpRequest;
|
||||||
|
@ -196,22 +200,27 @@ public class MultipartAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void containerWithMultipartConfigDisabled() {
|
public void containerWithMultipartConfigDisabled() {
|
||||||
|
testContainerWithCustomMultipartConfigEnabledSetting("false", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void containerWithMultipartConfigEnabled() {
|
||||||
|
testContainerWithCustomMultipartConfigEnabledSetting("true", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testContainerWithCustomMultipartConfigEnabledSetting(
|
||||||
|
final String propertyValue, int expectedNumberOfMultipartConfigElementBeans) {
|
||||||
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||||
this.context.getEnvironment().getPropertySources()
|
Map<String, Object> poperties = new LinkedHashMap<String, Object>();
|
||||||
.addFirst(new PropertySource<Object>("test") {
|
poperties.put("multipart.enabled", propertyValue);
|
||||||
@Override
|
MapPropertySource propertySource = new MapPropertySource("test", poperties);
|
||||||
public Object getProperty(String name) {
|
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
|
||||||
if (name.toLowerCase().contains("multipart.enabled")) {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.context.register(ContainerWithNoMultipartTomcat.class,
|
this.context.register(ContainerWithNoMultipartTomcat.class,
|
||||||
BaseConfiguration.class);
|
BaseConfiguration.class);
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
assertEquals(0, this.context.getBeansOfType(MultipartConfigElement.class).size());
|
this.context.getBean(MultipartProperties.class);
|
||||||
|
assertEquals(expectedNumberOfMultipartConfigElementBeans, this.context
|
||||||
|
.getBeansOfType(MultipartConfigElement.class).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -245,8 +254,12 @@ public class MultipartAutoConfigurationTests {
|
||||||
@Import({ EmbeddedServletContainerAutoConfiguration.class,
|
@Import({ EmbeddedServletContainerAutoConfiguration.class,
|
||||||
DispatcherServletAutoConfiguration.class, MultipartAutoConfiguration.class,
|
DispatcherServletAutoConfiguration.class, MultipartAutoConfiguration.class,
|
||||||
ServerPropertiesAutoConfiguration.class })
|
ServerPropertiesAutoConfiguration.class })
|
||||||
|
@EnableConfigurationProperties(MultipartProperties.class)
|
||||||
protected static class BaseConfiguration {
|
protected static class BaseConfiguration {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MultipartProperties properties;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ServerProperties serverProperties() {
|
public ServerProperties serverProperties() {
|
||||||
ServerProperties properties = new ServerProperties();
|
ServerProperties properties = new ServerProperties();
|
||||||
|
|
|
@ -53,7 +53,7 @@ content into your application; rather pick only the properties that you need.
|
||||||
spring.output.ansi.enabled=detect # Configure the ANSI output ("detect", "always", "never")
|
spring.output.ansi.enabled=detect # Configure the ANSI output ("detect", "always", "never")
|
||||||
|
|
||||||
# LOGGING
|
# LOGGING
|
||||||
logging.path=/var/logs
|
logging.path=/var/log
|
||||||
logging.file=myapp.log
|
logging.file=myapp.log
|
||||||
logging.config= # location of config file (default classpath:logback.xml for logback)
|
logging.config= # location of config file (default classpath:logback.xml for logback)
|
||||||
logging.level.*= # levels for loggers, e.g. "logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)
|
logging.level.*= # levels for loggers, e.g. "logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)
|
||||||
|
|
|
@ -213,11 +213,9 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
|
||||||
if (classifier.length() > 0 && !classifier.startsWith("-")) {
|
if (classifier.length() > 0 && !classifier.startsWith("-")) {
|
||||||
classifier = "-" + classifier;
|
classifier = "-" + classifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.outputDirectory.exists()) {
|
if (!this.outputDirectory.exists()) {
|
||||||
this.outputDirectory.mkdirs();
|
this.outputDirectory.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new File(this.outputDirectory, this.finalName + classifier + "."
|
return new File(this.outputDirectory, this.finalName + classifier + "."
|
||||||
+ this.project.getArtifact().getArtifactHandler().getExtension());
|
+ this.project.getArtifact().getArtifactHandler().getExtension());
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,41 +193,34 @@ public class VcapApplicationListener implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void flatten(Properties properties, Map<String, Object> input, String path) {
|
private void flatten(Properties properties, Map<String, Object> input, String path) {
|
||||||
for (Entry<String, Object> entry : input.entrySet()) {
|
for (Entry<String, Object> entry : input.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = getFullKey(path, entry.getKey());
|
||||||
if (StringUtils.hasText(path)) {
|
Object value = entry.getValue();
|
||||||
if (key.startsWith("[")) {
|
if (value instanceof Map) {
|
||||||
key = path + key;
|
// Need a compound key
|
||||||
}
|
flatten(properties, (Map<String, Object>) value, key);
|
||||||
else {
|
}
|
||||||
key = path + "." + key;
|
else if (value instanceof Collection) {
|
||||||
|
// Need a compound key
|
||||||
|
Collection<Object> collection = (Collection<Object>) value;
|
||||||
|
properties.put(key,
|
||||||
|
StringUtils.collectionToCommaDelimitedString(collection));
|
||||||
|
int count = 0;
|
||||||
|
for (Object item : collection) {
|
||||||
|
String itemKey = "[" + (count++) + "]";
|
||||||
|
flatten(properties, Collections.singletonMap(itemKey, item), key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object value = entry.getValue();
|
else if (value instanceof String) {
|
||||||
if (value instanceof String) {
|
|
||||||
properties.put(key, value);
|
properties.put(key, value);
|
||||||
}
|
}
|
||||||
else if (value instanceof Number) {
|
else if (value instanceof Number) {
|
||||||
properties.put(key, value.toString());
|
properties.put(key, value.toString());
|
||||||
}
|
}
|
||||||
else if (value instanceof Map) {
|
else if (value instanceof Boolean) {
|
||||||
// Need a compound key
|
properties.put(key, value.toString());
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> map = (Map<String, Object>) value;
|
|
||||||
flatten(properties, map, key);
|
|
||||||
}
|
|
||||||
else if (value instanceof Collection) {
|
|
||||||
// Need a compound key
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Collection<Object> collection = (Collection<Object>) value;
|
|
||||||
properties.put(key,
|
|
||||||
StringUtils.collectionToCommaDelimitedString(collection));
|
|
||||||
int count = 0;
|
|
||||||
for (Object object : collection) {
|
|
||||||
flatten(properties,
|
|
||||||
Collections.singletonMap("[" + (count++) + "]", object), key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
properties.put(key, value == null ? "" : value);
|
properties.put(key, value == null ? "" : value);
|
||||||
|
@ -235,4 +228,14 @@ public class VcapApplicationListener implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getFullKey(String path, String key) {
|
||||||
|
if (!StringUtils.hasText(path)) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
if (key.startsWith("[")) {
|
||||||
|
return path + key;
|
||||||
|
}
|
||||||
|
return path + "." + key;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,12 +111,15 @@ public class VcapApplicationListenerTests {
|
||||||
+ "\"plan\":\"10mb\",\"credentials\":{"
|
+ "\"plan\":\"10mb\",\"credentials\":{"
|
||||||
+ "\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
|
+ "\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
|
||||||
+ "\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
|
+ "\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
|
||||||
|
+ "\"ssl\":true,\"location\":null,"
|
||||||
+ "\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
|
+ "\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
|
||||||
+ "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":"
|
+ "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":"
|
||||||
+ "\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}");
|
+ "\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}");
|
||||||
this.initializer.onApplicationEvent(this.event);
|
this.initializer.onApplicationEvent(this.event);
|
||||||
assertEquals("mysql", getProperty("vcap.services.mysql.name"));
|
assertEquals("mysql", getProperty("vcap.services.mysql.name"));
|
||||||
assertEquals("3306", getProperty("vcap.services.mysql.credentials.port"));
|
assertEquals("3306", getProperty("vcap.services.mysql.credentials.port"));
|
||||||
|
assertEquals("true", getProperty("vcap.services.mysql.credentials.ssl"));
|
||||||
|
assertEquals("", getProperty("vcap.services.mysql.credentials.location"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue