pull/8929/head
Phillip Webb 8 years ago
parent b2f0ebfcb8
commit 758ddcd420

@ -41,13 +41,10 @@ public class SolrHealthIndicator extends AbstractHealthIndicator {
CoreAdminRequest request = new CoreAdminRequest(); CoreAdminRequest request = new CoreAdminRequest();
request.setAction(CoreAdminParams.CoreAdminAction.STATUS); request.setAction(CoreAdminParams.CoreAdminAction.STATUS);
CoreAdminResponse response = request.process(this.solrClient); CoreAdminResponse response = request.process(this.solrClient);
int status = response.getStatus(); int statusCode = response.getStatus();
if (status == 0) { Status status = (statusCode == 0 ? Status.UP : Status.DOWN);
builder.up().withDetail("solrStatus", "OK"); builder.status(status).withDetail("solrStatus",
} (statusCode == 0 ? "OK" : statusCode));
else {
builder.down().withDetail("solrStatus", status);
}
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -132,7 +132,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
add(trace, Include.USER_PRINCIPAL, "userPrincipal", add(trace, Include.USER_PRINCIPAL, "userPrincipal",
(userPrincipal == null ? null : userPrincipal.getName())); (userPrincipal == null ? null : userPrincipal.getName()));
if (isIncluded(Include.PARAMETERS)) { if (isIncluded(Include.PARAMETERS)) {
trace.put("parameters", getParameterMap(request)); trace.put("parameters", getParameterMapCopy(request));
} }
add(trace, Include.QUERY_STRING, "query", request.getQueryString()); add(trace, Include.QUERY_STRING, "query", request.getQueryString());
add(trace, Include.AUTH_TYPE, "authType", request.getAuthType()); add(trace, Include.AUTH_TYPE, "authType", request.getAuthType());
@ -170,10 +170,8 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
return headers; return headers;
} }
private Map<String, String[]> getParameterMap(HttpServletRequest request) { private Map<String, String[]> getParameterMapCopy(HttpServletRequest request) {
Map<String, String[]> map = new LinkedHashMap<String, String[]>(); return new LinkedHashMap<String, String[]>(request.getParameterMap());
map.putAll(request.getParameterMap());
return map;
} }
/** /**

@ -20,13 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.springframework.boot.autoconfigure.template.AbstractTemplateAvailabilityProvider;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.bind.PropertySourcesPropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
/** /**
* {@link TemplateAvailabilityProvider} that provides availability information for * {@link TemplateAvailabilityProvider} that provides availability information for
@ -36,35 +31,28 @@ import org.springframework.util.ClassUtils;
* @since 1.1.0 * @since 1.1.0
*/ */
public class FreeMarkerTemplateAvailabilityProvider public class FreeMarkerTemplateAvailabilityProvider
implements TemplateAvailabilityProvider { extends AbstractTemplateAvailabilityProvider {
@Override public FreeMarkerTemplateAvailabilityProvider() {
public boolean isTemplateAvailable(String view, Environment environment, super("freemarker.template.Configuration",
ClassLoader classLoader, ResourceLoader resourceLoader) { FreeMarkerTemplateAvailabilityProperties.class, "spring.freemarker");
if (ClassUtils.isPresent("freemarker.template.Configuration", classLoader)) {
FreeMarkerTemplateAvailabilityProperties properties = new FreeMarkerTemplateAvailabilityProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(properties,
"spring.freemarker");
binder.bind(new PropertySourcesPropertyValues(
((ConfigurableEnvironment) environment).getPropertySources()));
for (String loaderPath : properties.getTemplateLoaderPath()) {
if (resourceLoader.getResource(loaderPath + properties.getPrefix() + view
+ properties.getSuffix()).exists()) {
return true;
}
}
}
return false;
} }
static final class FreeMarkerTemplateAvailabilityProperties { static final class FreeMarkerTemplateAvailabilityProperties
extends TemplateAvailabilityProperties {
private List<String> templateLoaderPath = new ArrayList<String>( private List<String> templateLoaderPath = new ArrayList<String>(
Arrays.asList(FreeMarkerProperties.DEFAULT_TEMPLATE_LOADER_PATH)); Arrays.asList(FreeMarkerProperties.DEFAULT_TEMPLATE_LOADER_PATH));
private String prefix = FreeMarkerProperties.DEFAULT_PREFIX; FreeMarkerTemplateAvailabilityProperties() {
super(FreeMarkerProperties.DEFAULT_PREFIX,
FreeMarkerProperties.DEFAULT_SUFFIX);
}
private String suffix = FreeMarkerProperties.DEFAULT_SUFFIX; @Override
protected List<String> getLoaderPath() {
return this.templateLoaderPath;
}
public List<String> getTemplateLoaderPath() { public List<String> getTemplateLoaderPath() {
return this.templateLoaderPath; return this.templateLoaderPath;
@ -74,22 +62,6 @@ public class FreeMarkerTemplateAvailabilityProvider
this.templateLoaderPath = templateLoaderPath; this.templateLoaderPath = templateLoaderPath;
} }
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return this.suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
} }
} }

@ -20,13 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.springframework.boot.autoconfigure.template.AbstractTemplateAvailabilityProvider;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.bind.PropertySourcesPropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
/** /**
* {@link TemplateAvailabilityProvider} that provides availability information for Groovy * {@link TemplateAvailabilityProvider} that provides availability information for Groovy
@ -35,35 +30,29 @@ import org.springframework.util.ClassUtils;
* @author Dave Syer * @author Dave Syer
* @since 1.1.0 * @since 1.1.0
*/ */
public class GroovyTemplateAvailabilityProvider implements TemplateAvailabilityProvider { public class GroovyTemplateAvailabilityProvider
extends AbstractTemplateAvailabilityProvider {
@Override public GroovyTemplateAvailabilityProvider() {
public boolean isTemplateAvailable(String view, Environment environment, super("groovy.text.TemplateEngine", GroovyTemplateAvailabilityProperties.class,
ClassLoader classLoader, ResourceLoader resourceLoader) {
if (ClassUtils.isPresent("groovy.text.TemplateEngine", classLoader)) {
GroovyTemplateAvailabilityProperties properties = new GroovyTemplateAvailabilityProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(properties,
"spring.groovy.template"); "spring.groovy.template");
binder.bind(new PropertySourcesPropertyValues(
((ConfigurableEnvironment) environment).getPropertySources()));
for (String loaderPath : properties.getResourceLoaderPath()) {
if (resourceLoader.getResource(loaderPath + properties.getPrefix() + view
+ properties.getSuffix()).exists()) {
return true;
}
}
}
return false;
} }
static final class GroovyTemplateAvailabilityProperties { static final class GroovyTemplateAvailabilityProperties
extends TemplateAvailabilityProperties {
private List<String> resourceLoaderPath = new ArrayList<String>( private List<String> resourceLoaderPath = new ArrayList<String>(
Arrays.asList(GroovyTemplateProperties.DEFAULT_RESOURCE_LOADER_PATH)); Arrays.asList(GroovyTemplateProperties.DEFAULT_RESOURCE_LOADER_PATH));
private String prefix = GroovyTemplateProperties.DEFAULT_PREFIX; GroovyTemplateAvailabilityProperties() {
super(GroovyTemplateProperties.DEFAULT_PREFIX,
GroovyTemplateProperties.DEFAULT_SUFFIX);
}
private String suffix = GroovyTemplateProperties.DEFAULT_SUFFIX; @Override
protected List<String> getLoaderPath() {
return this.resourceLoaderPath;
}
public List<String> getResourceLoaderPath() { public List<String> getResourceLoaderPath() {
return this.resourceLoaderPath; return this.resourceLoaderPath;
@ -73,22 +62,6 @@ public class GroovyTemplateAvailabilityProvider implements TemplateAvailabilityP
this.resourceLoaderPath = resourceLoaderPath; this.resourceLoaderPath = resourceLoaderPath;
} }
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return this.suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
} }
} }

@ -0,0 +1,110 @@
/*
* Copyright 2012-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.template;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.bind.PropertySourcesPropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
/**
* Abstract base class for {@link TemplateAvailabilityProvider} implementations.
*
* @author Andy Wilkinson
* @author Phillip Webb
* @since 1.4.6
*/
public abstract class AbstractTemplateAvailabilityProvider
implements TemplateAvailabilityProvider {
private final String className;
private final Class<? extends TemplateAvailabilityProperties> propertiesClass;
private final String propertyPrefix;
public AbstractTemplateAvailabilityProvider(String className,
Class<? extends TemplateAvailabilityProperties> propertiesClass,
String propertyPrefix) {
this.className = className;
this.propertiesClass = propertiesClass;
this.propertyPrefix = propertyPrefix;
}
@Override
public boolean isTemplateAvailable(String view, Environment environment,
ClassLoader classLoader, ResourceLoader resourceLoader) {
if (ClassUtils.isPresent(this.className, classLoader)) {
TemplateAvailabilityProperties properties = BeanUtils
.instantiateClass(this.propertiesClass);
RelaxedDataBinder binder = new RelaxedDataBinder(properties,
this.propertyPrefix);
binder.bind(new PropertySourcesPropertyValues(
((ConfigurableEnvironment) environment).getPropertySources()));
return isTemplateAvailable(view, resourceLoader, properties);
}
return false;
}
private boolean isTemplateAvailable(String view, ResourceLoader resourceLoader,
TemplateAvailabilityProperties properties) {
String location = properties.getPrefix() + view + properties.getSuffix();
for (String path : properties.getLoaderPath()) {
if (resourceLoader.getResource(path + location).exists()) {
return true;
}
}
return false;
}
protected static abstract class TemplateAvailabilityProperties {
private String prefix;
private String suffix;
protected TemplateAvailabilityProperties(String prefix, String suffix) {
this.prefix = prefix;
this.suffix = suffix;
}
protected abstract List<String> getLoaderPath();
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return this.suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
}
}

@ -20,13 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.springframework.boot.autoconfigure.template.AbstractTemplateAvailabilityProvider;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.bind.PropertySourcesPropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
/** /**
* {@link TemplateAvailabilityProvider} that provides availability information for * {@link TemplateAvailabilityProvider} that provides availability information for
@ -39,36 +34,27 @@ import org.springframework.util.ClassUtils;
*/ */
@Deprecated @Deprecated
public class VelocityTemplateAvailabilityProvider public class VelocityTemplateAvailabilityProvider
implements TemplateAvailabilityProvider { extends AbstractTemplateAvailabilityProvider {
@Override public VelocityTemplateAvailabilityProvider() {
public boolean isTemplateAvailable(String view, Environment environment, super("org.apache.velocity.app.VelocityEngine",
ClassLoader classLoader, ResourceLoader resourceLoader) { VelocityTemplateAvailabilityProperties.class, "spring.velocity");
if (ClassUtils.isPresent("org.apache.velocity.app.VelocityEngine", classLoader)) {
VelocityTemplateAvailabilityProperties properties = new VelocityTemplateAvailabilityProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(properties,
"spring.velocity");
binder.bind(new PropertySourcesPropertyValues(
((ConfigurableEnvironment) environment).getPropertySources()));
for (String path : properties.getResourceLoaderPath()) {
if (resourceLoader.getResource(
path + properties.getPrefix() + view + properties.getSuffix())
.exists()) {
return true;
}
}
}
return false;
} }
static class VelocityTemplateAvailabilityProperties { static class VelocityTemplateAvailabilityProperties
extends TemplateAvailabilityProperties {
private List<String> resourceLoaderPath = new ArrayList<String>( private List<String> resourceLoaderPath = new ArrayList<String>(
Arrays.asList(VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH)); Arrays.asList(VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH));
private String prefix = VelocityProperties.DEFAULT_PREFIX; VelocityTemplateAvailabilityProperties() {
super(VelocityProperties.DEFAULT_PREFIX, VelocityProperties.DEFAULT_SUFFIX);
}
private String suffix = VelocityProperties.DEFAULT_SUFFIX; @Override
protected List<String> getLoaderPath() {
return this.resourceLoaderPath;
}
public List<String> getResourceLoaderPath() { public List<String> getResourceLoaderPath() {
return this.resourceLoaderPath; return this.resourceLoaderPath;
@ -78,22 +64,6 @@ public class VelocityTemplateAvailabilityProvider
this.resourceLoaderPath = resourceLoaderPath; this.resourceLoaderPath = resourceLoaderPath;
} }
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return this.suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
} }
} }

@ -450,10 +450,11 @@ public class ServerPropertiesTests {
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("server.max-http-post-size", "-1"); map.put("server.max-http-post-size", "-1");
bindProperties(map); bindProperties(map);
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(0); TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(
0);
this.properties.customize(container); this.properties.customize(container);
TomcatEmbeddedServletContainer embeddedContainer = TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container
(TomcatEmbeddedServletContainer) container.getEmbeddedServletContainer(); .getEmbeddedServletContainer();
embeddedContainer.start(); embeddedContainer.start();
try { try {
assertThat(embeddedContainer.getTomcat().getConnector().getMaxPostSize()) assertThat(embeddedContainer.getTomcat().getConnector().getMaxPostSize())

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

Loading…
Cancel
Save