Skip to content

Commit 1608d05

Browse files
jhoellerbclozel
authored andcommitted
Polishing
1 parent 62631bf commit 1608d05

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,11 +42,11 @@
4242
import org.springframework.util.Assert;
4343

4444
/**
45-
* {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that
46-
* uses <a href="http://netty.io/">Netty 4</a> to create requests.
45+
* {@link org.springframework.http.client.ClientHttpRequestFactory} implementation
46+
* that uses <a href="http://netty.io/">Netty 4</a> to create requests.
4747
*
48-
* <p>Allows to use a pre-configured {@link EventLoopGroup} instance - useful for sharing
49-
* across multiple clients.
48+
* <p>Allows to use a pre-configured {@link EventLoopGroup} instance: useful for
49+
* sharing across multiple clients.
5050
*
5151
* @author Arjen Poutsma
5252
* @author Rossen Stoyanchev
@@ -104,15 +104,6 @@ public Netty4ClientHttpRequestFactory(EventLoopGroup eventLoopGroup) {
104104
}
105105

106106

107-
private SslContext getDefaultClientSslContext() {
108-
try {
109-
return SslContextBuilder.forClient().build();
110-
}
111-
catch (SSLException exc) {
112-
throw new IllegalStateException("Could not create default client SslContext", exc);
113-
}
114-
}
115-
116107
/**
117108
* Set the default maximum response size.
118109
* <p>By default this is set to {@link #DEFAULT_MAX_RESPONSE_SIZE}.
@@ -150,9 +141,41 @@ public void setReadTimeout(int readTimeout) {
150141
this.readTimeout = readTimeout;
151142
}
152143

144+
145+
@Override
146+
public void afterPropertiesSet() {
147+
if (this.sslContext == null) {
148+
this.sslContext = getDefaultClientSslContext();
149+
}
150+
}
151+
152+
private SslContext getDefaultClientSslContext() {
153+
try {
154+
return SslContextBuilder.forClient().build();
155+
}
156+
catch (SSLException ex) {
157+
throw new IllegalStateException("Could not create default client SslContext", ex);
158+
}
159+
}
160+
161+
162+
@Override
163+
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
164+
return createRequestInternal(uri, httpMethod);
165+
}
166+
167+
@Override
168+
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
169+
return createRequestInternal(uri, httpMethod);
170+
}
171+
172+
private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMethod) {
173+
return new Netty4ClientHttpRequest(getBootstrap(uri), uri, httpMethod);
174+
}
175+
153176
private Bootstrap getBootstrap(URI uri) {
154-
final boolean isSecure = (uri.getPort() == 443)
155-
|| (uri.getPort() == -1 && "https".equalsIgnoreCase(uri.getScheme()));
177+
boolean isSecure = (uri.getPort() == 443 ||
178+
(uri.getPort() == -1 && "https".equalsIgnoreCase(uri.getScheme())));
156179
if (isSecure) {
157180
if (this.sslBootstrap == null) {
158181
this.sslBootstrap = buildBootstrap(true);
@@ -201,27 +224,6 @@ protected void configureChannel(SocketChannelConfig config) {
201224
}
202225
}
203226

204-
@Override
205-
public void afterPropertiesSet() throws Exception {
206-
if (this.sslContext == null) {
207-
this.sslContext = getDefaultClientSslContext();
208-
}
209-
}
210-
211-
@Override
212-
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
213-
return createRequestInternal(uri, httpMethod);
214-
}
215-
216-
@Override
217-
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
218-
return createRequestInternal(uri, httpMethod);
219-
}
220-
221-
private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMethod) {
222-
return new Netty4ClientHttpRequest(getBootstrap(uri), uri, httpMethod);
223-
}
224-
225227

226228
@Override
227229
public void destroy() throws InterruptedException {

0 commit comments

Comments
 (0)