From d765698ac358d5721b243bce3ccfe6e725bd297c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 4 Sep 2014 03:06:37 +0200 Subject: [PATCH] Polishing --- .../ListenableFutureCallbackRegistry.java | 6 ++-- .../concurrent/ListenableFutureTaskTests.java | 5 ++- .../bind/support/WebRequestDataBinder.java | 36 +++++++------------ 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java index 0f1873de5ff..ec328f14368 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java @@ -42,7 +42,7 @@ public class ListenableFutureCallbackRegistry { /** - * Adds the given callback to this registry. + * Add the given callback to this registry. * @param callback the callback to add */ @SuppressWarnings("unchecked") @@ -64,7 +64,7 @@ public class ListenableFutureCallbackRegistry { } /** - * Triggers a {@link ListenableFutureCallback#onSuccess(Object)} call on all + * Trigger a {@link ListenableFutureCallback#onSuccess(Object)} call on all * added callbacks with the given result. * @param result the result to trigger the callbacks with */ @@ -79,7 +79,7 @@ public class ListenableFutureCallbackRegistry { } /** - * Triggers a {@link ListenableFutureCallback#onFailure(Throwable)} call on all + * Trigger a {@link ListenableFutureCallback#onFailure(Throwable)} call on all * added callbacks with the given {@code Throwable}. * @param ex the exception to trigger the callbacks with */ diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java index 66eb49d1e9c..e5c956eee1e 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java @@ -18,7 +18,6 @@ package org.springframework.util.concurrent; import java.io.IOException; import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; import org.junit.Test; @@ -30,7 +29,7 @@ import static org.junit.Assert.*; public class ListenableFutureTaskTests { @Test - public void success() throws ExecutionException, InterruptedException { + public void success() throws Exception { final String s = "Hello World"; Callable callable = new Callable() { @Override @@ -53,7 +52,7 @@ public class ListenableFutureTaskTests { } @Test - public void failure() throws ExecutionException, InterruptedException { + public void failure() throws Exception { final String s = "Hello World"; Callable callable = new Callable() { @Override diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java index 1b88177cc2b..94b40ae979f 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -16,11 +16,8 @@ package org.springframework.web.bind.support; -import java.io.IOException; import java.util.List; import java.util.Map; - -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Part; @@ -73,7 +70,6 @@ import org.springframework.web.multipart.MultipartRequest; */ public class WebRequestDataBinder extends WebDataBinder { - /** * Create a new WebRequestDataBinder instance, with default object name. * @param target the target object to bind onto (or {@code null} @@ -115,8 +111,7 @@ public class WebRequestDataBinder extends WebDataBinder { */ public void bind(WebRequest request) { MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap()); - - if (isMultipartRequest(request) && (request instanceof NativeWebRequest)) { + if (isMultipartRequest(request) && request instanceof NativeWebRequest) { MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class); if (multipartRequest != null) { bindMultipart(multipartRequest.getMultiFileMap(), mpvs); @@ -129,6 +124,15 @@ public class WebRequestDataBinder extends WebDataBinder { doBind(mpvs); } + /** + * Check if the request is a multipart request (by checking its Content-Type header). + * @param request request with parameters to bind + */ + private boolean isMultipartRequest(WebRequest request) { + String contentType = request.getHeader("Content-Type"); + return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart")); + } + /** * Treats errors as fatal. *

Use this method only if it's an error if the input isn't valid. @@ -141,16 +145,6 @@ public class WebRequestDataBinder extends WebDataBinder { } } - /** - * Check if the request is a multipart request (by checking its Content-Type header). - * - * @param request request with parameters to bind - */ - private boolean isMultipartRequest(WebRequest request) { - String contentType = request.getHeader("Content-Type"); - return ((contentType != null) && StringUtils.startsWithIgnoreCase(contentType, "multipart")); - } - /** * Encapsulate Part binding code for Servlet 3.0+ only containers. @@ -160,12 +154,10 @@ public class WebRequestDataBinder extends WebDataBinder { private final boolean bindEmptyMultipartFiles; - public Servlet3MultipartHelper(boolean bindEmptyMultipartFiles) { this.bindEmptyMultipartFiles = bindEmptyMultipartFiles; } - public void bindParts(HttpServletRequest request, MutablePropertyValues mpvs) { try { MultiValueMap map = new LinkedMultiValueMap(); @@ -184,14 +176,10 @@ public class WebRequestDataBinder extends WebDataBinder { } } } - catch (IOException ex) { - throw new MultipartException("Failed to get request parts", ex); - } - catch(ServletException ex) { + catch (Exception ex) { throw new MultipartException("Failed to get request parts", ex); } } - } }