Skip to content

Commit d87f271

Browse files
committed
Merge branch '1.2.x'
2 parents 49e5382 + d6e24a1 commit d87f271

File tree

7 files changed

+81
-51
lines changed

7 files changed

+81
-51
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private void setField(Object target, String name, Object value) {
183183
ReflectionUtils.makeAccessible(field);
184184
ReflectionUtils.setField(field, target, value);
185185
}
186-
catch (Exception e) {
186+
catch (Exception ex) {
187187
logger.info("Could not set " + name);
188188
}
189189
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,11 @@
5050
@ConfigurationProperties(prefix = "multipart", ignoreUnknownFields = false)
5151
public class MultipartProperties {
5252

53+
/**
54+
* Enable multipart upload handling.
55+
*/
56+
private boolean enabled;
57+
5358
/**
5459
* Intermediate location of uploaded files.
5560
*/
@@ -73,32 +78,40 @@ public class MultipartProperties {
7378
*/
7479
private String fileSizeThreshold = "0";
7580

76-
public String getMaxFileSize() {
77-
return this.maxFileSize;
78-
}
79-
80-
public String getMaxRequestSize() {
81-
return this.maxRequestSize;
81+
public boolean getEnabled() {
82+
return this.enabled;
8283
}
8384

84-
public String getFileSizeThreshold() {
85-
return this.fileSizeThreshold;
85+
public void setEnabled(boolean enabled) {
86+
this.enabled = enabled;
8687
}
8788

8889
public String getLocation() {
8990
return this.location;
9091
}
9192

93+
public void setLocation(String location) {
94+
this.location = location;
95+
}
96+
97+
public String getMaxFileSize() {
98+
return this.maxFileSize;
99+
}
100+
92101
public void setMaxFileSize(String maxFileSize) {
93102
this.maxFileSize = maxFileSize;
94103
}
95104

105+
public String getMaxRequestSize() {
106+
return this.maxRequestSize;
107+
}
108+
96109
public void setMaxRequestSize(String maxRequestSize) {
97110
this.maxRequestSize = maxRequestSize;
98111
}
99112

100-
public void setLocation(String location) {
101-
this.location = location;
113+
public String getFileSizeThreshold() {
114+
return this.fileSizeThreshold;
102115
}
103116

104117
public void setFileSizeThreshold(String fileSizeThreshold) {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,21 +17,25 @@
1717
package org.springframework.boot.autoconfigure.web;
1818

1919
import java.net.URI;
20+
import java.util.LinkedHashMap;
21+
import java.util.Map;
2022

2123
import javax.servlet.MultipartConfigElement;
2224

2325
import org.junit.After;
2426
import org.junit.Rule;
2527
import org.junit.Test;
2628
import org.junit.rules.ExpectedException;
29+
import org.springframework.beans.factory.annotation.Autowired;
2730
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
2831
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
2932
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
3033
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
34+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3135
import org.springframework.context.annotation.Bean;
3236
import org.springframework.context.annotation.Configuration;
3337
import org.springframework.context.annotation.Import;
34-
import org.springframework.core.env.PropertySource;
38+
import org.springframework.core.env.MapPropertySource;
3539
import org.springframework.http.HttpMethod;
3640
import org.springframework.http.HttpStatus;
3741
import org.springframework.http.client.ClientHttpRequest;
@@ -196,22 +200,27 @@ public void containerWithAutomatedMultipartUndertowConfiguration() {
196200

197201
@Test
198202
public void containerWithMultipartConfigDisabled() {
203+
testContainerWithCustomMultipartConfigEnabledSetting("false", 0);
204+
}
199205

206+
@Test
207+
public void containerWithMultipartConfigEnabled() {
208+
testContainerWithCustomMultipartConfigEnabledSetting("true", 1);
209+
}
210+
211+
private void testContainerWithCustomMultipartConfigEnabledSetting(
212+
final String propertyValue, int expectedNumberOfMultipartConfigElementBeans) {
200213
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
201-
this.context.getEnvironment().getPropertySources()
202-
.addFirst(new PropertySource<Object>("test") {
203-
@Override
204-
public Object getProperty(String name) {
205-
if (name.toLowerCase().contains("multipart.enabled")) {
206-
return "false";
207-
}
208-
return null;
209-
}
210-
});
214+
Map<String, Object> poperties = new LinkedHashMap<String, Object>();
215+
poperties.put("multipart.enabled", propertyValue);
216+
MapPropertySource propertySource = new MapPropertySource("test", poperties);
217+
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
211218
this.context.register(ContainerWithNoMultipartTomcat.class,
212219
BaseConfiguration.class);
213220
this.context.refresh();
214-
assertEquals(0, this.context.getBeansOfType(MultipartConfigElement.class).size());
221+
this.context.getBean(MultipartProperties.class);
222+
assertEquals(expectedNumberOfMultipartConfigElementBeans, this.context
223+
.getBeansOfType(MultipartConfigElement.class).size());
215224
}
216225

217226
@Test
@@ -245,8 +254,12 @@ private void verifyServletWorks() {
245254
@Import({ EmbeddedServletContainerAutoConfiguration.class,
246255
DispatcherServletAutoConfiguration.class, MultipartAutoConfiguration.class,
247256
ServerPropertiesAutoConfiguration.class })
257+
@EnableConfigurationProperties(MultipartProperties.class)
248258
protected static class BaseConfiguration {
249259

260+
@Autowired
261+
private MultipartProperties properties;
262+
250263
@Bean
251264
public ServerProperties serverProperties() {
252265
ServerProperties properties = new ServerProperties();

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ content into your application; rather pick only the properties that you need.
5353
spring.output.ansi.enabled=detect # Configure the ANSI output ("detect", "always", "never")
5454
5555
# LOGGING
56-
logging.path=/var/logs
56+
logging.path=/var/log
5757
logging.file=myapp.log
5858
logging.config= # location of config file (default classpath:logback.xml for logback)
5959
logging.level.*= # levels for loggers, e.g. "logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)

spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,9 @@ private File getTargetFile() {
213213
if (classifier.length() > 0 && !classifier.startsWith("-")) {
214214
classifier = "-" + classifier;
215215
}
216-
217216
if (!this.outputDirectory.exists()) {
218217
this.outputDirectory.mkdirs();
219218
}
220-
221219
return new File(this.outputDirectory, this.finalName + classifier + "."
222220
+ this.project.getArtifact().getArtifactHandler().getExtension());
223221
}

spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,46 +193,49 @@ private void extractPropertiesFromServices(Properties properties,
193193
}
194194
}
195195

196+
@SuppressWarnings("unchecked")
196197
private void flatten(Properties properties, Map<String, Object> input, String path) {
197198
for (Entry<String, Object> entry : input.entrySet()) {
198-
String key = entry.getKey();
199-
if (StringUtils.hasText(path)) {
200-
if (key.startsWith("[")) {
201-
key = path + key;
202-
}
203-
else {
204-
key = path + "." + key;
205-
}
206-
}
199+
String key = getFullKey(path, entry.getKey());
207200
Object value = entry.getValue();
208-
if (value instanceof String) {
209-
properties.put(key, value);
210-
}
211-
else if (value instanceof Number) {
212-
properties.put(key, value.toString());
213-
}
214-
else if (value instanceof Map) {
201+
if (value instanceof Map) {
215202
// Need a compound key
216-
@SuppressWarnings("unchecked")
217-
Map<String, Object> map = (Map<String, Object>) value;
218-
flatten(properties, map, key);
203+
flatten(properties, (Map<String, Object>) value, key);
219204
}
220205
else if (value instanceof Collection) {
221206
// Need a compound key
222-
@SuppressWarnings("unchecked")
223207
Collection<Object> collection = (Collection<Object>) value;
224208
properties.put(key,
225209
StringUtils.collectionToCommaDelimitedString(collection));
226210
int count = 0;
227-
for (Object object : collection) {
228-
flatten(properties,
229-
Collections.singletonMap("[" + (count++) + "]", object), key);
211+
for (Object item : collection) {
212+
String itemKey = "[" + (count++) + "]";
213+
flatten(properties, Collections.singletonMap(itemKey, item), key);
230214
}
231215
}
216+
else if (value instanceof String) {
217+
properties.put(key, value);
218+
}
219+
else if (value instanceof Number) {
220+
properties.put(key, value.toString());
221+
}
222+
else if (value instanceof Boolean) {
223+
properties.put(key, value.toString());
224+
}
232225
else {
233226
properties.put(key, value == null ? "" : value);
234227
}
235228
}
236229
}
237230

231+
private String getFullKey(String path, String key) {
232+
if (!StringUtils.hasText(path)) {
233+
return key;
234+
}
235+
if (key.startsWith("[")) {
236+
return path + key;
237+
}
238+
return path + "." + key;
239+
}
240+
238241
}

spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,15 @@ public void testServiceProperties() {
111111
+ "\"plan\":\"10mb\",\"credentials\":{"
112112
+ "\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
113113
+ "\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
114+
+ "\"ssl\":true,\"location\":null,"
114115
+ "\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
115116
+ "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":"
116117
+ "\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}");
117118
this.initializer.onApplicationEvent(this.event);
118119
assertEquals("mysql", getProperty("vcap.services.mysql.name"));
119120
assertEquals("3306", getProperty("vcap.services.mysql.credentials.port"));
121+
assertEquals("true", getProperty("vcap.services.mysql.credentials.ssl"));
122+
assertEquals("", getProperty("vcap.services.mysql.credentials.location"));
120123
}
121124

122125
@Test

0 commit comments

Comments
 (0)