This commit is contained in:
Phillip Webb 2014-12-10 09:53:28 -08:00
parent 034ce0ad89
commit c678c1f788
23 changed files with 54 additions and 86 deletions

View File

@ -110,11 +110,7 @@ public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>
.getBeansOfType(AbstractUrlHandlerMapping.class);
for (String name : mappings.keySet()) {
AbstractUrlHandlerMapping mapping = mappings.get(name);
if (AopUtils.isCglibProxy(mapping)) {
// The getHandlerMap() method is final so it cannot be cglibbed
continue;
}
Map<String, Object> handlers = mapping.getHandlerMap();
Map<String, Object> handlers = getHandlerMap(mapping);
for (String key : handlers.keySet()) {
result.put(key, Collections.singletonMap("bean", name));
}
@ -122,6 +118,15 @@ public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>
}
}
private Map<String, Object> getHandlerMap(AbstractUrlHandlerMapping mapping) {
if (AopUtils.isCglibProxy(mapping)) {
// If the AbstractUrlHandlerMapping is a cglib proxy we can't call
// the final getHandlerMap() method.
return Collections.emptyMap();
}
return mapping.getHandlerMap();
}
protected void extractHandlerMappings(
Collection<AbstractUrlHandlerMapping> handlerMappings,
Map<String, Object> result) {

View File

@ -38,6 +38,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link RequestMappingEndpoint}.
*
* @author Dave Syer
*/
public class RequestMappingEndpointTests {

View File

@ -23,11 +23,14 @@ import org.springframework.context.support.StaticApplicationContext;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link MvcEndpoints}.
*
* @author Dave Syer
*/
public class MvcEndpointsTests {
private MvcEndpoints endpoints = new MvcEndpoints();
private StaticApplicationContext context = new StaticApplicationContext();
@Test

View File

@ -48,23 +48,10 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
*/
private String[] templateLoaderPath = new String[] { DEFAULT_TEMPLATE_LOADER_PATH };
/**
* Switches off MVC view resolution if set to false (default true).
*/
private boolean enabled = true;
public FreeMarkerProperties() {
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Map<String, String> getSettings() {
return this.settings;
}

View File

@ -50,19 +50,6 @@ public class GroovyTemplateProperties extends AbstractViewResolverProperties {
*/
private Map<String, Object> configuration = new HashMap<String, Object>();
/**
* Switches off MVC view resolution if set to false (default true).
*/
private boolean enabled = true;
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getPrefix() {
return this.prefix;
}

View File

@ -29,6 +29,11 @@ import org.springframework.web.servlet.ViewResolver;
*/
public abstract class AbstractViewResolverProperties {
/**
* Enable MVC view resolution for this technology.
*/
private boolean enabled = true;
/**
* Enable template caching.
*/
@ -54,6 +59,14 @@ public abstract class AbstractViewResolverProperties {
*/
private boolean checkTemplateLocation = true;
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return this.enabled;
}
public void setCheckTemplateLocation(boolean checkTemplateLocation) {
this.checkTemplateLocation = checkTemplateLocation;
}

View File

@ -77,7 +77,7 @@ public class ThymeleafProperties {
private String[] excludedViewNames;
/**
* Switches off MVC view resolution if set to false (default true).
* Enable MVC Thymeleaf view resolution.
*/
private boolean enabled = true;

View File

@ -71,23 +71,10 @@ public class VelocityProperties extends AbstractTemplateViewResolverProperties {
*/
private boolean preferFileSystemAccess = true;
/**
* Switches off MVC view resolution if set to false (default true).
*/
private boolean enabled = true;
public VelocityProperties() {
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getDateToolAttribute() {
return this.dateToolAttribute;
}

View File

@ -234,7 +234,6 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
}
private void doBindPropertiesToTarget() throws BindException {
RelaxedDataBinder dataBinder = (this.targetName != null ? new RelaxedDataBinder(
this.target, this.targetName) : new RelaxedDataBinder(this.target));
if (this.validator != null) {
@ -247,7 +246,15 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);
customizeBinder(dataBinder);
Set<String> names = getNames();
PropertyValues propertyValues = getPropertyValues(names);
dataBinder.bind(propertyValues);
if (this.validator != null) {
validate(dataBinder);
}
}
private Set<String> getNames() {
Set<String> names = new HashSet<String>();
if (this.target != null) {
PropertyDescriptor[] descriptors = BeanUtils
@ -262,17 +269,15 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
}
}
}
PropertyNamePatternsMatcher patterns = new DefaultPropertyNamePatternsMatcher(
names);
return names;
}
PropertyValues propertyValues = (this.properties != null ? new MutablePropertyValues(
this.properties) : new PropertySourcesPropertyValues(
this.propertySources, patterns, names));
dataBinder.bind(propertyValues);
if (this.validator != null) {
validate(dataBinder);
private PropertyValues getPropertyValues(Set<String> names) {
if (this.properties != null) {
return new MutablePropertyValues(this.properties);
}
return new PropertySourcesPropertyValues(this.propertySources,
new DefaultPropertyNamePatternsMatcher(names), names);
}
private void validate(RelaxedDataBinder dataBinder) throws BindException {

View File

@ -40,4 +40,5 @@ class SimplePropertyNamePatternsMatcher implements PropertyNamePatternsMatcher {
public boolean matches(String propertyName) {
return PatternMatchUtils.simpleMatch(this.patterns, propertyName);
}
}

View File

@ -121,16 +121,13 @@ public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourc
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
if (this.yaml == null) {
Assert.state(this.resource != null, "Resource should not be null");
this.yaml = StreamUtils.copyToString(this.resource.getInputStream(),
Charset.defaultCharset());
}
Assert.state(this.yaml != null, "Yaml document should not be null: "
+ "either set it directly or set the resource to load it from");
try {
if (this.logger.isTraceEnabled()) {
this.logger.trace("Yaml document is\n" + this.yaml);
@ -155,7 +152,6 @@ public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourc
BindingResult errors = new BeanPropertyBindingResult(this.configuration,
"configuration");
this.validator.validate(this.configuration, errors);
if (errors.hasErrors()) {
this.logger.error("YAML configuration failed validation");
for (ObjectError error : errors.getAllErrors()) {

View File

@ -232,9 +232,7 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
"Cannot initialize context because there is already a root application context present - "
+ "check whether you have multiple ServletContextInitializers!");
}
else {
return;
}
return;
}
Log logger = LogFactory.getLog(ContextLoader.class);
servletContext.log("Initializing Spring embedded WebApplicationContext");

View File

@ -96,7 +96,6 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
@Override
public void start() throws EmbeddedServletContainerException {
this.server.setConnectors(this.connectors);
if (!this.autoStart) {
return;
}

View File

@ -143,11 +143,9 @@ public class TomcatEmbeddedServletContainerFactory extends
tomcat.setConnector(connector);
tomcat.getHost().setAutoDeploy(false);
tomcat.getEngine().setBackgroundProcessorDelay(-1);
for (Connector additionalConnector : this.additionalTomcatConnectors) {
tomcat.getService().addConnector(additionalConnector);
}
prepareContext(tomcat.getHost(), initializers);
return getTomcatEmbeddedServletContainer(tomcat);
}

View File

@ -46,7 +46,6 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
@Override
public synchronized Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
Class<?> resultClass = null;
// Check local class caches

View File

@ -324,7 +324,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
}
loader.load(resource);
}
MutablePropertySources loaded = loader.getPropertySources();
if (mergeDefaultSources) {
for (PropertySource<?> propertySource : this.propertySources) {

View File

@ -49,4 +49,5 @@ public class ConfigurationPropertiesBindingPostProcessorRegistrar implements
registry.registerBeanDefinition(METADATA_BEAN_NAME, meta.getBeanDefinition());
}
}
}

View File

@ -103,7 +103,6 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
private void doFilter(HttpServletRequest request, HttpServletResponse response,
FilterChain chain) throws IOException, ServletException {
ErrorWrapperResponse wrapped = new ErrorWrapperResponse(response);
try {
chain.doFilter(request, wrapped);
@ -125,7 +124,6 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
private void handleErrorStatus(HttpServletRequest request,
HttpServletResponse response, int status, String message)
throws ServletException, IOException {
if (response.isCommitted()) {
handleCommittedResponse(request, null);
return;
@ -139,7 +137,6 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
response.setStatus(status);
setErrorAttributes(request, status, message);
request.getRequestDispatcher(errorPath).forward(request, response);
}
private void handleException(HttpServletRequest request,
@ -162,18 +159,15 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
private void forwardToErrorPage(String path, HttpServletRequest request,
HttpServletResponse response, Throwable ex) throws ServletException,
IOException {
if (logger.isErrorEnabled()) {
String message = "Forwarding to error page from request "
+ getDescription(request) + " due to exception [" + ex.getMessage()
+ "]";
logger.error(message, ex);
}
setErrorAttributes(request, 500, ex.getMessage());
request.setAttribute(ERROR_EXCEPTION, ex);
request.setAttribute(ERROR_EXCEPTION_TYPE, ex.getClass().getName());
response.reset();
response.sendError(500, ex.getMessage());
request.getRequestDispatcher(path).forward(request, response);
@ -288,7 +282,6 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
public void sendError(int status, String message) throws IOException {
this.status = status;
this.message = message;
this.errorToSend = true;
}

View File

@ -77,29 +77,24 @@ public class BasicJsonParser implements JsonParser {
if (json.startsWith("[")) {
return parseListInternal(json);
}
if (json.startsWith("{")) {
return parseMapInternal(json);
}
if (json.startsWith("\"")) {
return trimTrailingCharacter(trimLeadingCharacter(json, '"'), '"');
}
try {
return Long.valueOf(json);
}
catch (NumberFormatException ex) {
// ignore
}
try {
return Double.valueOf(json);
}
catch (NumberFormatException ex) {
// ignore
}
return json;
}

View File

@ -61,4 +61,5 @@ public class JsonSimpleJsonParser implements JsonParser {
}
return nested;
}
}

View File

@ -28,4 +28,5 @@ package org.springframework.boot.json;
*/
@Deprecated
public class SimpleJsonParser extends BasicJsonParser {
}

View File

@ -17,15 +17,15 @@
package org.springframework.boot.orm.jpa.hibernate;
import org.hibernate.cfg.ImprovedNamingStrategy;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.StringHelper;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Hibernate {@link NamingStrategy} that follows Spring recommended naming conventions.
* Naming conventions implemented here are identical to {@link ImprovedNamingStrategy}
* with the exception that foreign key columns include the referenced column name.
* Hibernate {@link org.hibernate.cfg.NamingStrategy} that follows Spring recommended
* naming conventions. Naming conventions implemented here are identical to
* {@link ImprovedNamingStrategy} with the exception that foreign key columns include the
* referenced column name.
*
* @author Phillip Webb
* @see "http://stackoverflow.com/questions/7689206/ejb3namingstrategy-vs-improvednamingstrategy-foreign-key-naming"

View File

@ -34,9 +34,7 @@ public class DefaultProfileDocumentMatcher implements DocumentMatcher {
if (!properties.containsKey("spring.profiles")) {
return MatchStatus.FOUND;
}
else {
return MatchStatus.NOT_FOUND;
}
return MatchStatus.NOT_FOUND;
}
}