From 13283ec9189b90152ffd90184e8a9d14cf8bfa80 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 12 Oct 2015 23:24:36 +0200 Subject: [PATCH] Polishing --- .../org/springframework/util/StreamUtils.java | 6 ++--- .../BufferingClientHttpRequestFactory.java | 24 ++++++++++++------- .../BufferingClientHttpRequestWrapper.java | 4 +--- .../BufferingClientHttpResponseWrapper.java | 6 ++--- .../web/bind/annotation/ExceptionHandler.java | 15 ++++++------ .../web/bind/annotation/RequestMapping.java | 17 ++++++------- .../view/json/MappingJackson2JsonView.java | 9 +++---- 7 files changed, 45 insertions(+), 36 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/StreamUtils.java b/spring-core/src/main/java/org/springframework/util/StreamUtils.java index b08cc83230..0cfc2d9b65 100644 --- a/spring-core/src/main/java/org/springframework/util/StreamUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StreamUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -129,7 +129,7 @@ public abstract class StreamUtils { } /** - * Returns a variant of the given {@link InputStream} where calling + * Return a variant of the given {@link InputStream} where calling * {@link InputStream#close() close()} has no effect. * @param in the InputStream to decorate * @return a version of the InputStream that ignores calls to close @@ -140,7 +140,7 @@ public abstract class StreamUtils { } /** - * Returns a variant of the given {@link OutputStream} where calling + * Return a variant of the given {@link OutputStream} where calling * {@link OutputStream#close() close()} has no effect. * @param out the OutputStream to decorate * @return a version of the OutputStream that ignores calls to close diff --git a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestFactory.java index 47517bf1dc..3f3b418514 100644 --- a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2015 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. @@ -22,22 +22,30 @@ import java.net.URI; import org.springframework.http.HttpMethod; /** - * Wrapper for a {@link ClientHttpRequestFactory} that buffers all outgoing and incoming streams in memory. + * Wrapper for a {@link ClientHttpRequestFactory} that buffers + * all outgoing and incoming streams in memory. * - *

Using this wrapper allows for multiple reads of the {@linkplain ClientHttpResponse#getBody() response body}. + *

Using this wrapper allows for multiple reads of the + * @linkplain ClientHttpResponse#getBody() response body}. * * @author Arjen Poutsma * @since 3.1 */ public class BufferingClientHttpRequestFactory extends AbstractClientHttpRequestFactoryWrapper { + /** + * Create a buffering wrapper for the given {@link ClientHttpRequestFactory}. + * @param requestFactory the target request factory to wrap + */ public BufferingClientHttpRequestFactory(ClientHttpRequestFactory requestFactory) { super(requestFactory); } + @Override protected ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod, ClientHttpRequestFactory requestFactory) throws IOException { + ClientHttpRequest request = requestFactory.createRequest(uri, httpMethod); if (shouldBuffer(uri, httpMethod)) { return new BufferingClientHttpRequestWrapper(request); @@ -48,11 +56,10 @@ public class BufferingClientHttpRequestFactory extends AbstractClientHttpRequest } /** - * Indicates whether the request/response exchange for the given URI and method should be buffered in memory. - * - *

Default implementation returns {@code true} for all URIs and methods. Subclasses can override this method to - * change this behavior. - * + * Indicates whether the request/response exchange for the given URI and method + * should be buffered in memory. + *

The default implementation returns {@code true} for all URIs and methods. + * Subclasses can override this method to change this behavior. * @param uri the URI * @param httpMethod the method * @return {@code true} if the exchange should be buffered; {@code false} otherwise @@ -60,4 +67,5 @@ public class BufferingClientHttpRequestFactory extends AbstractClientHttpRequest protected boolean shouldBuffer(URI uri, HttpMethod httpMethod) { return true; } + } diff --git a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java index 204dc67d7d..1de5a5e487 100644 --- a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java +++ b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -21,7 +21,6 @@ import java.net.URI; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.util.Assert; import org.springframework.util.StreamUtils; /** @@ -36,7 +35,6 @@ final class BufferingClientHttpRequestWrapper extends AbstractBufferingClientHtt BufferingClientHttpRequestWrapper(ClientHttpRequest request) { - Assert.notNull(request, "'request' must not be null"); this.request = request; } diff --git a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java index 10f3de0079..297218281a 100644 --- a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java +++ b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -25,8 +25,8 @@ import org.springframework.http.HttpStatus; import org.springframework.util.StreamUtils; /** - * Simple implementation of {@link ClientHttpResponse} that reads the response's body into memory, - * thus allowing for multiple invocations of {@link #getBody()}. + * Simple implementation of {@link ClientHttpResponse} that reads the response's body + * into memory, thus allowing for multiple invocations of {@link #getBody()}. * * @author Arjen Poutsma * @since 3.1 diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java index b21bd6ac5c..1b646bbc02 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -27,8 +27,8 @@ import java.lang.annotation.Target; * handler methods. Provides consistent style between Servlet and Portlet * environments, with the semantics adapting to the concrete environment. * - *

Handler methods which are annotated with this annotation are allowed - * to have very flexible signatures. They may have arguments of the following + *

Handler methods which are annotated with this annotation are allowed to + * have very flexible signatures. They may have parameters of the following * types, in arbitrary order: *