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");
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @since 3.0.6
|
||||
* @since 4.0
|
||||
*/
|
||||
abstract class AbstractBufferingAsyncClientHttpRequest
|
||||
extends AbstractAsyncClientHttpRequest {
|
||||
abstract class AbstractBufferingAsyncClientHttpRequest extends AbstractAsyncClientHttpRequest {
|
||||
|
||||
private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
@Override
|
||||
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
||||
return this.bufferedOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers)
|
||||
throws IOException {
|
||||
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers) throws IOException {
|
||||
byte[] bytes = this.bufferedOutput.toByteArray();
|
||||
if (headers.getContentLength() == -1) {
|
||||
headers.setContentLength(bytes.length);
|
||||
|
@ -52,9 +52,7 @@ abstract class AbstractBufferingAsyncClientHttpRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* Abstract template method that writes the given headers and content to the HTTP
|
||||
* request.
|
||||
*
|
||||
* Abstract template method that writes the given headers and content to the HTTP request.
|
||||
* @param headers the HTTP headers
|
||||
* @param bufferedOutput the body content
|
||||
* @return the response object for the executed request
|
||||
|
@ -62,5 +60,4 @@ abstract class AbstractBufferingAsyncClientHttpRequest
|
|||
protected abstract ListenableFuture<ClientHttpResponse> executeInternal(
|
||||
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");
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @since 3.0.6
|
||||
|
@ -32,6 +33,7 @@ abstract class AbstractBufferingClientHttpRequest extends AbstractClientHttpRequ
|
|||
|
||||
private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
@Override
|
||||
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
||||
return this.bufferedOutput;
|
||||
|
|
|
@ -66,8 +66,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||
|
||||
|
||||
/**
|
||||
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory} with
|
||||
* a default {@link HttpClient}.
|
||||
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
|
||||
* with a default {@link HttpClient}.
|
||||
*/
|
||||
public HttpComponentsClientHttpRequestFactory() {
|
||||
this(HttpClients.createSystem());
|
||||
|
@ -76,10 +76,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||
/**
|
||||
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
|
||||
* with the given {@link HttpClient} instance.
|
||||
* <p>
|
||||
* As of Spring Framework 4 the given client is expected to be of type
|
||||
* <p>As of Spring Framework 4.0, the given client is expected to be of type
|
||||
* CloseableHttpClient (requiring HttpClient 4.3+).
|
||||
*
|
||||
* @param httpClient the HttpClient instance to use for this request factory
|
||||
*/
|
||||
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
|
||||
|
@ -91,11 +89,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||
|
||||
/**
|
||||
* Set the {@code HttpClient} used for
|
||||
* <p>
|
||||
* As of Spring Framework 4 the given client is expected to be of type
|
||||
* <p>As of Spring Framework 4.0, the given client is expected to be of type
|
||||
* CloseableHttpClient (requiring HttpClient 4.3+).
|
||||
*
|
||||
* {@linkplain #createRequest(URI, HttpMethod) synchronous execution}.
|
||||
*/
|
||||
public void setHttpClient(HttpClient httpClient) {
|
||||
Assert.isInstanceOf(CloseableHttpClient.class, httpClient, "'httpClient' is not of type CloseableHttpClient");
|
||||
|
|
Loading…
Reference in New Issue