Polishing

This commit is contained in:
Juergen Hoeller 2018-06-13 22:04:10 +02:00
parent 3fc8ec498c
commit 0dc434b35e
4 changed files with 32 additions and 12 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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)

View File

@ -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<String> HTTP_METHODS = Arrays.asList("PUT", "PATCH", "DELETE");
private FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();
@ -65,7 +65,7 @@ public class FormContentFilter extends OncePerRequestFilter {
* <p>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<String, String> 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<String, String> 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);
}