Browse Source

Polishing

pull/689/head
Juergen Hoeller 12 years ago
parent
commit
3264437cec
  1. 14
      spring-web/src/main/java/org/springframework/http/HttpEntity.java
  2. 6
      spring-web/src/main/java/org/springframework/http/ResponseEntity.java
  3. 21
      spring-web/src/main/java/org/springframework/web/client/RestOperations.java
  4. 6
      spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

14
spring-web/src/main/java/org/springframework/http/HttpEntity.java

@ -1,5 +1,5 @@ @@ -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<T> { @@ -138,20 +138,20 @@ public class HttpEntity<T> {
@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();

6
spring-web/src/main/java/org/springframework/http/ResponseEntity.java

@ -106,16 +106,16 @@ public class ResponseEntity<T> extends HttpEntity<T> { @@ -106,16 +106,16 @@ public class ResponseEntity<T> extends HttpEntity<T> {
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

21
spring-web/src/main/java/org/springframework/web/client/RestOperations.java

@ -1,5 +1,5 @@ @@ -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 { @@ -105,6 +105,7 @@ public interface RestOperations {
*/
<T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws RestClientException;
// HEAD
/**
@ -132,6 +133,7 @@ public interface RestOperations { @@ -132,6 +133,7 @@ public interface RestOperations {
*/
HttpHeaders headForHeaders(URI url) throws RestClientException;
// POST
/**
@ -264,6 +266,7 @@ public interface RestOperations { @@ -264,6 +266,7 @@ public interface RestOperations {
*/
<T> ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType) throws RestClientException;
// PUT
/**
@ -300,6 +303,7 @@ public interface RestOperations { @@ -300,6 +303,7 @@ public interface RestOperations {
*/
void put(URI url, Object request) throws RestClientException;
// DELETE
/**
@ -325,6 +329,7 @@ public interface RestOperations { @@ -325,6 +329,7 @@ public interface RestOperations {
*/
void delete(URI url) throws RestClientException;
// OPTIONS
/**
@ -352,6 +357,7 @@ public interface RestOperations { @@ -352,6 +357,7 @@ public interface RestOperations {
*/
Set<HttpMethod> optionsForAllow(URI url) throws RestClientException;
// exchange
/**
@ -401,12 +407,10 @@ public interface RestOperations { @@ -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:
*
* <pre class="code">
* ParameterizedTypeReference&lt;List&lt;MyBean&gt;&gt; myBean = new ParameterizedTypeReference&lt;List&lt;MyBean&gt;&gt;() {};
* ResponseEntity&lt;List&lt;MyBean&gt;&gt; response = template.exchange(&quot;http://example.com&quot;,HttpMethod.GET, null, myBean);
* </pre>
*
* @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 { @@ -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
*/
<T> ResponseEntity<T> exchange(String url,HttpMethod method, HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException;
@ -423,19 +427,17 @@ public interface RestOperations { @@ -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:
*
* <pre class="code">
* ParameterizedTypeReference&lt;List&lt;MyBean&gt;&gt; myBean = new ParameterizedTypeReference&lt;List&lt;MyBean&gt;&gt;() {};
* ResponseEntity&lt;List&lt;MyBean&gt;&gt; response = template.exchange(&quot;http://example.com&quot;,HttpMethod.GET, null, myBean);
* </pre>
*
* @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
*/
<T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException;
@ -444,22 +446,21 @@ public interface RestOperations { @@ -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:
*
* <pre class="code">
* ParameterizedTypeReference&lt;List&lt;MyBean&gt;&gt; myBean = new ParameterizedTypeReference&lt;List&lt;MyBean&gt;&gt;() {};
* ResponseEntity&lt;List&lt;MyBean&gt;&gt; response = template.exchange(&quot;http://example.com&quot;,HttpMethod.GET, null, myBean);
* </pre>
*
* @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
*/
<T> ResponseEntity<T> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType) throws RestClientException;
// general execution
/**

6
spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

@ -280,6 +280,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -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 @@ -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 @@ -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 @@ -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 @@ -397,6 +401,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
execute(url, HttpMethod.DELETE, null, null);
}
// OPTIONS
public Set<HttpMethod> optionsForAllow(String url, Object... urlVariables) throws RestClientException {
@ -414,6 +419,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -414,6 +419,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
return headers.getAllow();
}
// exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method,

Loading…
Cancel
Save