From 0dc434b35e8009878984219920cdefc8ce0518d2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Jun 2018 22:04:10 +0200 Subject: [PATCH] Polishing --- .../support/ScheduledMethodRunnable.java | 21 ++++++++++++++++++- .../web/bind/annotation/ControllerAdvice.java | 4 +++- .../bind/annotation/RestControllerAdvice.java | 4 +++- .../web/filter/FormContentFilter.java | 15 ++++++------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java b/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java index 7c1fd599f28..0016622563c 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -38,21 +38,40 @@ public class ScheduledMethodRunnable implements Runnable { private final Method method; + /** + * Create a {@code ScheduledMethodRunnable} for the given target instance, + * calling the specified method. + * @param target the target instance to call the method on + * @param method the target method to call + */ public ScheduledMethodRunnable(Object target, Method method) { this.target = target; this.method = method; } + /** + * Create a {@code ScheduledMethodRunnable} for the given target instance, + * calling the specified method by name. + * @param target the target instance to call the method on + * @param methodName the name of the target method + * @throws NoSuchMethodException if the specified method does not exist + */ public ScheduledMethodRunnable(Object target, String methodName) throws NoSuchMethodException { this.target = target; this.method = target.getClass().getMethod(methodName); } + /** + * Return the target instance to call the method on. + */ public Object getTarget() { return this.target; } + /** + * Return the target method to call. + */ public Method getMethod() { return this.method; } diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java index b88fb5ccae2..3e24c1dcb5d 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -63,6 +63,8 @@ import org.springframework.stereotype.Component; * @author Brian Clozel * @author Sam Brannen * @since 3.2 + * @see org.springframework.stereotype.Controller + * @see RestControllerAdvice */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java index 7ab99fea10e..58232692641 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -41,6 +41,8 @@ import org.springframework.core.annotation.AliasFor; * * @author Rossen Stoyanchev * @since 4.3 + * @see RestController + * @see ControllerAdvice */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java b/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java index 9e6ef165868..67b33c21c99 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java @@ -41,6 +41,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -56,7 +57,6 @@ public class FormContentFilter extends OncePerRequestFilter { private static final List HTTP_METHODS = Arrays.asList("PUT", "PATCH", "DELETE"); - private FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter(); @@ -65,7 +65,7 @@ public class FormContentFilter extends OncePerRequestFilter { *

By default this is an instance of {@link AllEncompassingFormHttpMessageConverter}. */ public void setFormConverter(FormHttpMessageConverter converter) { - Assert.notNull(converter, "FormHttpMessageConverter is required."); + Assert.notNull(converter, "FormHttpMessageConverter is required"); this.formConverter = converter; } @@ -84,12 +84,12 @@ public class FormContentFilter extends OncePerRequestFilter { @Override - protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response, - FilterChain filterChain) throws ServletException, IOException { + protected void doFilterInternal( + HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { MultiValueMap params = parseIfNecessary(request); - - if (params != null && !params.isEmpty()) { + if (!CollectionUtils.isEmpty(params)) { filterChain.doFilter(new FormContentRequestWrapper(request, params), response); } else { @@ -99,19 +99,16 @@ public class FormContentFilter extends OncePerRequestFilter { @Nullable private MultiValueMap parseIfNecessary(HttpServletRequest request) throws IOException { - if (!shouldParse(request)) { return null; } HttpInputMessage inputMessage = new ServletServerHttpRequest(request) { - @Override public InputStream getBody() throws IOException { return request.getInputStream(); } }; - return this.formConverter.read(null, inputMessage); }