From 3264437cecc238a657169ece7439f145ae48f394 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 4 Sep 2014 02:37:36 +0200 Subject: [PATCH] Polishing --- .../org/springframework/http/HttpEntity.java | 14 ++++++------- .../springframework/http/ResponseEntity.java | 6 +++--- .../web/client/RestOperations.java | 21 ++++++++++--------- .../web/client/RestTemplate.java | 6 ++++++ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/HttpEntity.java b/spring-web/src/main/java/org/springframework/http/HttpEntity.java index c876d8fe708..436a2b6337b 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpEntity.java +++ b/spring-web/src/main/java/org/springframework/http/HttpEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -138,20 +138,20 @@ public class HttpEntity { @Override public int hashCode() { - return ObjectUtils.nullSafeHashCode(this.headers) * 29 + ObjectUtils.nullSafeHashCode(this.body); + return (ObjectUtils.nullSafeHashCode(this.headers) * 29 + ObjectUtils.nullSafeHashCode(this.body)); } @Override public String toString() { StringBuilder builder = new StringBuilder("<"); - if (body != null) { - builder.append(body); - if (headers != null) { + if (this.body != null) { + builder.append(this.body); + if (this.headers != null) { builder.append(','); } } - if (headers != null) { - builder.append(headers); + if (this.headers != null) { + builder.append(this.headers); } builder.append('>'); return builder.toString(); diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java index e4451aec28d..69c2a31e270 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -106,16 +106,16 @@ public class ResponseEntity extends HttpEntity { if (this == other) { return true; } - if (!(other instanceof ResponseEntity)) { + if (!(other instanceof ResponseEntity) || !super.equals(other)) { return false; } ResponseEntity otherEntity = (ResponseEntity) other; - return (ObjectUtils.nullSafeEquals(this.statusCode, otherEntity.statusCode) && super.equals(other)); + return ObjectUtils.nullSafeEquals(this.statusCode, otherEntity.statusCode); } @Override public int hashCode() { - return super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.statusCode); + return (super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.statusCode)); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java b/spring-web/src/main/java/org/springframework/web/client/RestOperations.java index 62ea452dd37..d1e0caf8fc2 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -105,6 +105,7 @@ public interface RestOperations { */ ResponseEntity getForEntity(URI url, Class responseType) throws RestClientException; + // HEAD /** @@ -132,6 +133,7 @@ public interface RestOperations { */ HttpHeaders headForHeaders(URI url) throws RestClientException; + // POST /** @@ -264,6 +266,7 @@ public interface RestOperations { */ ResponseEntity postForEntity(URI url, Object request, Class responseType) throws RestClientException; + // PUT /** @@ -300,6 +303,7 @@ public interface RestOperations { */ void put(URI url, Object request) throws RestClientException; + // DELETE /** @@ -325,6 +329,7 @@ public interface RestOperations { */ void delete(URI url) throws RestClientException; + // OPTIONS /** @@ -352,6 +357,7 @@ public interface RestOperations { */ Set optionsForAllow(URI url) throws RestClientException; + // exchange /** @@ -401,12 +407,10 @@ public interface RestOperations { * Execute the HTTP method to the given URI template, writing the given * request entity to the request, and returns the response as {@link ResponseEntity}. * The given {@link ParameterizedTypeReference} is used to pass generic type information: - * *
 	 * ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
 	 * ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",HttpMethod.GET, null, myBean);
 	 * 
- * * @param url the URL * @param method the HTTP method (GET, POST, etc) * @param requestEntity the entity (headers and/or body) to write to the @@ -414,7 +418,7 @@ public interface RestOperations { * @param responseType the type of the return value * @param uriVariables the variables to expand in the template * @return the response as entity - * @since 3.2.0 + * @since 3.2 */ ResponseEntity exchange(String url,HttpMethod method, HttpEntity requestEntity, ParameterizedTypeReference responseType, Object... uriVariables) throws RestClientException; @@ -423,19 +427,17 @@ public interface RestOperations { * Execute the HTTP method to the given URI template, writing the given * request entity to the request, and returns the response as {@link ResponseEntity}. * The given {@link ParameterizedTypeReference} is used to pass generic type information: - * *
 	 * ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
 	 * ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",HttpMethod.GET, null, myBean);
 	 * 
- * * @param url the URL * @param method the HTTP method (GET, POST, etc) * @param requestEntity the entity (headers and/or body) to write to the request, may be {@code null} * @param responseType the type of the return value * @param uriVariables the variables to expand in the template * @return the response as entity - * @since 3.2.0 + * @since 3.2 */ ResponseEntity exchange(String url, HttpMethod method, HttpEntity requestEntity, ParameterizedTypeReference responseType, Map uriVariables) throws RestClientException; @@ -444,22 +446,21 @@ public interface RestOperations { * Execute the HTTP method to the given URI template, writing the given * request entity to the request, and returns the response as {@link ResponseEntity}. * The given {@link ParameterizedTypeReference} is used to pass generic type information: - * *
 	 * ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
 	 * ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",HttpMethod.GET, null, myBean);
 	 * 
- * * @param url the URL * @param method the HTTP method (GET, POST, etc) * @param requestEntity the entity (headers and/or body) to write to the request, may be {@code null} * @param responseType the type of the return value * @return the response as entity - * @since 3.2.0 + * @since 3.2 */ ResponseEntity exchange(URI url, HttpMethod method, HttpEntity requestEntity, ParameterizedTypeReference responseType) throws RestClientException; + // general execution /** diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 60481c904b7..825a5bacbfd 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -280,6 +280,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat return execute(url, HttpMethod.GET, requestCallback, responseExtractor); } + // HEAD public HttpHeaders headForHeaders(String url, Object... urlVariables) throws RestClientException { @@ -294,6 +295,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat return execute(url, HttpMethod.HEAD, null, this.headersExtractor); } + // POST public URI postForLocation(String url, Object request, Object... urlVariables) throws RestClientException { @@ -366,6 +368,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat return execute(url, HttpMethod.POST, requestCallback, responseExtractor); } + // PUT public void put(String url, Object request, Object... urlVariables) throws RestClientException { @@ -383,6 +386,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat execute(url, HttpMethod.PUT, requestCallback, null); } + // DELETE public void delete(String url, Object... urlVariables) throws RestClientException { @@ -397,6 +401,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat execute(url, HttpMethod.DELETE, null, null); } + // OPTIONS public Set optionsForAllow(String url, Object... urlVariables) throws RestClientException { @@ -414,6 +419,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat return headers.getAllow(); } + // exchange public ResponseEntity exchange(String url, HttpMethod method,