Polishing
This commit is contained in:
@@ -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> {
|
||||
|
||||
@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();
|
||||
|
||||
@@ -128,20 +128,20 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof RequestEntity)) {
|
||||
if (!(other instanceof RequestEntity) || !super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
RequestEntity<?> otherEntity = (RequestEntity<?>) other;
|
||||
return (ObjectUtils.nullSafeEquals(this.method, otherEntity.method) &&
|
||||
ObjectUtils.nullSafeEquals(this.url, otherEntity.url) &&
|
||||
super.equals(other));
|
||||
ObjectUtils.nullSafeEquals(this.url, otherEntity.url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 29 * super.hashCode() +
|
||||
29 * ObjectUtils.nullSafeHashCode(this.method) +
|
||||
ObjectUtils.nullSafeHashCode(this.url);
|
||||
int hashCode = super.hashCode();
|
||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.method);
|
||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.url);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,6 +166,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
// Static builder methods
|
||||
|
||||
/**
|
||||
@@ -422,6 +423,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return method(HttpMethod.OPTIONS, url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines a builder that adds headers to the request entity.
|
||||
* @param <B> the builder subclass
|
||||
@@ -471,9 +473,9 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @see BodyBuilder#body(Object)
|
||||
*/
|
||||
RequestEntity<Void> build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines a builder that adds a body to the response entity.
|
||||
*/
|
||||
@@ -504,9 +506,9 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the built request entity
|
||||
*/
|
||||
<T> RequestEntity<T> body(T body);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class DefaultBodyBuilder implements BodyBuilder {
|
||||
|
||||
private final HttpMethod method;
|
||||
@@ -515,7 +517,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
|
||||
private final HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
|
||||
public DefaultBodyBuilder(HttpMethod method, URI url) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
|
||||
@@ -121,16 +121,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
|
||||
|
||||
@@ -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.
|
||||
@@ -107,6 +107,7 @@ public interface RestOperations {
|
||||
*/
|
||||
<T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws RestClientException;
|
||||
|
||||
|
||||
// HEAD
|
||||
|
||||
/**
|
||||
@@ -134,6 +135,7 @@ public interface RestOperations {
|
||||
*/
|
||||
HttpHeaders headForHeaders(URI url) throws RestClientException;
|
||||
|
||||
|
||||
// POST
|
||||
|
||||
/**
|
||||
@@ -266,6 +268,7 @@ public interface RestOperations {
|
||||
*/
|
||||
<T> ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType) throws RestClientException;
|
||||
|
||||
|
||||
// PUT
|
||||
|
||||
/**
|
||||
@@ -302,6 +305,7 @@ public interface RestOperations {
|
||||
*/
|
||||
void put(URI url, Object request) throws RestClientException;
|
||||
|
||||
|
||||
// DELETE
|
||||
|
||||
/**
|
||||
@@ -327,6 +331,7 @@ public interface RestOperations {
|
||||
*/
|
||||
void delete(URI url) throws RestClientException;
|
||||
|
||||
|
||||
// OPTIONS
|
||||
|
||||
/**
|
||||
@@ -354,6 +359,7 @@ public interface RestOperations {
|
||||
*/
|
||||
Set<HttpMethod> optionsForAllow(URI url) throws RestClientException;
|
||||
|
||||
|
||||
// exchange
|
||||
|
||||
/**
|
||||
@@ -403,12 +409,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<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",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
|
||||
@@ -416,7 +420,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;
|
||||
@@ -425,19 +429,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<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",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;
|
||||
@@ -446,18 +448,16 @@ 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<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
* ResponseEntity<List<MyBean>> response = template.exchange("http://example.com",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;
|
||||
@@ -466,40 +466,35 @@ public interface RestOperations {
|
||||
* Execute the request specified in the given {@link RequestEntity} and return
|
||||
* the response as {@link ResponseEntity}. Typically used in combination
|
||||
* with the static builder methods on {@code RequestEntity}, for instance:
|
||||
*
|
||||
* <pre class="code">
|
||||
* MyRequest body = ...
|
||||
* RequestEntity request = RequestEntity.post("http://example.com/{foo}", "bar").accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
|
||||
* </pre>
|
||||
*
|
||||
* @param requestEntity the entity to write to the request
|
||||
* @param responseType the type of the return value
|
||||
* @return the response as entity
|
||||
* @since 4.1
|
||||
*/
|
||||
<T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity,
|
||||
Class<T> responseType) throws RestClientException;
|
||||
<T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, Class<T> responseType) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Execute the request specified in the given {@link RequestEntity} and return
|
||||
* the response as {@link ResponseEntity}. The given
|
||||
* {@link ParameterizedTypeReference} is used to pass generic type information:
|
||||
*
|
||||
* <pre class="code">
|
||||
* MyRequest body = ...
|
||||
* RequestEntity request = RequestEntity.post("http://example.com/{foo}", "bar").accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* ParameterizedTypeReference<List<MyResponse>> myBean = new ParameterizedTypeReference<List<MyResponse>>() {};
|
||||
* ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
|
||||
* </pre>
|
||||
*
|
||||
* @param requestEntity the entity to write to the request
|
||||
* @param responseType the type of the return value
|
||||
* @return the response as entity
|
||||
* @since 4.1
|
||||
*/
|
||||
<T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType) throws RestClientException;
|
||||
<T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
|
||||
throws RestClientException;
|
||||
|
||||
|
||||
// general execution
|
||||
|
||||
@@ -269,6 +269,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
return execute(url, HttpMethod.GET, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
|
||||
// HEAD
|
||||
|
||||
@Override
|
||||
@@ -286,6 +287,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
return execute(url, HttpMethod.HEAD, null, headersExtractor());
|
||||
}
|
||||
|
||||
|
||||
// POST
|
||||
|
||||
@Override
|
||||
@@ -362,6 +364,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
return execute(url, HttpMethod.POST, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
|
||||
// PUT
|
||||
|
||||
@Override
|
||||
@@ -382,6 +385,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
execute(url, HttpMethod.PUT, requestCallback, null);
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
|
||||
@Override
|
||||
@@ -399,6 +403,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
execute(url, HttpMethod.DELETE, null, null);
|
||||
}
|
||||
|
||||
|
||||
// OPTIONS
|
||||
|
||||
@Override
|
||||
@@ -422,6 +427,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
return headers.getAllow();
|
||||
}
|
||||
|
||||
|
||||
// exchange
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user