Skip to content

Commit e5e6489

Browse files
author
Stephane Landelle
committed
Move setting a SSLEngineFactory into Netty specific conf as Grizzly doesn't use it
1 parent eb84fa5 commit e5e6489

File tree

5 files changed

+25
-49
lines changed

5 files changed

+25
-49
lines changed

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import javax.net.ssl.HostnameVerifier;
2727
import javax.net.ssl.SSLContext;
28-
import javax.net.ssl.SSLEngine;
2928

3029
import java.io.IOException;
3130
import java.io.InputStream;
@@ -94,7 +93,6 @@ public class AsyncHttpClientConfig {
9493
protected ExecutorService applicationThreadPool;
9594
protected ProxyServerSelector proxyServerSelector;
9695
protected SSLContext sslContext;
97-
protected SSLEngineFactory sslEngineFactory;
9896
protected AsyncHttpProviderConfig<?, ?> providerConfig;
9997
protected Realm realm;
10098
protected List<RequestFilter> requestFilters;
@@ -169,7 +167,6 @@ private AsyncHttpClientConfig(int maxTotalConnections, //
169167
this.userAgent = userAgent;
170168
this.allowPoolingConnection = keepAlive;
171169
this.sslContext = sslContext;
172-
this.sslEngineFactory = sslEngineFactory;
173170
this.providerConfig = providerConfig;
174171
this.realm = realm;
175172
this.requestFilters = requestFilters;
@@ -332,28 +329,6 @@ public SSLContext getSSLContext() {
332329
return sslContext;
333330
}
334331

335-
/**
336-
* Return an instance of {@link SSLEngineFactory} used for SSL connection.
337-
*
338-
* @return an instance of {@link SSLEngineFactory} used for SSL connection.
339-
*/
340-
public SSLEngineFactory getSSLEngineFactory() {
341-
if (sslEngineFactory == null) {
342-
return new SSLEngineFactory() {
343-
public SSLEngine newSSLEngine() {
344-
if (sslContext != null) {
345-
SSLEngine sslEngine = sslContext.createSSLEngine();
346-
sslEngine.setUseClientMode(true);
347-
return sslEngine;
348-
} else {
349-
return null;
350-
}
351-
}
352-
};
353-
}
354-
return sslEngineFactory;
355-
}
356-
357332
/**
358333
* Return the {@link AsyncHttpProviderConfig}
359334
*
@@ -1122,7 +1097,6 @@ public Builder(AsyncHttpClientConfig prototype) {
11221097
realm = prototype.getRealm();
11231098
requestTimeoutInMs = prototype.getRequestTimeoutInMs();
11241099
sslContext = prototype.getSSLContext();
1125-
sslEngineFactory = prototype.getSSLEngineFactory();
11261100
userAgent = prototype.getUserAgent();
11271101
redirectEnabled = prototype.isRedirectEnabled();
11281102
compressionEnabled = prototype.isCompressionEnabled();

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ public AsyncHttpClientConfigBean setSslContext(SSLContext sslContext) {
175175
return this;
176176
}
177177

178-
public AsyncHttpClientConfigBean setSslEngineFactory(SSLEngineFactory sslEngineFactory) {
179-
this.sslEngineFactory = sslEngineFactory;
180-
return this;
181-
}
182-
183178
public AsyncHttpClientConfigBean setProviderConfig(AsyncHttpProviderConfig<?, ?> providerConfig) {
184179
this.providerConfig = providerConfig;
185180
return this;

api/src/main/java/org/asynchttpclient/util/SslUtils.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.asynchttpclient.util;
1717

1818
import javax.net.ssl.SSLContext;
19-
import javax.net.ssl.SSLEngine;
2019
import java.io.IOException;
2120
import java.security.GeneralSecurityException;
2221

@@ -33,20 +32,7 @@ public static SslUtils getInstance() {
3332
return SingletonHolder.instance;
3433
}
3534

36-
public SSLEngine getSSLEngine() throws GeneralSecurityException, IOException {
37-
SSLEngine engine = null;
38-
39-
SSLContext context = getSSLContext();
40-
if (context != null) {
41-
engine = context.createSSLEngine();
42-
engine.setUseClientMode(true);
43-
}
44-
45-
return engine;
46-
}
47-
4835
public SSLContext getSSLContext() throws GeneralSecurityException, IOException {
4936
return SSLContext.getDefault();
5037
}
51-
5238
}

providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.asynchttpclient.providers.netty;
1818

1919
import org.asynchttpclient.AsyncHttpProviderConfig;
20+
import org.asynchttpclient.SSLEngineFactory;
2021
import org.asynchttpclient.providers.netty.channel.ChannelPool;
2122
import org.asynchttpclient.providers.netty.response.EagerResponseBodyPart;
2223
import org.asynchttpclient.providers.netty.response.LazyResponseBodyPart;
@@ -93,6 +94,8 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig<Str
9394

9495
private long handshakeTimeoutInMillis;
9596

97+
private SSLEngineFactory sslEngineFactory;
98+
9699
public NettyAsyncHttpProviderConfig() {
97100
properties.put(REUSE_ADDRESS, Boolean.FALSE);
98101
}
@@ -250,6 +253,14 @@ public long getHandshakeTimeoutInMillis() {
250253
public void setHandshakeTimeoutInMillis(long handshakeTimeoutInMillis) {
251254
this.handshakeTimeoutInMillis = handshakeTimeoutInMillis;
252255
}
256+
257+
public SSLEngineFactory getSslEngineFactory() {
258+
return sslEngineFactory;
259+
}
260+
261+
public void setSslEngineFactory(SSLEngineFactory sslEngineFactory) {
262+
this.sslEngineFactory = sslEngineFactory;
263+
}
253264

254265
public static interface AdditionalChannelInitializer {
255266

providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import io.netty.util.Timer;
5959
import io.netty.util.TimerTask;
6060

61+
import javax.net.ssl.SSLContext;
6162
import javax.net.ssl.SSLEngine;
6263

6364
import java.io.IOException;
@@ -202,11 +203,20 @@ private Timer newNettyTimer() {
202203
}
203204

204205
private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException {
205-
SSLEngine sslEngine = config.getSSLEngineFactory().newSSLEngine();
206-
if (sslEngine == null) {
207-
sslEngine = SslUtils.getInstance().getSSLEngine();
206+
207+
if (nettyProviderConfig.getSslEngineFactory() != null) {
208+
return nettyProviderConfig.getSslEngineFactory().newSSLEngine();
209+
210+
} else {
211+
SSLContext sslContext = config.getSSLContext();
212+
if (sslContext == null) {
213+
sslContext = SslUtils.getInstance().getSSLContext();
214+
}
215+
216+
SSLEngine sslEngine = sslContext.createSSLEngine();
217+
sslEngine.setUseClientMode(true);
218+
return sslEngine;
208219
}
209-
return sslEngine;
210220
}
211221

212222
public void configureProcessor(NettyRequestSender requestSender, AtomicBoolean closed) {

0 commit comments

Comments
 (0)