From 1608d0596d9eabaa1d19012f5bd568c8035f86d3 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 4 Nov 2016 12:25:38 +0100 Subject: [PATCH] Polishing --- .../Netty4ClientHttpRequestFactory.java | 76 ++++++++++--------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java index 6cdfa7d48f1..d95aa175914 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -42,11 +42,11 @@ import org.springframework.http.HttpMethod; import org.springframework.util.Assert; /** - * {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that - * uses Netty 4 to create requests. + * {@link org.springframework.http.client.ClientHttpRequestFactory} implementation + * that uses Netty 4 to create requests. * - *

Allows to use a pre-configured {@link EventLoopGroup} instance - useful for sharing - * across multiple clients. + *

Allows to use a pre-configured {@link EventLoopGroup} instance: useful for + * sharing across multiple clients. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -104,15 +104,6 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, } - private SslContext getDefaultClientSslContext() { - try { - return SslContextBuilder.forClient().build(); - } - catch (SSLException exc) { - throw new IllegalStateException("Could not create default client SslContext", exc); - } - } - /** * Set the default maximum response size. *

By default this is set to {@link #DEFAULT_MAX_RESPONSE_SIZE}. @@ -150,9 +141,41 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, this.readTimeout = readTimeout; } + + @Override + public void afterPropertiesSet() { + if (this.sslContext == null) { + this.sslContext = getDefaultClientSslContext(); + } + } + + private SslContext getDefaultClientSslContext() { + try { + return SslContextBuilder.forClient().build(); + } + catch (SSLException ex) { + throw new IllegalStateException("Could not create default client SslContext", ex); + } + } + + + @Override + public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { + return createRequestInternal(uri, httpMethod); + } + + @Override + public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { + return createRequestInternal(uri, httpMethod); + } + + private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMethod) { + return new Netty4ClientHttpRequest(getBootstrap(uri), uri, httpMethod); + } + private Bootstrap getBootstrap(URI uri) { - final boolean isSecure = (uri.getPort() == 443) - || (uri.getPort() == -1 && "https".equalsIgnoreCase(uri.getScheme())); + boolean isSecure = (uri.getPort() == 443 || + (uri.getPort() == -1 && "https".equalsIgnoreCase(uri.getScheme()))); if (isSecure) { if (this.sslBootstrap == null) { this.sslBootstrap = buildBootstrap(true); @@ -201,27 +224,6 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, } } - @Override - public void afterPropertiesSet() throws Exception { - if (this.sslContext == null) { - this.sslContext = getDefaultClientSslContext(); - } - } - - @Override - public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { - return createRequestInternal(uri, httpMethod); - } - - @Override - public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { - return createRequestInternal(uri, httpMethod); - } - - private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMethod) { - return new Netty4ClientHttpRequest(getBootstrap(uri), uri, httpMethod); - } - @Override public void destroy() throws InterruptedException {