polishing

This commit is contained in:
Juergen Hoeller
2011-07-13 23:03:50 +00:00
parent 210c77ddb0
commit 8041f6abdd
2 changed files with 11 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2011 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.
@@ -58,7 +58,7 @@ public class CommonsClientHttpRequestFactory implements ClientHttpRequestFactory
* {@link HttpClient} that uses a default {@link MultiThreadedHttpConnectionManager}. * {@link HttpClient} that uses a default {@link MultiThreadedHttpConnectionManager}.
*/ */
public CommonsClientHttpRequestFactory() { public CommonsClientHttpRequestFactory() {
httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); this.httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
this.setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS); this.setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2011 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.
@@ -30,21 +30,23 @@ import org.springframework.util.Assert;
* {@link ClientHttpRequestFactory} implementation that uses standard J2SE facilities. * {@link ClientHttpRequestFactory} implementation that uses standard J2SE facilities.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0
* @see java.net.HttpURLConnection * @see java.net.HttpURLConnection
* @see CommonsClientHttpRequestFactory * @see CommonsClientHttpRequestFactory
* @since 3.0
*/ */
public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory { public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory {
private Proxy proxy; private Proxy proxy;
/** /**
* Sets the {@link Proxy} to use for this request factory. * Set the {@link Proxy} to use for this request factory.
*/ */
public void setProxy(Proxy proxy) { public void setProxy(Proxy proxy) {
this.proxy = proxy; this.proxy = proxy;
} }
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpURLConnection connection = openConnection(uri.toURL(), proxy); HttpURLConnection connection = openConnection(uri.toURL(), proxy);
prepareConnection(connection, httpMethod.name()); prepareConnection(connection, httpMethod.name());
@@ -53,16 +55,15 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory
/** /**
* Opens and returns a connection to the given URL. * Opens and returns a connection to the given URL.
* <p>The default implementation uses the given {@linkplain #setProxy(java.net.Proxy) proxy} - if any - to open a * <p>The default implementation uses the given {@linkplain #setProxy(java.net.Proxy) proxy} -
* connection. * if any - to open a connection.
*
* @param url the URL to open a connection to * @param url the URL to open a connection to
* @param proxy the proxy to use, may be {@code null} * @param proxy the proxy to use, may be {@code null}
* @return the opened connection * @return the opened connection
* @throws IOException in case of I/O errors * @throws IOException in case of I/O errors
*/ */
protected HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException { protected HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException {
URLConnection urlConnection = proxy != null ? url.openConnection(proxy) : url.openConnection(); URLConnection urlConnection = (proxy != null ? url.openConnection(proxy) : url.openConnection());
Assert.isInstanceOf(HttpURLConnection.class, urlConnection); Assert.isInstanceOf(HttpURLConnection.class, urlConnection);
return (HttpURLConnection) urlConnection; return (HttpURLConnection) urlConnection;
} }
@@ -70,7 +71,6 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory
/** /**
* Template method for preparing the given {@link HttpURLConnection}. * Template method for preparing the given {@link HttpURLConnection}.
* <p>The default implementation prepares the connection for input and output, and sets the HTTP method. * <p>The default implementation prepares the connection for input and output, and sets the HTTP method.
*
* @param connection the connection to prepare * @param connection the connection to prepare
* @param httpMethod the HTTP request method ({@code GET}, {@code POST}, etc.) * @param httpMethod the HTTP request method ({@code GET}, {@code POST}, etc.)
* @throws IOException in case of I/O errors * @throws IOException in case of I/O errors