Skip to content

Commit d301d0f

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents 535451f + 758ddcd commit d301d0f

File tree

9 files changed

+190
-139
lines changed

9 files changed

+190
-139
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SolrHealthIndicator.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
4141
CoreAdminRequest request = new CoreAdminRequest();
4242
request.setAction(CoreAdminParams.CoreAdminAction.STATUS);
4343
CoreAdminResponse response = request.process(this.solrClient);
44-
int status = response.getStatus();
45-
if (status == 0) {
46-
builder.up().withDetail("solrStatus", "OK");
47-
}
48-
else {
49-
builder.down().withDetail("solrStatus", status);
50-
}
44+
int statusCode = response.getStatus();
45+
Status status = (statusCode == 0 ? Status.UP : Status.DOWN);
46+
builder.status(status).withDetail("solrStatus",
47+
(statusCode == 0 ? "OK" : statusCode));
5148
}
5249

5350
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected Map<String, Object> getTrace(HttpServletRequest request) {
138138
add(trace, Include.USER_PRINCIPAL, "userPrincipal",
139139
(userPrincipal == null ? null : userPrincipal.getName()));
140140
if (isIncluded(Include.PARAMETERS)) {
141-
trace.put("parameters", getParameterMap(request));
141+
trace.put("parameters", getParameterMapCopy(request));
142142
}
143143
add(trace, Include.QUERY_STRING, "query", request.getQueryString());
144144
add(trace, Include.AUTH_TYPE, "authType", request.getAuthType());
@@ -190,10 +190,8 @@ private Object getHeaderValue(HttpServletRequest request, String name) {
190190
return value;
191191
}
192192

193-
private Map<String, String[]> getParameterMap(HttpServletRequest request) {
194-
Map<String, String[]> map = new LinkedHashMap<String, String[]>();
195-
map.putAll(request.getParameterMap());
196-
return map;
193+
private Map<String, String[]> getParameterMapCopy(HttpServletRequest request) {
194+
return new LinkedHashMap<String, String[]>(request.getParameterMap());
197195
}
198196

199197
/**

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void indicatorExists() {
6868
public void solrIsUp() throws Exception {
6969
SolrClient solrClient = mock(SolrClient.class);
7070
given(solrClient.request(any(CoreAdminRequest.class), (String) isNull()))
71-
.willReturn(mockResponse(0));
71+
.willReturn(mockResponse(0));
7272
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
7373
Health health = healthIndicator.health();
7474
assertThat(health.getStatus()).isEqualTo(Status.UP);
@@ -79,7 +79,7 @@ public void solrIsUp() throws Exception {
7979
public void solrIsUpAndRequestFailed() throws Exception {
8080
SolrClient solrClient = mock(SolrClient.class);
8181
given(solrClient.request(any(CoreAdminRequest.class), (String) isNull()))
82-
.willReturn(mockResponse(400));
82+
.willReturn(mockResponse(400));
8383
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
8484
Health health = healthIndicator.health();
8585
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
@@ -90,7 +90,7 @@ public void solrIsUpAndRequestFailed() throws Exception {
9090
public void solrIsDown() throws Exception {
9191
SolrClient solrClient = mock(SolrClient.class);
9292
given(solrClient.request(any(CoreAdminRequest.class), (String) isNull()))
93-
.willThrow(new IOException("Connection failed"));
93+
.willThrow(new IOException("Connection failed"));
9494
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
9595
Health health = healthIndicator.health();
9696
assertThat(health.getStatus()).isEqualTo(Status.DOWN);

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerTemplateAvailabilityProvider.java

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23+
import org.springframework.boot.autoconfigure.template.AbstractTemplateAvailabilityProvider;
2324
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
24-
import org.springframework.boot.bind.PropertySourcesPropertyValues;
25-
import org.springframework.boot.bind.RelaxedDataBinder;
26-
import org.springframework.core.env.ConfigurableEnvironment;
27-
import org.springframework.core.env.Environment;
28-
import org.springframework.core.io.ResourceLoader;
29-
import org.springframework.util.ClassUtils;
3025

3126
/**
3227
* {@link TemplateAvailabilityProvider} that provides availability information for
@@ -36,35 +31,28 @@
3631
* @since 1.1.0
3732
*/
3833
public class FreeMarkerTemplateAvailabilityProvider
39-
implements TemplateAvailabilityProvider {
34+
extends AbstractTemplateAvailabilityProvider {
4035

41-
@Override
42-
public boolean isTemplateAvailable(String view, Environment environment,
43-
ClassLoader classLoader, ResourceLoader resourceLoader) {
44-
if (ClassUtils.isPresent("freemarker.template.Configuration", classLoader)) {
45-
FreeMarkerTemplateAvailabilityProperties properties = new FreeMarkerTemplateAvailabilityProperties();
46-
RelaxedDataBinder binder = new RelaxedDataBinder(properties,
47-
"spring.freemarker");
48-
binder.bind(new PropertySourcesPropertyValues(
49-
((ConfigurableEnvironment) environment).getPropertySources()));
50-
for (String loaderPath : properties.getTemplateLoaderPath()) {
51-
if (resourceLoader.getResource(loaderPath + properties.getPrefix() + view
52-
+ properties.getSuffix()).exists()) {
53-
return true;
54-
}
55-
}
56-
}
57-
return false;
36+
public FreeMarkerTemplateAvailabilityProvider() {
37+
super("freemarker.template.Configuration",
38+
FreeMarkerTemplateAvailabilityProperties.class, "spring.freemarker");
5839
}
5940

60-
static final class FreeMarkerTemplateAvailabilityProperties {
41+
static final class FreeMarkerTemplateAvailabilityProperties
42+
extends TemplateAvailabilityProperties {
6143

6244
private List<String> templateLoaderPath = new ArrayList<String>(
6345
Arrays.asList(FreeMarkerProperties.DEFAULT_TEMPLATE_LOADER_PATH));
6446

65-
private String prefix = FreeMarkerProperties.DEFAULT_PREFIX;
47+
FreeMarkerTemplateAvailabilityProperties() {
48+
super(FreeMarkerProperties.DEFAULT_PREFIX,
49+
FreeMarkerProperties.DEFAULT_SUFFIX);
50+
}
6651

67-
private String suffix = FreeMarkerProperties.DEFAULT_SUFFIX;
52+
@Override
53+
protected List<String> getLoaderPath() {
54+
return this.templateLoaderPath;
55+
}
6856

6957
public List<String> getTemplateLoaderPath() {
7058
return this.templateLoaderPath;
@@ -74,22 +62,6 @@ public void setTemplateLoaderPath(List<String> templateLoaderPath) {
7462
this.templateLoaderPath = templateLoaderPath;
7563
}
7664

77-
public String getPrefix() {
78-
return this.prefix;
79-
}
80-
81-
public void setPrefix(String prefix) {
82-
this.prefix = prefix;
83-
}
84-
85-
public String getSuffix() {
86-
return this.suffix;
87-
}
88-
89-
public void setSuffix(String suffix) {
90-
this.suffix = suffix;
91-
}
92-
9365
}
9466

9567
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAvailabilityProvider.java

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23+
import org.springframework.boot.autoconfigure.template.AbstractTemplateAvailabilityProvider;
2324
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
24-
import org.springframework.boot.bind.PropertySourcesPropertyValues;
25-
import org.springframework.boot.bind.RelaxedDataBinder;
26-
import org.springframework.core.env.ConfigurableEnvironment;
27-
import org.springframework.core.env.Environment;
28-
import org.springframework.core.io.ResourceLoader;
29-
import org.springframework.util.ClassUtils;
3025

3126
/**
3227
* {@link TemplateAvailabilityProvider} that provides availability information for Groovy
@@ -35,35 +30,29 @@
3530
* @author Dave Syer
3631
* @since 1.1.0
3732
*/
38-
public class GroovyTemplateAvailabilityProvider implements TemplateAvailabilityProvider {
33+
public class GroovyTemplateAvailabilityProvider
34+
extends AbstractTemplateAvailabilityProvider {
3935

40-
@Override
41-
public boolean isTemplateAvailable(String view, Environment environment,
42-
ClassLoader classLoader, ResourceLoader resourceLoader) {
43-
if (ClassUtils.isPresent("groovy.text.TemplateEngine", classLoader)) {
44-
GroovyTemplateAvailabilityProperties properties = new GroovyTemplateAvailabilityProperties();
45-
RelaxedDataBinder binder = new RelaxedDataBinder(properties,
46-
"spring.groovy.template");
47-
binder.bind(new PropertySourcesPropertyValues(
48-
((ConfigurableEnvironment) environment).getPropertySources()));
49-
for (String loaderPath : properties.getResourceLoaderPath()) {
50-
if (resourceLoader.getResource(loaderPath + properties.getPrefix() + view
51-
+ properties.getSuffix()).exists()) {
52-
return true;
53-
}
54-
}
55-
}
56-
return false;
36+
public GroovyTemplateAvailabilityProvider() {
37+
super("groovy.text.TemplateEngine", GroovyTemplateAvailabilityProperties.class,
38+
"spring.groovy.template");
5739
}
5840

59-
static final class GroovyTemplateAvailabilityProperties {
41+
static final class GroovyTemplateAvailabilityProperties
42+
extends TemplateAvailabilityProperties {
6043

6144
private List<String> resourceLoaderPath = new ArrayList<String>(
6245
Arrays.asList(GroovyTemplateProperties.DEFAULT_RESOURCE_LOADER_PATH));
6346

64-
private String prefix = GroovyTemplateProperties.DEFAULT_PREFIX;
47+
GroovyTemplateAvailabilityProperties() {
48+
super(GroovyTemplateProperties.DEFAULT_PREFIX,
49+
GroovyTemplateProperties.DEFAULT_SUFFIX);
50+
}
6551

66-
private String suffix = GroovyTemplateProperties.DEFAULT_SUFFIX;
52+
@Override
53+
protected List<String> getLoaderPath() {
54+
return this.resourceLoaderPath;
55+
}
6756

6857
public List<String> getResourceLoaderPath() {
6958
return this.resourceLoaderPath;
@@ -73,22 +62,6 @@ public void setResourceLoaderPath(List<String> resourceLoaderPath) {
7362
this.resourceLoaderPath = resourceLoaderPath;
7463
}
7564

76-
public String getPrefix() {
77-
return this.prefix;
78-
}
79-
80-
public void setPrefix(String prefix) {
81-
this.prefix = prefix;
82-
}
83-
84-
public String getSuffix() {
85-
return this.suffix;
86-
}
87-
88-
public void setSuffix(String suffix) {
89-
this.suffix = suffix;
90-
}
91-
9265
}
9366

9467
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.template;
18+
19+
import java.util.List;
20+
21+
import org.springframework.beans.BeanUtils;
22+
import org.springframework.boot.bind.PropertySourcesPropertyValues;
23+
import org.springframework.boot.bind.RelaxedDataBinder;
24+
import org.springframework.core.env.ConfigurableEnvironment;
25+
import org.springframework.core.env.Environment;
26+
import org.springframework.core.io.ResourceLoader;
27+
import org.springframework.util.ClassUtils;
28+
29+
/**
30+
* Abstract base class for {@link TemplateAvailabilityProvider} implementations.
31+
*
32+
* @author Andy Wilkinson
33+
* @author Phillip Webb
34+
* @since 1.4.6
35+
*/
36+
public abstract class AbstractTemplateAvailabilityProvider
37+
implements TemplateAvailabilityProvider {
38+
39+
private final String className;
40+
41+
private final Class<? extends TemplateAvailabilityProperties> propertiesClass;
42+
43+
private final String propertyPrefix;
44+
45+
public AbstractTemplateAvailabilityProvider(String className,
46+
Class<? extends TemplateAvailabilityProperties> propertiesClass,
47+
String propertyPrefix) {
48+
this.className = className;
49+
this.propertiesClass = propertiesClass;
50+
this.propertyPrefix = propertyPrefix;
51+
}
52+
53+
@Override
54+
public boolean isTemplateAvailable(String view, Environment environment,
55+
ClassLoader classLoader, ResourceLoader resourceLoader) {
56+
if (ClassUtils.isPresent(this.className, classLoader)) {
57+
TemplateAvailabilityProperties properties = BeanUtils
58+
.instantiateClass(this.propertiesClass);
59+
RelaxedDataBinder binder = new RelaxedDataBinder(properties,
60+
this.propertyPrefix);
61+
binder.bind(new PropertySourcesPropertyValues(
62+
((ConfigurableEnvironment) environment).getPropertySources()));
63+
return isTemplateAvailable(view, resourceLoader, properties);
64+
}
65+
return false;
66+
}
67+
68+
private boolean isTemplateAvailable(String view, ResourceLoader resourceLoader,
69+
TemplateAvailabilityProperties properties) {
70+
String location = properties.getPrefix() + view + properties.getSuffix();
71+
for (String path : properties.getLoaderPath()) {
72+
if (resourceLoader.getResource(path + location).exists()) {
73+
return true;
74+
}
75+
}
76+
return false;
77+
}
78+
79+
protected static abstract class TemplateAvailabilityProperties {
80+
81+
private String prefix;
82+
83+
private String suffix;
84+
85+
protected TemplateAvailabilityProperties(String prefix, String suffix) {
86+
this.prefix = prefix;
87+
this.suffix = suffix;
88+
}
89+
90+
protected abstract List<String> getLoaderPath();
91+
92+
public String getPrefix() {
93+
return this.prefix;
94+
}
95+
96+
public void setPrefix(String prefix) {
97+
this.prefix = prefix;
98+
}
99+
100+
public String getSuffix() {
101+
return this.suffix;
102+
}
103+
104+
public void setSuffix(String suffix) {
105+
this.suffix = suffix;
106+
}
107+
108+
}
109+
110+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,15 @@ public void customTomcatDisableMaxHttpPostSize() {
579579
Map<String, String> map = new HashMap<String, String>();
580580
map.put("server.tomcat.max-http-post-size", "-1");
581581
bindProperties(map);
582-
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(0);
582+
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(
583+
0);
583584
this.properties.customize(container);
584-
TomcatEmbeddedServletContainer embeddedContainer =
585-
(TomcatEmbeddedServletContainer) container.getEmbeddedServletContainer();
585+
TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container
586+
.getEmbeddedServletContainer();
586587
embeddedContainer.start();
587588
try {
588589
assertThat(embeddedContainer.getTomcat().getConnector().getMaxPostSize())
589-
.isEqualTo(-1);
590+
.isEqualTo(-1);
590591
}
591592
finally {
592593
embeddedContainer.stop();

0 commit comments

Comments
 (0)