diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 6c8b2fcc972..1dfb9548424 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -1019,7 +1019,7 @@ public class ServerProperties @Deprecated @DeprecatedConfigurationProperty(replacement = "server.undertow.accesslog.enabled") public boolean isAccessLogEnabled() { - return this.accesslog.isEnabled(); + return Boolean.TRUE.equals(this.accesslog.getEnabled()); } /** @@ -1055,14 +1055,30 @@ public class ServerProperties void customizeUndertow(ServerProperties serverProperties, UndertowEmbeddedServletContainerFactory factory) { - factory.setBufferSize(this.bufferSize); - factory.setBuffersPerRegion(this.buffersPerRegion); - factory.setIoThreads(this.ioThreads); - factory.setWorkerThreads(this.workerThreads); - factory.setDirectBuffers(this.directBuffers); - factory.setAccessLogDirectory(this.accesslog.dir); - factory.setAccessLogPattern(this.accesslog.pattern); - factory.setAccessLogEnabled(this.accesslog.enabled); + if (this.bufferSize != null) { + factory.setBufferSize(this.bufferSize); + } + if (this.buffersPerRegion != null) { + factory.setBuffersPerRegion(this.buffersPerRegion); + } + if (this.ioThreads != null) { + factory.setIoThreads(this.ioThreads); + } + if (this.workerThreads != null) { + factory.setWorkerThreads(this.workerThreads); + } + if (this.directBuffers != null) { + factory.setDirectBuffers(this.directBuffers); + } + if (this.accesslog.dir != null) { + factory.setAccessLogDirectory(this.accesslog.dir); + } + if (this.accesslog.pattern != null) { + factory.setAccessLogPattern(this.accesslog.pattern); + } + if (this.accesslog.enabled != null) { + factory.setAccessLogEnabled(this.accesslog.enabled); + } factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders()); } @@ -1071,7 +1087,7 @@ public class ServerProperties /** * Enable access log. */ - private boolean enabled = false; + private Boolean enabled; /** * Format pattern for access logs. @@ -1083,11 +1099,11 @@ public class ServerProperties */ private File dir = new File("logs"); - public boolean isEnabled() { + public Boolean getEnabled() { return this.enabled; } - public void setEnabled(boolean enabled) { + public void setEnabled(Boolean enabled) { this.enabled = enabled; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index a12f8fb3a48..4ea0e62c825 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -53,6 +53,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -412,6 +413,14 @@ public class ServerPropertiesTests { verify(container).setSessionStoreDir(new File("myfolder")); } + @Test + public void skipNullElementsForUndertow() throws Exception { + UndertowEmbeddedServletContainerFactory container = mock( + UndertowEmbeddedServletContainerFactory.class); + this.properties.customize(container); + verify(container, never()).setAccessLogEnabled(anyBoolean()); + } + private void bindProperties(Map map) { new RelaxedDataBinder(this.properties, "server") .bind(new MutablePropertyValues(map));