Merge branch 'release-preparation'

This commit is contained in:
Oleg Kalnichevski 2019-04-03 09:40:14 +02:00
commit 8ccdf119c6
43 changed files with 169 additions and 113 deletions

View File

@ -1,26 +1,14 @@
Release 5.0-BETA4
-------------------
* Update Apache Commons Codec from 1.11 to 1.12
Contributed by Gary Gregory <ggregory at apache.org>
* Update RxJava from 2.2.2 to 2.2.7
Contributed by Gary Gregory <ggregory at apache.org>
* Update JNA from 5.0.0 to 5.2.0
Contributed by Gary Gregory <ggregory at apache.org>
Release 5.0-BETA3
-------------------
This BETA release adds support for advanced TLS functions (such as ALPN protocol negotiation)
on Java 1.7 and Java 1.8 through Conscrypt TLS library and picks up the latest fixes
and performance improvements from HttpCore.
This BETA release picks up the latest fixes and performance improvements from HttpCore
and addresses a number of issues found since the previous BETA release.
Notable features in this release:
* TLS ALPN protocol negotiation support on older JREs through Conscrypt TLS library.
* Security improvements.
* URI handling improvements.
Notable changes and features included in the 5.0 series are:
@ -60,6 +48,75 @@ and documentation improvements.
Changelog:
-------------------
* HTTPCLIENT-1976: Unsafe deserialization in DefaultHttpCacheEntrySerializer.
Contributed by Artem Smotrakov <artem.smotrakov at gmail.com>
* HTTPCLIENT-1969: Filter out weak cipher suites.
Contributed by Artem Smotrakov <artem.smotrakov at gmail.com>
* HttpClient should not retry requests in case of ConnectionClosedException
Contributed by Oleg Kalnichevski <olegk at apache.org>
* Bug fix: Simple response consumer to discard stored content when releasing resources.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* Bug fix: main async request execution handlers to release the associated response consumer
upon exception.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* Update Apache Commons Codec from 1.11 to 1.12.
Contributed by Gary Gregory <ggregory at apache.org>
* Update RxJava from 2.2.2 to 2.2.7.
Contributed by Gary Gregory <ggregory at apache.org>
* Update JNA from 5.0.0 to 5.2.0.
Contributed by Gary Gregory <ggregory at apache.org>
* Some well known proxies respond with Content-Length=0, when returning 304. For robustness,
always use the cached entity's content length, as modern browsers do.
Contributed by Jayson Raymond <Jayson.Raymond15 at T-Mobile.com>
* HTTPCLIENT-1960: URIBuilder incorrect handling of multiple leading slashes in path component.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* HTTPCLIENT-1958: PoolingHttpClientConnectionManager to throw ExecutionException
in case of a lease operation cancellation instead of InterruptedException.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* Shutdown executorService on AbstractHttpAsyncClientBase shutdown.
Contributed by 吴雪山 <xueshan.wu at ndkey.com.cn>
* [HTTPCLIENT-1952: Allow default User Agent to be disabled
Contributed by Michael Osipov <michaelo at apache.org>
* Improve HttpResponseException#getMessage.
Contributed by Michael Osipov <michaelo at apache.org>
* Better handling of http(s).proxyUser and http(s).proxyPassword
Contributed by Jens Borgland <jborglan at tibco.com>
* Wrong argument name in PoolingAsyncClientConnectionManagerBuilder#setConnPoolPolicy results
with self assignment of variable.
Contributed by Eryk Szymanski <eszymanski at collab.net>
Release 5.0-BETA3
-------------------
This BETA release adds support for advanced TLS functions (such as ALPN protocol negotiation)
on Java 1.7 and Java 1.8 through Conscrypt TLS library and picks up the latest fixes
and performance improvements from HttpCore.
Notable features in this release:
* TLS ALPN protocol negotiation support on older JREs through Conscrypt TLS library.
Changelog:
-------------------

View File

@ -44,12 +44,12 @@ import org.apache.hc.core5.concurrent.FutureCallback;
*/
public class FluentAsync {
public static void main(String[] args)throws Exception {
public static void main(final String... args)throws Exception {
// Use pool of two threads
ExecutorService threadpool = Executors.newFixedThreadPool(2);
Async async = Async.newInstance().use(threadpool);
final ExecutorService threadpool = Executors.newFixedThreadPool(2);
final Async async = Async.newInstance().use(threadpool);
Request[] requests = new Request[] {
final Request[] requests = new Request[] {
Request.Get("http://www.google.com/"),
Request.Get("http://www.yahoo.com/"),
Request.Get("http://www.apache.com/"),
@ -57,10 +57,10 @@ public class FluentAsync {
};
Queue<Future<Content>> queue = new LinkedList<>();
final Queue<Future<Content>> queue = new LinkedList<>();
// Execute requests asynchronously
for (final Request request: requests) {
Future<Content> future = async.execute(request, new FutureCallback<Content>() {
final Future<Content> future = async.execute(request, new FutureCallback<Content>() {
@Override
public void failed(final Exception ex) {
@ -81,10 +81,10 @@ public class FluentAsync {
}
while(!queue.isEmpty()) {
Future<Content> future = queue.remove();
final Future<Content> future = queue.remove();
try {
future.get();
} catch (ExecutionException ex) {
} catch (final ExecutionException ex) {
}
}
System.out.println("Done");

View File

@ -44,8 +44,8 @@ import org.apache.hc.core5.util.Timeout;
*/
public class FluentExecutor {
public static void main(String[] args)throws Exception {
Executor executor = Executor.newInstance()
public static void main(final String... args)throws Exception {
final Executor executor = Executor.newInstance()
.auth(new HttpHost("somehost"), "username", "password".toCharArray())
.auth(new HttpHost("myproxy", 8080), "username", "password".toCharArray())
.authPreemptive(new HttpHost("myproxy", 8080));

View File

@ -31,7 +31,7 @@ import org.apache.hc.client5.http.fluent.Request;
public class FluentQuickStart {
public static void main(String[] args) throws Exception {
public static void main(final String... args) throws Exception {
// The fluent API relieves the user from having to deal with manual
// deallocation of system resources at the cost of having to buffer
// response content in memory in some cases.

View File

@ -40,7 +40,7 @@ import org.apache.hc.core5.util.Timeout;
*/
public class FluentRequests {
public static void main(String[] args)throws Exception {
public static void main(final String... args)throws Exception {
// Execute a GET with timeout settings and return response content as String.
Request.Get("http://somehost/")
.connectTimeout(Timeout.ofSeconds(1))

View File

@ -51,24 +51,24 @@ import org.xml.sax.SAXException;
*/
public class FluentResponseHandling {
public static void main(String[] args)throws Exception {
Document result = Request.Get("http://somehost/content")
public static void main(final String... args)throws Exception {
final Document result = Request.Get("http://somehost/content")
.execute().handleResponse(new HttpClientResponseHandler<Document>() {
@Override
public Document handleResponse(final ClassicHttpResponse response) throws IOException {
int status = response.getCode();
HttpEntity entity = response.getEntity();
final int status = response.getCode();
final HttpEntity entity = response.getEntity();
if (status >= HttpStatus.SC_REDIRECTION) {
throw new HttpResponseException(status, response.getReasonPhrase());
}
if (entity == null) {
throw new ClientProtocolException("Response contains no content");
}
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
final DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
ContentType contentType = ContentType.parseLenient(entity.getContentType());
final DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
final ContentType contentType = ContentType.parseLenient(entity.getContentType());
if (!contentType.equals(ContentType.APPLICATION_XML)) {
throw new ClientProtocolException("Unexpected content type:" + contentType);
}
@ -77,9 +77,9 @@ public class FluentResponseHandling {
charset = StandardCharsets.ISO_8859_1;
}
return docBuilder.parse(entity.getContent(), charset.name());
} catch (ParserConfigurationException ex) {
} catch (final ParserConfigurationException ex) {
throw new IllegalStateException(ex);
} catch (SAXException ex) {
} catch (final SAXException ex) {
throw new ClientProtocolException("Malformed XML document", ex);
}
}

View File

@ -45,18 +45,18 @@ import org.apache.hc.core5.io.CloseMode;
*/
public class AsyncClientAuthentication {
public static void main(String[] args) throws Exception {
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
public static void main(final String[] args) throws Exception {
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope("httpbin.org", 80),
new UsernamePasswordCredentials("user", "passwd".toCharArray()));
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
httpclient.start();
final String requestUri = "http://httpbin.org/basic-auth/user/passwd";
SimpleHttpRequest httpget = SimpleHttpRequests.GET.create(requestUri);
final SimpleHttpRequest httpget = SimpleHttpRequests.GET.create(requestUri);
System.out.println("Executing request " + requestUri);
final Future<SimpleHttpResponse> future = httpclient.execute(

View File

@ -57,7 +57,7 @@ import org.apache.hc.core5.ssl.TrustStrategy;
*/
public class AsyncClientCustomSSL {
public final static void main(final String[] args) throws Exception {
public static void main(final String[] args) throws Exception {
// Trust standard CA and those trusted by our custom strategy
final SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(new TrustStrategy() {
@ -91,7 +91,7 @@ public class AsyncClientCustomSSL {
final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create()
.setTlsStrategy(tlsStrategy)
.build();
try (CloseableHttpAsyncClient client = HttpAsyncClients.custom()
try (final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
.setConnectionManager(cm)
.build()) {

View File

@ -66,7 +66,7 @@ import org.apache.hc.core5.util.Timeout;
*/
public class AsyncClientInterceptors {
public final static void main(final String[] args) throws Exception {
public static void main(final String[] args) throws Exception {
final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
.setSoTimeout(Timeout.ofSeconds(5))
@ -101,11 +101,11 @@ public class AsyncClientInterceptors {
final AsyncExecChain.Scope scope,
final AsyncExecChain chain,
final AsyncExecCallback asyncExecCallback) throws HttpException, IOException {
Header idHeader = request.getFirstHeader("request-id");
final Header idHeader = request.getFirstHeader("request-id");
if (idHeader != null && "13".equalsIgnoreCase(idHeader.getValue())) {
HttpResponse response = new BasicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie");
ByteBuffer content = ByteBuffer.wrap("bad luck".getBytes(StandardCharsets.US_ASCII));
AsyncDataConsumer asyncDataConsumer = asyncExecCallback.handleResponse(
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie");
final ByteBuffer content = ByteBuffer.wrap("bad luck".getBytes(StandardCharsets.US_ASCII));
final AsyncDataConsumer asyncDataConsumer = asyncExecCallback.handleResponse(
response,
new BasicEntityDetails(content.remaining(), ContentType.TEXT_PLAIN));
asyncDataConsumer.consume(content);

View File

@ -72,7 +72,7 @@ public class AsyncClientTlsAlpn {
final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create()
.setTlsStrategy(tlsStrategy)
.build();
try (CloseableHttpAsyncClient client = HttpAsyncClients.custom()
try (final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
.setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
.setConnectionManager(cm)
.build()) {

View File

@ -48,15 +48,15 @@ import org.apache.hc.core5.http.nio.AsyncRequestProducer;
public class AsyncQuickStart {
public static void main(String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
public static void mainfinal (final String[] args) throws Exception {
final CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
// Start the client
httpclient.start();
// Execute request
final SimpleHttpRequest request1 = SimpleHttpRequests.GET.create("http://httpbin.org/get");
Future<SimpleHttpResponse> future = httpclient.execute(request1, null);
final Future<SimpleHttpResponse> future = httpclient.execute(request1, null);
// and wait until response is received
final SimpleHttpResponse response1 = future.get();
System.out.println(request1.getRequestUri() + "->" + response1.getCode());
@ -90,8 +90,8 @@ public class AsyncQuickStart {
// In real world one most likely would want also want to stream
// request and response body content
final CountDownLatch latch2 = new CountDownLatch(1);
AsyncRequestProducer producer3 = AsyncRequestBuilder.get("http://httpbin.org/get").build();
AbstractCharResponseConsumer<HttpResponse> consumer3 = new AbstractCharResponseConsumer<HttpResponse>() {
final AsyncRequestProducer producer3 = AsyncRequestBuilder.get("http://httpbin.org/get").build();
final AbstractCharResponseConsumer<HttpResponse> consumer3 = new AbstractCharResponseConsumer<HttpResponse>() {
HttpResponse response;

View File

@ -37,12 +37,12 @@ import org.apache.hc.client5.http.impl.classic.HttpClients;
*/
public class ClientAbortMethod {
public final static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
public static void main(final String[] args) throws Exception {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpGet httpget = new HttpGet("http://httpbin.org/get");
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
// Do not feel like reading the response body

View File

@ -46,13 +46,13 @@ public class ClientAuthentication {
credsProvider.setCredentials(
new AuthScope("httpbin.org", 80),
new UsernamePasswordCredentials("user", "passwd".toCharArray()));
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build()) {
final HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd");
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -47,7 +47,7 @@ public class ClientChunkEncodedPost {
System.out.println("File path not given");
System.exit(1);
}
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpPost httppost = new HttpPost("http://httpbin.org/post");
final File file = new File(args[0]);
@ -63,7 +63,7 @@ public class ClientChunkEncodedPost {
httppost.setEntity(reqEntity);
System.out.println("Executing request " + httppost.getMethod() + " " + httppost.getUri());
try (CloseableHttpResponse response = httpclient.execute(httppost)) {
try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -201,7 +201,7 @@ public class ClientConfiguration {
// Create an HttpClient with the given custom dependencies and configuration.
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(connManager)
.setDefaultCookieStore(cookieStore)
.setDefaultCredentialsProvider(credentialsProvider)
@ -226,7 +226,7 @@ public class ClientConfiguration {
context.setCredentialsProvider(credentialsProvider);
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
try (CloseableHttpResponse response = httpclient.execute(httpget, context)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget, context)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -43,11 +43,11 @@ import org.apache.hc.core5.http.HttpEntity;
public class ClientConnectionRelease {
public final static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpGet httpget = new HttpGet("http://httpbin.org/get");
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
@ -57,7 +57,7 @@ public class ClientConnectionRelease {
// If the response does not enclose an entity, there is no need
// to bother about connection release
if (entity != null) {
try (InputStream inStream = entity.getContent()) {
try (final InputStream inStream = entity.getContent()) {
inStream.read();
// do something useful with the response
} catch (final IOException ex) {

View File

@ -45,8 +45,8 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
*/
public class ClientCustomContext {
public final static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
public static void main(final String[] args) throws Exception {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
// Create a local instance of cookie store
final CookieStore cookieStore = new BasicCookieStore();
@ -59,7 +59,7 @@ public class ClientCustomContext {
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
// Pass local context as a parameter
try (CloseableHttpResponse response = httpclient.execute(httpget, localContext)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget, localContext)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
final List<Cookie> cookies = cookieStore.getCookies();

View File

@ -51,7 +51,7 @@ import org.apache.hc.core5.ssl.SSLContexts;
*/
public class ClientCustomPublicSuffixList {
public final static void main(final String[] args) throws Exception {
public static void main(final String[] args) throws Exception {
// Use PublicSuffixMatcherLoader to load public suffix list from a file,
// resource or from an arbitrary URL
@ -72,7 +72,7 @@ public class ClientCustomPublicSuffixList {
final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(sslsf)
.build();
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.setDefaultCookieSpecRegistry(cookieSpecRegistry)
.build()) {
@ -81,7 +81,7 @@ public class ClientCustomPublicSuffixList {
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -44,7 +44,7 @@ public class ClientEvictExpiredConnections {
public static void main(final String[] args) throws Exception {
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(100);
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.evictExpiredConnections()
.evictIdleConnections(TimeValue.ofSeconds(5))
@ -56,13 +56,12 @@ public class ClientEvictExpiredConnections {
"http://hc.apache.org/httpcomponents-client-ga/",
};
for (int i = 0; i < urisToGet.length; i++) {
final String requestURI = urisToGet[i];
for (final String requestURI : urisToGet) {
final HttpGet request = new HttpGet(requestURI);
System.out.println("Executing request " + request.getMethod() + " " + request.getRequestUri());
try (CloseableHttpResponse response = httpclient.execute(request)) {
try (final CloseableHttpResponse response = httpclient.execute(request)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
EntityUtils.consume(response.getEntity());

View File

@ -43,7 +43,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
public class ClientExecuteProxy {
public static void main(final String[] args)throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpHost target = new HttpHost("https", "httpbin.org", 443);
final HttpHost proxy = new HttpHost("http", "127.0.0.1", 8080);
@ -56,7 +56,7 @@ public class ClientExecuteProxy {
System.out.println("Executing request " + request.getMethod() + " " + request.getUri() +
" via " + proxy);
try (CloseableHttpResponse response = httpclient.execute(target, request)) {
try (final CloseableHttpResponse response = httpclient.execute(target, request)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -60,7 +60,7 @@ public class ClientExecuteSOCKS {
.register("http", new MyConnectionSocketFactory())
.build();
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg);
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.build()) {
final InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234);
@ -72,7 +72,7 @@ public class ClientExecuteSOCKS {
System.out.println("Executing request " + request.getMethod() + " " + request.getUri() +
" via SOCKS proxy " + socksaddr);
try (CloseableHttpResponse response = httpclient.execute(target, request, context)) {
try (final CloseableHttpResponse response = httpclient.execute(target, request, context)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));
@ -97,7 +97,7 @@ public class ClientExecuteSOCKS {
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpContext context) throws IOException {
Socket sock;
final Socket sock;
if (socket != null) {
sock = socket;
} else {

View File

@ -48,11 +48,11 @@ public class ClientFormLogin {
public static void main(final String[] args) throws Exception {
final BasicCookieStore cookieStore = new BasicCookieStore();
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.build()) {
final HttpGet httpget = new HttpGet("https://someportal/");
try (CloseableHttpResponse response1 = httpclient.execute(httpget)) {
try (final CloseableHttpResponse response1 = httpclient.execute(httpget)) {
final HttpEntity entity = response1.getEntity();
System.out.println("Login form get: " + response1.getCode() + " " + response1.getReasonPhrase());
@ -74,7 +74,7 @@ public class ClientFormLogin {
.addParameter("IDToken1", "username")
.addParameter("IDToken2", "password")
.build();
try (CloseableHttpResponse response2 = httpclient.execute(login)) {
try (final CloseableHttpResponse response2 = httpclient.execute(login)) {
final HttpEntity entity = response2.getEntity();
System.out.println("Login form get: " + response2.getCode() + " " + response2.getReasonPhrase());

View File

@ -57,8 +57,8 @@ import org.apache.hc.core5.http.protocol.HttpContext;
*/
public class ClientInterceptors {
public final static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.custom()
public static void main(final String[] args) throws Exception {
try (final CloseableHttpClient httpclient = HttpClients.custom()
// Add a simple request ID to each outgoing request
@ -85,9 +85,9 @@ public class ClientInterceptors {
final ExecChain.Scope scope,
final ExecChain chain) throws IOException, HttpException {
Header idHeader = request.getFirstHeader("request-id");
final Header idHeader = request.getFirstHeader("request-id");
if (idHeader != null && "13".equalsIgnoreCase(idHeader.getValue())) {
ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie");
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie");
response.setEntity(new StringEntity("bad luck", ContentType.TEXT_PLAIN));
return response;
} else {
@ -103,7 +103,7 @@ public class ClientInterceptors {
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -49,7 +49,7 @@ public class ClientMultiThreadedExecution {
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(100);
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.build()) {
// create an array of URIs to perform GETs on
@ -67,13 +67,13 @@ public class ClientMultiThreadedExecution {
}
// start the threads
for (int j = 0; j < threads.length; j++) {
threads[j].start();
for (final GetThread thread : threads) {
thread.start();
}
// join the threads
for (int j = 0; j < threads.length; j++) {
threads[j].join();
for (final GetThread thread : threads) {
thread.join();
}
}

View File

@ -49,7 +49,7 @@ public class ClientMultipartFormPost {
System.out.println("File path not given");
System.exit(1);
}
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpPost httppost = new HttpPost("http://localhost:8080" +
"/servlets-examples/servlet/RequestInfoExample");
@ -65,7 +65,7 @@ public class ClientMultipartFormPost {
httppost.setEntity(reqEntity);
System.out.println("executing request " + httppost);
try (CloseableHttpResponse response = httpclient.execute(httppost)) {
try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
System.out.println("----------------------------------------");
System.out.println(response);
final HttpEntity resEntity = response.getEntity();

View File

@ -47,7 +47,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
public class ClientPreemptiveBasicAuthentication {
public static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
// Generate BASIC scheme object and add it to the local auth cache
final BasicScheme basicAuth = new BasicScheme();
@ -63,7 +63,7 @@ public class ClientPreemptiveBasicAuthentication {
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
for (int i = 0; i < 3; i++) {
try (CloseableHttpResponse response = httpclient.execute(httpget, localContext)) {
try (final CloseableHttpResponse response = httpclient.execute(httpget, localContext)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -49,7 +49,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
public class ClientPreemptiveDigestAuthentication {
public static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpHost target = new HttpHost("http", "httpbin.org", 80);
@ -64,7 +64,7 @@ public class ClientPreemptiveDigestAuthentication {
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
for (int i = 0; i < 3; i++) {
try (CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) {
try (final CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
EntityUtils.consume(response.getEntity());
@ -73,7 +73,7 @@ public class ClientPreemptiveDigestAuthentication {
if (authExchange != null) {
final AuthScheme authScheme = authExchange.getAuthScheme();
if (authScheme instanceof DigestScheme) {
DigestScheme digestScheme = (DigestScheme) authScheme;
final DigestScheme digestScheme = (DigestScheme) authScheme;
System.out.println("Nonce: " + digestScheme.getNonce() +
"; count: " + digestScheme.getNounceCount());
}

View File

@ -51,7 +51,7 @@ public class ClientProxyAuthentication {
credsProvider.setCredentials(
new AuthScope("httpbin.org", 80),
new UsernamePasswordCredentials("user", "passwd".toCharArray()));
try (CloseableHttpClient httpclient = HttpClients.custom()
try (final CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider).build()) {
final HttpHost target = new HttpHost("http", "httpbin.org", 80);
final HttpHost proxy = new HttpHost("localhost", 8888);
@ -65,7 +65,7 @@ public class ClientProxyAuthentication {
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri() +
" via " + proxy);
try (CloseableHttpResponse response = httpclient.execute(target, httpget)) {
try (final CloseableHttpResponse response = httpclient.execute(target, httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));

View File

@ -57,7 +57,7 @@ public class ClientWithRequestFuture {
.setConnectionManager(cm)
.build();
final ExecutorService execService = Executors.newFixedThreadPool(5);
try (FutureRequestExecutionService requestExecService = new FutureRequestExecutionService(
try (final FutureRequestExecutionService requestExecService = new FutureRequestExecutionService(
httpclient, execService)) {
// Because things are asynchronous, you must provide a HttpClientResponseHandler
final HttpClientResponseHandler<Boolean> handler = new HttpClientResponseHandler<Boolean>() {

View File

@ -46,8 +46,8 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
*/
public class ClientWithResponseHandler {
public final static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
public static void main(final String[] args) throws Exception {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpGet httpget = new HttpGet("http://httpbin.org/get");
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());

View File

@ -49,7 +49,7 @@ public class ProxyTunnelDemo {
final HttpHost target = new HttpHost("www.yahoo.com", 80);
final HttpHost proxy = new HttpHost("localhost", 8888);
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd".toCharArray());
try (Socket socket = proxyClient.tunnel(proxy, target, credentials)) {
try (final Socket socket = proxyClient.tunnel(proxy, target, credentials)) {
final Writer out = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.ISO_8859_1);
out.write("GET / HTTP/1.1\r\n");
out.write("Host: " + target.toHostString() + "\r\n");

View File

@ -43,7 +43,7 @@ import org.apache.hc.core5.http.message.BasicNameValuePair;
public class QuickStart {
public static void main(final String[] args) throws Exception {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpGet httpGet = new HttpGet("http://httpbin.org/get");
// The underlying HTTP connection is still held by the response object
// to allow the response content to be streamed directly from the network socket.
@ -52,7 +52,7 @@ public class QuickStart {
// Please note that if response content is not fully consumed the underlying
// connection cannot be safely re-used and will be shut down and discarded
// by the connection manager.
try (CloseableHttpResponse response1 = httpclient.execute(httpGet)) {
try (final CloseableHttpResponse response1 = httpclient.execute(httpGet)) {
System.out.println(response1.getCode() + " " + response1.getReasonPhrase());
final HttpEntity entity1 = response1.getEntity();
// do something useful with the response body
@ -66,7 +66,7 @@ public class QuickStart {
nvps.add(new BasicNameValuePair("password", "secret"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
try (CloseableHttpResponse response2 = httpclient.execute(httpPost)) {
try (final CloseableHttpResponse response2 = httpclient.execute(httpPost)) {
System.out.println(response2.getCode() + " " + response2.getReasonPhrase());
final HttpEntity entity2 = response2.getEntity();
// do something useful with the response body

View File

@ -75,7 +75,7 @@ public class ReactiveClientFullDuplexExchange {
client.start();
final URI requestUri = new URI("http://httpbin.org/post");
byte[] bs = "stuff".getBytes(StandardCharsets.UTF_8);
final byte[] bs = "stuff".getBytes(StandardCharsets.UTF_8);
final ReactiveEntityProducer reactiveEntityProducer = new ReactiveEntityProducer(
Flowable.just(ByteBuffer.wrap(bs)), bs.length, ContentType.TEXT_PLAIN, null);
final BasicRequestProducer requestProducer = new BasicRequestProducer(
@ -86,7 +86,7 @@ public class ReactiveClientFullDuplexExchange {
final Message<HttpResponse, Publisher<ByteBuffer>> streamingResponse = consumer.getResponseFuture().get();
System.out.println(streamingResponse.getHead());
for (Header header : streamingResponse.getHead().getHeaders()) {
for (final Header header : streamingResponse.getHead().getHeaders()) {
System.out.println(header.toString());
}
System.out.println();