Polishing
This commit is contained in:
parent
74bdcd8ed4
commit
1ee0626c94
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -47,14 +47,12 @@ import org.springframework.validation.annotation.Validated;
|
|||
* at the type level of the containing target class, applying to all public service methods
|
||||
* of that class. By default, JSR-303 will validate against its default group only.
|
||||
*
|
||||
* <p>As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider
|
||||
* (such as Hibernate Validator 5.x).
|
||||
* <p>As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @see MethodValidationPostProcessor
|
||||
* @see javax.validation.executable.ExecutableValidator
|
||||
* @see org.hibernate.validator.method.MethodValidator
|
||||
*/
|
||||
public class MethodValidationInterceptor implements MethodInterceptor {
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -48,14 +48,12 @@ import org.springframework.validation.annotation.Validated;
|
|||
* inline constraint annotations. Validation groups can be specified through {@code @Validated}
|
||||
* as well. By default, JSR-303 will validate against its default group only.
|
||||
*
|
||||
* <p>As of Spring 4.0, this functionality requires either a Bean Validation 1.1 provider
|
||||
* (such as Hibernate Validator 5.x) or the Bean Validation 1.0 API with Hibernate Validator
|
||||
* 4.3. The actual provider will be autodetected and automatically adapted.
|
||||
* <p>As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @see MethodValidationInterceptor
|
||||
* @see org.hibernate.validator.method.MethodValidator
|
||||
* @see javax.validation.executable.ExecutableValidator
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class MethodValidationPostProcessor extends AbstractBeanFactoryAwareAdvisingPostProcessor
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -54,8 +54,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ModelAttributeMethodProcessor
|
||||
implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler {
|
||||
public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -250,7 +250,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
|
|||
}
|
||||
|
||||
/**
|
||||
* Validate the request part if applicable.
|
||||
* Validate the binding target if applicable.
|
||||
* <p>The default implementation checks for {@code @javax.validation.Valid},
|
||||
* Spring's {@link org.springframework.validation.annotation.Validated},
|
||||
* and custom annotations whose name starts with "Valid".
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -110,8 +110,8 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
|||
* @param mavContainer the ModelAndViewContainer for this request
|
||||
* @param providedArgs "given" arguments matched by type (not resolved)
|
||||
*/
|
||||
public void invokeAndHandle(ServletWebRequest webRequest,
|
||||
ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception {
|
||||
public void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer mavContainer,
|
||||
Object... providedArgs) throws Exception {
|
||||
|
||||
Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs);
|
||||
setResponseStatus(webRequest);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -142,7 +142,6 @@ import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
|
|||
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -159,7 +158,9 @@ import static org.junit.Assert.*;
|
|||
*/
|
||||
public class MvcNamespaceTests {
|
||||
|
||||
public static final String VIEWCONTROLLER_BEAN_NAME = "org.springframework.web.servlet.config.viewControllerHandlerMapping";
|
||||
public static final String VIEWCONTROLLER_BEAN_NAME =
|
||||
"org.springframework.web.servlet.config.viewControllerHandlerMapping";
|
||||
|
||||
|
||||
private GenericWebApplicationContext appContext;
|
||||
|
||||
|
@ -197,7 +198,7 @@ public class MvcNamespaceTests {
|
|||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
ContentNegotiationManager manager = mapping.getContentNegotiationManager();
|
||||
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
|
||||
|
||||
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
|
@ -697,7 +698,8 @@ public class MvcNamespaceTests {
|
|||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
|
||||
assertEquals(Collections.singletonList(MediaType.valueOf("application/rss+xml")),
|
||||
manager.resolveMediaTypes(webRequest));
|
||||
|
||||
ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
|
||||
assertNotNull(compositeResolver);
|
||||
|
@ -882,7 +884,7 @@ public class MvcNamespaceTests {
|
|||
assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
|
||||
assertNull(config.getExposedHeaders());
|
||||
assertTrue(config.getAllowCredentials());
|
||||
assertEquals(new Long(1800), config.getMaxAge());
|
||||
assertEquals(Long.valueOf(1800), config.getMaxAge());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -905,14 +907,14 @@ public class MvcNamespaceTests {
|
|||
assertArrayEquals(new String[]{"header1", "header2", "header3"}, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[]{"header1", "header2"}, config.getExposedHeaders().toArray());
|
||||
assertFalse(config.getAllowCredentials());
|
||||
assertEquals(new Long(123), config.getMaxAge());
|
||||
assertEquals(Long.valueOf(123), config.getMaxAge());
|
||||
config = configs.get("/resources/**");
|
||||
assertArrayEquals(new String[]{"http://domain1.com"}, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[]{"GET", "HEAD", "POST"}, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
|
||||
assertNull(config.getExposedHeaders());
|
||||
assertTrue(config.getAllowCredentials());
|
||||
assertEquals(new Long(1800), config.getMaxAge());
|
||||
assertEquals(Long.valueOf(1800), config.getMaxAge());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -928,21 +930,21 @@ public class MvcNamespaceTests {
|
|||
|
||||
|
||||
@DateTimeFormat(iso = ISO.DATE)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface IsoDate {
|
||||
}
|
||||
|
||||
|
||||
@NumberFormat(style = NumberFormat.Style.PERCENT)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PercentNumber {
|
||||
}
|
||||
|
||||
|
||||
@Validated(MyGroup.class)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyValid {
|
||||
}
|
||||
|
@ -961,6 +963,7 @@ public class MvcNamespaceTests {
|
|||
public void testBind(@RequestParam @IsoDate Date date,
|
||||
@RequestParam(required = false) @PercentNumber Double percent,
|
||||
@MyValid TestBean bean, BindingResult result) {
|
||||
|
||||
this.date = date;
|
||||
this.percent = percent;
|
||||
this.recordedValidationError = (result.getErrorCount() == 1);
|
||||
|
|
Loading…
Reference in New Issue