Polishing
This commit is contained in:
parent
7972b31118
commit
3080ff3890
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -24,24 +24,24 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.util.concurrent.ListenableFuture;
|
import org.springframework.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base for {@link org.springframework.http.client.ClientHttpRequest} that buffers output in a byte array before sending it over the wire.
|
* Base implementation of {@link AsyncClientHttpRequest} that buffers output
|
||||||
|
* in a byte array before sending it over the wire.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 3.0.6
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
abstract class AbstractBufferingAsyncClientHttpRequest
|
abstract class AbstractBufferingAsyncClientHttpRequest extends AbstractAsyncClientHttpRequest {
|
||||||
extends AbstractAsyncClientHttpRequest {
|
|
||||||
|
|
||||||
private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream();
|
private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
||||||
return this.bufferedOutput;
|
return this.bufferedOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers)
|
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers) throws IOException {
|
||||||
throws IOException {
|
|
||||||
byte[] bytes = this.bufferedOutput.toByteArray();
|
byte[] bytes = this.bufferedOutput.toByteArray();
|
||||||
if (headers.getContentLength() == -1) {
|
if (headers.getContentLength() == -1) {
|
||||||
headers.setContentLength(bytes.length);
|
headers.setContentLength(bytes.length);
|
||||||
|
@ -52,9 +52,7 @@ abstract class AbstractBufferingAsyncClientHttpRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract template method that writes the given headers and content to the HTTP
|
* Abstract template method that writes the given headers and content to the HTTP request.
|
||||||
* request.
|
|
||||||
*
|
|
||||||
* @param headers the HTTP headers
|
* @param headers the HTTP headers
|
||||||
* @param bufferedOutput the body content
|
* @param bufferedOutput the body content
|
||||||
* @return the response object for the executed request
|
* @return the response object for the executed request
|
||||||
|
@ -62,5 +60,4 @@ abstract class AbstractBufferingAsyncClientHttpRequest
|
||||||
protected abstract ListenableFuture<ClientHttpResponse> executeInternal(
|
protected abstract ListenableFuture<ClientHttpResponse> executeInternal(
|
||||||
HttpHeaders headers, byte[] bufferedOutput) throws IOException;
|
HttpHeaders headers, byte[] bufferedOutput) throws IOException;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,7 +23,8 @@ import java.io.OutputStream;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base for {@link ClientHttpRequest} that buffers output in a byte array before sending it over the wire.
|
* Base implementation of {@link ClientHttpRequest} that buffers output
|
||||||
|
* in a byte array before sending it over the wire.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 3.0.6
|
* @since 3.0.6
|
||||||
|
@ -32,6 +33,7 @@ abstract class AbstractBufferingClientHttpRequest extends AbstractClientHttpRequ
|
||||||
|
|
||||||
private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream();
|
private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
||||||
return this.bufferedOutput;
|
return this.bufferedOutput;
|
||||||
|
|
|
@ -66,8 +66,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory} with
|
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
|
||||||
* a default {@link HttpClient}.
|
* with a default {@link HttpClient}.
|
||||||
*/
|
*/
|
||||||
public HttpComponentsClientHttpRequestFactory() {
|
public HttpComponentsClientHttpRequestFactory() {
|
||||||
this(HttpClients.createSystem());
|
this(HttpClients.createSystem());
|
||||||
|
@ -76,10 +76,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
||||||
/**
|
/**
|
||||||
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
|
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
|
||||||
* with the given {@link HttpClient} instance.
|
* with the given {@link HttpClient} instance.
|
||||||
* <p>
|
* <p>As of Spring Framework 4.0, the given client is expected to be of type
|
||||||
* As of Spring Framework 4 the given client is expected to be of type
|
|
||||||
* CloseableHttpClient (requiring HttpClient 4.3+).
|
* CloseableHttpClient (requiring HttpClient 4.3+).
|
||||||
*
|
|
||||||
* @param httpClient the HttpClient instance to use for this request factory
|
* @param httpClient the HttpClient instance to use for this request factory
|
||||||
*/
|
*/
|
||||||
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
|
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
|
||||||
|
@ -91,11 +89,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@code HttpClient} used for
|
* Set the {@code HttpClient} used for
|
||||||
* <p>
|
* <p>As of Spring Framework 4.0, the given client is expected to be of type
|
||||||
* As of Spring Framework 4 the given client is expected to be of type
|
|
||||||
* CloseableHttpClient (requiring HttpClient 4.3+).
|
* CloseableHttpClient (requiring HttpClient 4.3+).
|
||||||
*
|
|
||||||
* {@linkplain #createRequest(URI, HttpMethod) synchronous execution}.
|
|
||||||
*/
|
*/
|
||||||
public void setHttpClient(HttpClient httpClient) {
|
public void setHttpClient(HttpClient httpClient) {
|
||||||
Assert.isInstanceOf(CloseableHttpClient.class, httpClient, "'httpClient' is not of type CloseableHttpClient");
|
Assert.isInstanceOf(CloseableHttpClient.class, httpClient, "'httpClient' is not of type CloseableHttpClient");
|
||||||
|
|
Loading…
Reference in New Issue