Polishing

Issue: SPR-12196
This commit is contained in:
Juergen Hoeller 2014-09-16 15:03:21 +02:00
parent 26a93b6a33
commit f394c8aa2a
3 changed files with 20 additions and 25 deletions

View File

@ -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.
@ -23,7 +23,8 @@ import org.springframework.http.HttpHeaders;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Abstract base for {@link ClientHttpRequest} that makes sure that headers and body are not written multiple times. * Abstract base for {@link ClientHttpRequest} that makes sure that headers
* and body are not written multiple times.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0 * @since 3.0
@ -55,8 +56,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
} }
/** /**
* Asserts that this request has not been {@linkplain #execute() executed} yet. * Assert that this request has not been {@linkplain #execute() executed} yet.
*
* @throws IllegalStateException if this request has been executed * @throws IllegalStateException if this request has been executed
*/ */
protected void assertNotExecuted() { protected void assertNotExecuted() {

View File

@ -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.
@ -28,7 +28,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* {@link ClientHttpRequestFactory} implementation that uses standard J2SE facilities. * {@link ClientHttpRequestFactory} implementation that uses standard JDK facilities.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Juergen Hoeller * @author Juergen Hoeller
@ -36,8 +36,7 @@ import org.springframework.util.Assert;
* @see java.net.HttpURLConnection * @see java.net.HttpURLConnection
* @see HttpComponentsClientHttpRequestFactory * @see HttpComponentsClientHttpRequestFactory
*/ */
public class SimpleClientHttpRequestFactory public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory {
implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory {
private static final int DEFAULT_CHUNK_SIZE = 4096; private static final int DEFAULT_CHUNK_SIZE = 4096;
@ -111,14 +110,12 @@ public class SimpleClientHttpRequestFactory
} }
/** /**
* Set if the underlying URLConnection can be set to 'output streaming' mode. When * Set if the underlying URLConnection can be set to 'output streaming' mode.
* output streaming is enabled, authentication and redirection cannot be handled * Default is {@code true}.
* automatically. If output streaming is disabled the * <p>When output streaming is enabled, authentication and redirection cannot be handled automatically.
* {@link HttpURLConnection#setFixedLengthStreamingMode(int) * If output streaming is disabled, the {@link HttpURLConnection#setFixedLengthStreamingMode} and
* setFixedLengthStreamingMode} and * {@link HttpURLConnection#setChunkedStreamingMode} methods of the underlying connection will never
* {@link HttpURLConnection#setChunkedStreamingMode(int) setChunkedStreamingMode} * be called.
* methods of the underlying connection will never be called.
* <p>Default is {@code true}.
* @param outputStreaming if output streaming is enabled * @param outputStreaming if output streaming is enabled
*/ */
public void setOutputStreaming(boolean outputStreaming) { public void setOutputStreaming(boolean outputStreaming) {
@ -126,15 +123,15 @@ public class SimpleClientHttpRequestFactory
} }
/** /**
* Sets the task executor for this request factory. Setting this property is required * Set the task executor for this request factory. Setting this property is required
* for {@linkplain #createAsyncRequest(URI, HttpMethod) creating asynchronous * for {@linkplain #createAsyncRequest(URI, HttpMethod) creating asynchronous requests}.
* request}.
* @param taskExecutor the task executor * @param taskExecutor the task executor
*/ */
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) { public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor; this.taskExecutor = taskExecutor;
} }
@Override @Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy); HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
@ -153,10 +150,8 @@ public class SimpleClientHttpRequestFactory
* is required before calling this method. * is required before calling this method.
*/ */
@Override @Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
throws IOException { Assert.state(this.taskExecutor != null, "Asynchronous execution requires an AsyncTaskExecutor to be set");
Assert.state(this.taskExecutor != null, "Asynchronous execution requires an " +
"AsyncTaskExecutor to be set");
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy); HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
prepareConnection(connection, httpMethod.name()); prepareConnection(connection, httpMethod.name());
if (this.bufferRequestBody) { if (this.bufferRequestBody) {

View File

@ -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"); * 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,7 +24,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* {@link ClientHttpResponse} implementation that uses standard J2SE facilities. * {@link ClientHttpResponse} implementation that uses standard JDK facilities.
* Obtained via {@link SimpleBufferingClientHttpRequest#execute()} and * Obtained via {@link SimpleBufferingClientHttpRequest#execute()} and
* {@link SimpleStreamingClientHttpRequest#execute()}. * {@link SimpleStreamingClientHttpRequest#execute()}.
* *