Polishing
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
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) {
|
public ScheduledMethodRunnable(Object target, Method method) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.method = method;
|
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 {
|
public ScheduledMethodRunnable(Object target, String methodName) throws NoSuchMethodException {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.method = target.getClass().getMethod(methodName);
|
this.method = target.getClass().getMethod(methodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the target instance to call the method on.
|
||||||
|
*/
|
||||||
public Object getTarget() {
|
public Object getTarget() {
|
||||||
return this.target;
|
return this.target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the target method to call.
|
||||||
|
*/
|
||||||
public Method getMethod() {
|
public Method getMethod() {
|
||||||
return this.method;
|
return this.method;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 Brian Clozel
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
|
* @see org.springframework.stereotype.Controller
|
||||||
|
* @see RestControllerAdvice
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
|
* @see RestController
|
||||||
|
* @see ControllerAdvice
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
|
|||||||
import org.springframework.http.server.ServletServerHttpRequest;
|
import org.springframework.http.server.ServletServerHttpRequest;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.util.StringUtils;
|
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 static final List<String> HTTP_METHODS = Arrays.asList("PUT", "PATCH", "DELETE");
|
||||||
|
|
||||||
|
|
||||||
private FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();
|
private FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public class FormContentFilter extends OncePerRequestFilter {
|
|||||||
* <p>By default this is an instance of {@link AllEncompassingFormHttpMessageConverter}.
|
* <p>By default this is an instance of {@link AllEncompassingFormHttpMessageConverter}.
|
||||||
*/
|
*/
|
||||||
public void setFormConverter(FormHttpMessageConverter converter) {
|
public void setFormConverter(FormHttpMessageConverter converter) {
|
||||||
Assert.notNull(converter, "FormHttpMessageConverter is required.");
|
Assert.notNull(converter, "FormHttpMessageConverter is required");
|
||||||
this.formConverter = converter;
|
this.formConverter = converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,12 +84,12 @@ public class FormContentFilter extends OncePerRequestFilter {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
|
protected void doFilterInternal(
|
||||||
FilterChain filterChain) throws ServletException, IOException {
|
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
MultiValueMap<String, String> params = parseIfNecessary(request);
|
MultiValueMap<String, String> params = parseIfNecessary(request);
|
||||||
|
if (!CollectionUtils.isEmpty(params)) {
|
||||||
if (params != null && !params.isEmpty()) {
|
|
||||||
filterChain.doFilter(new FormContentRequestWrapper(request, params), response);
|
filterChain.doFilter(new FormContentRequestWrapper(request, params), response);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -99,19 +99,16 @@ public class FormContentFilter extends OncePerRequestFilter {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private MultiValueMap<String, String> parseIfNecessary(HttpServletRequest request) throws IOException {
|
private MultiValueMap<String, String> parseIfNecessary(HttpServletRequest request) throws IOException {
|
||||||
|
|
||||||
if (!shouldParse(request)) {
|
if (!shouldParse(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {
|
HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
return request.getInputStream();
|
return request.getInputStream();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.formConverter.read(null, inputMessage);
|
return this.formConverter.read(null, inputMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user