|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
42 | 42 | import org.springframework.util.Assert;
|
43 | 43 |
|
44 | 44 | /**
|
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. |
47 | 47 | *
|
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. |
50 | 50 | *
|
51 | 51 | * @author Arjen Poutsma
|
52 | 52 | * @author Rossen Stoyanchev
|
@@ -104,15 +104,6 @@ public Netty4ClientHttpRequestFactory(EventLoopGroup eventLoopGroup) {
|
104 | 104 | }
|
105 | 105 |
|
106 | 106 |
|
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 |
| - |
116 | 107 | /**
|
117 | 108 | * Set the default maximum response size.
|
118 | 109 | * <p>By default this is set to {@link #DEFAULT_MAX_RESPONSE_SIZE}.
|
@@ -150,9 +141,41 @@ public void setReadTimeout(int readTimeout) {
|
150 | 141 | this.readTimeout = readTimeout;
|
151 | 142 | }
|
152 | 143 |
|
| 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 | + |
153 | 176 | 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()))); |
156 | 179 | if (isSecure) {
|
157 | 180 | if (this.sslBootstrap == null) {
|
158 | 181 | this.sslBootstrap = buildBootstrap(true);
|
@@ -201,27 +224,6 @@ protected void configureChannel(SocketChannelConfig config) {
|
201 | 224 | }
|
202 | 225 | }
|
203 | 226 |
|
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 |
| - |
225 | 227 |
|
226 | 228 | @Override
|
227 | 229 | public void destroy() throws InterruptedException {
|
|
0 commit comments