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); .getBeansOfType(AbstractUrlHandlerMapping.class);
for (String name : mappings.keySet()) { for (String name : mappings.keySet()) {
AbstractUrlHandlerMapping mapping = mappings.get(name); AbstractUrlHandlerMapping mapping = mappings.get(name);
if (AopUtils.isCglibProxy(mapping)) { Map<String, Object> handlers = getHandlerMap(mapping);
// The getHandlerMap() method is final so it cannot be cglibbed
continue;
}
Map<String, Object> handlers = mapping.getHandlerMap();
for (String key : handlers.keySet()) { for (String key : handlers.keySet()) {
result.put(key, Collections.singletonMap("bean", name)); 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( protected void extractHandlerMappings(
Collection<AbstractUrlHandlerMapping> handlerMappings, Collection<AbstractUrlHandlerMapping> handlerMappings,
Map<String, Object> result) { Map<String, Object> result) {

View File

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

View File

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

View File

@ -48,23 +48,10 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
*/ */
private String[] templateLoaderPath = new String[] { DEFAULT_TEMPLATE_LOADER_PATH }; 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() { public FreeMarkerProperties() {
super(DEFAULT_PREFIX, DEFAULT_SUFFIX); super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
} }
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Map<String, String> getSettings() { public Map<String, String> getSettings() {
return this.settings; return this.settings;
} }

View File

@ -50,19 +50,6 @@ public class GroovyTemplateProperties extends AbstractViewResolverProperties {
*/ */
private Map<String, Object> configuration = new HashMap<String, Object>(); 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() { public String getPrefix() {
return this.prefix; return this.prefix;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,15 +17,15 @@
package org.springframework.boot.orm.jpa.hibernate; package org.springframework.boot.orm.jpa.hibernate;
import org.hibernate.cfg.ImprovedNamingStrategy; import org.hibernate.cfg.ImprovedNamingStrategy;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* Hibernate {@link NamingStrategy} that follows Spring recommended naming conventions. * Hibernate {@link org.hibernate.cfg.NamingStrategy} that follows Spring recommended
* Naming conventions implemented here are identical to {@link ImprovedNamingStrategy} * naming conventions. Naming conventions implemented here are identical to
* with the exception that foreign key columns include the referenced column name. * {@link ImprovedNamingStrategy} with the exception that foreign key columns include the
* referenced column name.
* *
* @author Phillip Webb * @author Phillip Webb
* @see "http://stackoverflow.com/questions/7689206/ejb3namingstrategy-vs-improvednamingstrategy-foreign-key-naming" * @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")) { if (!properties.containsKey("spring.profiles")) {
return MatchStatus.FOUND; return MatchStatus.FOUND;
} }
else {
return MatchStatus.NOT_FOUND; return MatchStatus.NOT_FOUND;
} }
}
} }