From 135e9d10a6f9b84312923f1f23f4df34ca6a9343 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 15 Jun 2015 10:52:02 -0700 Subject: [PATCH 1/6] Polish --- .../security/AuthenticationManagerConfiguration.java | 2 +- .../main/java/org/springframework/boot/maven/RepackageMojo.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java index 059ffa9e0e..ebaa9d55cf 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java @@ -183,7 +183,7 @@ public class AuthenticationManagerConfiguration { ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, target, value); } - catch (Exception e) { + catch (Exception ex) { logger.info("Could not set " + name); } } diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java index e06e9b51d8..c8041150a4 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java @@ -186,11 +186,9 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { if (classifier.length() > 0 && !classifier.startsWith("-")) { classifier = "-" + classifier; } - if (!this.outputDirectory.exists()) { this.outputDirectory.mkdirs(); } - return new File(this.outputDirectory, this.finalName + classifier + "." + this.project.getArtifact().getArtifactHandler().getExtension()); } From a83d999f2779b64e2ec45e71b92801b80058a683 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 15 Jun 2015 11:18:01 -0700 Subject: [PATCH 2/6] Add missing MultipartProperties.enabled property Fixes gh-3209 --- .../web/MultipartProperties.java | 15 ++++++- .../web/MultipartAutoConfigurationTests.java | 39 ++++++++++++------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java index c1e15fc9ac..b1bbd6d4b9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java @@ -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"); * 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) public class MultipartProperties { + /** + * Enable multipart upload handling. + */ + private boolean enabled; + /** * Intermediate location of uploaded files. */ @@ -73,6 +78,14 @@ public class MultipartProperties { */ private String fileSizeThreshold = "0"; + public boolean getEnabled() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + public String getMaxFileSize() { return this.maxFileSize; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java index 0c93d3796a..1546917932 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ package org.springframework.boot.autoconfigure.web; import java.net.URI; +import java.util.LinkedHashMap; +import java.util.Map; import javax.servlet.MultipartConfigElement; @@ -24,14 +26,16 @@ import org.junit.After; import org.junit.Rule; import org.junit.Test; 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.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; 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.Configuration; 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.HttpStatus; import org.springframework.http.client.ClientHttpRequest; @@ -196,22 +200,27 @@ public class MultipartAutoConfigurationTests { @Test 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.getEnvironment().getPropertySources() - .addFirst(new PropertySource("test") { - @Override - public Object getProperty(String name) { - if (name.toLowerCase().contains("multipart.enabled")) { - return "false"; - } - return null; - } - }); + Map poperties = new LinkedHashMap(); + poperties.put("multipart.enabled", propertyValue); + MapPropertySource propertySource = new MapPropertySource("test", poperties); + this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.register(ContainerWithNoMultipartTomcat.class, BaseConfiguration.class); 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 @@ -245,8 +254,12 @@ public class MultipartAutoConfigurationTests { @Import({ EmbeddedServletContainerAutoConfiguration.class, DispatcherServletAutoConfiguration.class, MultipartAutoConfiguration.class, ServerPropertiesAutoConfiguration.class }) + @EnableConfigurationProperties(MultipartProperties.class) protected static class BaseConfiguration { + @Autowired + private MultipartProperties properties; + @Bean public ServerProperties serverProperties() { ServerProperties properties = new ServerProperties(); From 75ffd1b01741cd61ba1e97f6f760512959866438 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 15 Jun 2015 11:19:47 -0700 Subject: [PATCH 3/6] Polish --- .../web/MultipartProperties.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java index b1bbd6d4b9..eba3f97821 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java @@ -86,32 +86,32 @@ public class MultipartProperties { this.enabled = enabled; } - public String getMaxFileSize() { - return this.maxFileSize; - } - - public String getMaxRequestSize() { - return this.maxRequestSize; + public String getLocation() { + return this.location; } - public String getFileSizeThreshold() { - return this.fileSizeThreshold; + public void setLocation(String location) { + this.location = location; } - public String getLocation() { - return this.location; + public String getMaxFileSize() { + return this.maxFileSize; } public void setMaxFileSize(String maxFileSize) { this.maxFileSize = maxFileSize; } + public String getMaxRequestSize() { + return this.maxRequestSize; + } + public void setMaxRequestSize(String maxRequestSize) { this.maxRequestSize = maxRequestSize; } - public void setLocation(String location) { - this.location = location; + public String getFileSizeThreshold() { + return this.fileSizeThreshold; } public void setFileSizeThreshold(String fileSizeThreshold) { From 818d3bd230c5ea22b72e1a2d5b4361b5918d101c Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Mon, 15 Jun 2015 16:02:16 +0100 Subject: [PATCH 4/6] VcapApplicationListener Boolean Credentials Previously, the VcapApplicationListener would discard any service credential value that wasn't a String, Number, Map, Collection, or null. This was particularly a problem for services that exposed a value as a JSON boolean. This change takes booleans in the credential payload into account, converting them to Strings so that they will pass through the properties system properly. There's no real downside to this as Spring will coerce them back into Booleans if needed, by the application. Fixes gh-3237 --- .../boot/cloudfoundry/VcapApplicationListener.java | 3 +++ .../boot/cloudfoundry/VcapApplicationListenerTests.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java index 116d5f54cf..58fc2b0844 100644 --- a/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java @@ -211,6 +211,9 @@ public class VcapApplicationListener implements else if (value instanceof Number) { properties.put(key, value.toString()); } + else if (value instanceof Boolean) { + properties.put(key, value.toString()); + } else if (value instanceof Map) { // Need a compound key @SuppressWarnings("unchecked") diff --git a/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java index 6e1e9986d2..74b9a75c2f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java @@ -111,12 +111,15 @@ public class VcapApplicationListenerTests { + "\"plan\":\"10mb\",\"credentials\":{" + "\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\"," + "\"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\"," + "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":" + "\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}"); this.initializer.onApplicationEvent(this.event); assertEquals("mysql", getProperty("vcap.services.mysql.name")); assertEquals("3306", getProperty("vcap.services.mysql.credentials.port")); + assertEquals("true", getProperty("vcap.services.mysql.credentials.ssl")); + assertEquals("", getProperty("vcap.services.mysql.credentials.location")); } @Test From 20d39f7af2165c67d5221f556f58820c992d2cc6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 15 Jun 2015 11:31:33 -0700 Subject: [PATCH 5/6] Polish --- .../cloudfoundry/VcapApplicationListener.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java index 58fc2b0844..3ab6b27e33 100644 --- a/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java @@ -193,49 +193,49 @@ public class VcapApplicationListener implements } } + @SuppressWarnings("unchecked") private void flatten(Properties properties, Map input, String path) { for (Entry entry : input.entrySet()) { - String key = entry.getKey(); - if (StringUtils.hasText(path)) { - if (key.startsWith("[")) { - key = path + key; - } - else { - key = path + "." + key; - } - } + String key = getFullKey(path, entry.getKey()); Object value = entry.getValue(); - if (value instanceof String) { - properties.put(key, value); - } - else if (value instanceof Number) { - properties.put(key, value.toString()); - } - else if (value instanceof Boolean) { - properties.put(key, value.toString()); - } - else if (value instanceof Map) { + if (value instanceof Map) { // Need a compound key - @SuppressWarnings("unchecked") - Map map = (Map) value; - flatten(properties, map, key); + flatten(properties, (Map) value, key); } else if (value instanceof Collection) { // Need a compound key - @SuppressWarnings("unchecked") Collection collection = (Collection) value; properties.put(key, StringUtils.collectionToCommaDelimitedString(collection)); int count = 0; - for (Object object : collection) { - flatten(properties, - Collections.singletonMap("[" + (count++) + "]", object), key); + for (Object item : collection) { + String itemKey = "[" + (count++) + "]"; + flatten(properties, Collections.singletonMap(itemKey, item), key); } } + else if (value instanceof String) { + properties.put(key, value); + } + else if (value instanceof Number) { + properties.put(key, value.toString()); + } + else if (value instanceof Boolean) { + properties.put(key, value.toString()); + } else { properties.put(key, value == null ? "" : value); } } } + private String getFullKey(String path, String key) { + if (!StringUtils.hasText(path)) { + return key; + } + if (key.startsWith("[")) { + return path + key; + } + return path + "." + key; + } + } From d6e24a15ded6a966c0f72eb73f8b21b49661477d Mon Sep 17 00:00:00 2001 From: Artur Mkrtchyan Date: Sun, 14 Jun 2015 22:36:16 +0200 Subject: [PATCH 6/6] Update `logging.path` documentation sample Update appendix example to use the more common `/var/log` folder rather than `/var/logs`. Fixes gh-3225 --- .../src/main/asciidoc/appendix-application-properties.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index f376a3d320..9bd16f8277 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -42,7 +42,7 @@ content into your application; rather pick only the properties that you need. spring.main....= # see class for all properties # LOGGING - logging.path=/var/logs + logging.path=/var/log logging.file=myapp.log 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)