Don't apply `null` ServerProperties from customize

Update ServerProperties so that `null` values are not applied when
customizing the EmbeddedServletContainerFactory. Primarily changed to
stop `server.undertow.accesslog.enabled` from being blindly applied.

Fixes gh-5515
pull/5663/merge
Phillip Webb 9 years ago
parent 3ca365cff0
commit d7e56abdf3

@ -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) {
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;
}

@ -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<String, String> map) {
new RelaxedDataBinder(this.properties, "server")
.bind(new MutablePropertyValues(map));

Loading…
Cancel
Save