You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/04/19 16:39:19 UTC
svn commit: r1791940 [1/2] - in /httpcomponents/httpcore/trunk:
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/
httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ ht...
Author: olegk
Date: Wed Apr 19 16:39:18 2017
New Revision: 1791940
URL: http://svn.apache.org/viewvc?rev=1791940&view=rev
Log:
Transport Layer Security APIs refinement
Added:
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java (contents, props changed)
- copied, changed from r1791755, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/TlsCapableIOSession.java
- copied, changed from r1791755, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java
Removed:
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java
Modified:
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexer.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpCoreContext.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequest.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequestImpl.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java Wed Apr 19 16:39:18 2017
@@ -30,6 +30,8 @@ package org.apache.hc.core5.http2.impl.n
import java.io.IOException;
import java.net.SocketAddress;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
@@ -112,6 +114,11 @@ class AbstractHttp2IOEventHandler implem
}
@Override
+ public SSLSession getSSLSession() {
+ return streamMultiplexer.getSSLSession();
+ }
+
+ @Override
public EndpointDetails getEndpointDetails() {
return streamMultiplexer.getEndpointDetails();
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java Wed Apr 19 16:39:18 2017
@@ -43,6 +43,8 @@ import java.util.concurrent.atomic.Atomi
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.http.ConnectionClosedException;
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.Header;
@@ -81,7 +83,7 @@ import org.apache.hc.core5.http2.nio.com
import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.net.InetAddressUtils;
import org.apache.hc.core5.reactor.Command;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.ByteArrayBuffer;
@@ -94,7 +96,7 @@ abstract class AbstractHttp2StreamMultip
enum SettingsHandshake { READY, TRANSMITTED, ACKED }
private final Mode mode;
- private final IOSession ioSession;
+ private final TlsCapableIOSession ioSession;
private final FrameFactory frameFactory;
private final StreamIdGenerator idGenerator;
private final HttpProcessor httpProcessor;
@@ -130,7 +132,7 @@ abstract class AbstractHttp2StreamMultip
AbstractHttp2StreamMultiplexer(
final Mode mode,
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final FrameFactory frameFactory,
final StreamIdGenerator idGenerator,
final HttpProcessor httpProcessor,
@@ -591,6 +593,7 @@ abstract class AbstractHttp2StreamMultip
remoteConfig.getInitialWindowSize());
final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext());
+ context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
final Http2StreamHandler streamHandler = new ClientHttp2StreamHandler(
channel,
@@ -1183,6 +1186,11 @@ abstract class AbstractHttp2StreamMultip
}
@Override
+ public SSLSession getSSLSession() {
+ return ioSession.getSSLSession();
+ }
+
+ @Override
public EndpointDetails getEndpointDetails() {
if (endpointDetails == null) {
endpointDetails = new BasicEndpointDetails(ioSession.getRemoteAddress(), ioSession.getLocalAddress(), connMetrics);
@@ -1312,6 +1320,7 @@ abstract class AbstractHttp2StreamMultip
localConfig.getInitialWindowSize(),
remoteConfig.getInitialWindowSize());
final HttpCoreContext context = HttpCoreContext.create();
+ context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
final Http2StreamHandler streamHandler = new ServerPushHttp2StreamHandler(
channel, httpProcessor, connMetrics, pushProducer, context);
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java Wed Apr 19 16:39:18 2017
@@ -39,7 +39,7 @@ import org.apache.hc.core5.http2.config.
import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
import org.apache.hc.core5.http2.frame.FrameFactory;
import org.apache.hc.core5.http2.frame.StreamIdGenerator;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
/**
* Client side HTTP/2 stream multiplexer.
@@ -51,7 +51,7 @@ public class ClientHttp2StreamMultiplexe
private final HandlerFactory<AsyncPushConsumer> pushHandlerFactory;
public ClientHttp2StreamMultiplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final FrameFactory frameFactory,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
@@ -65,7 +65,7 @@ public class ClientHttp2StreamMultiplexe
}
public ClientHttp2StreamMultiplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
final CharCodingConfig charCodingConfig,
@@ -75,7 +75,7 @@ public class ClientHttp2StreamMultiplexe
}
public ClientHttp2StreamMultiplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final CharCodingConfig charCodingConfig,
final H2Config h2Config) {
@@ -88,6 +88,7 @@ public class ClientHttp2StreamMultiplexe
final HttpProcessor httpProcessor,
final BasicHttpConnectionMetrics connMetrics) throws IOException {
final HttpCoreContext context = HttpCoreContext.create();
+ context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
return new ClientPushHttp2StreamHandler(channel, httpProcessor, connMetrics, pushHandlerFactory, context);
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java Wed Apr 19 16:39:18 2017
@@ -33,6 +33,8 @@ import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.EndpointDetails;
@@ -51,6 +53,7 @@ import org.apache.hc.core5.io.ShutdownTy
import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -65,7 +68,7 @@ public class ClientHttpProtocolNegotiato
0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a, 0x0d, 0x0a, 0x53, 0x4d,
0x0d, 0x0a, 0x0d, 0x0a};
- private final IOSession ioSession;
+ private final TlsCapableIOSession ioSession;
private final HttpProcessor httpProcessor;
private final CharCodingConfig charCodingConfig;
private final H2Config h2Config;
@@ -75,7 +78,7 @@ public class ClientHttpProtocolNegotiato
private final ByteBuffer preface;
public ClientHttpProtocolNegotiator(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
final CharCodingConfig charCodingConfig,
@@ -92,7 +95,7 @@ public class ClientHttpProtocolNegotiato
this.preface = ByteBuffer.wrap(PREFACE);
}
- protected ClientHttp2StreamMultiplexer createStreamMultiplexer(final IOSession ioSession) {
+ protected ClientHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
return new ClientHttp2StreamMultiplexer(ioSession, DefaultFrameFactory.INSTANCE, httpProcessor,
pushHandlerFactory, charCodingConfig, h2Config, connectionListener, streamListener);
}
@@ -167,6 +170,11 @@ public class ClientHttpProtocolNegotiato
}
@Override
+ public SSLSession getSSLSession() {
+ return ioSession.getSSLSession();
+ }
+
+ @Override
public EndpointDetails getEndpointDetails() {
return null;
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java Wed Apr 19 16:39:18 2017
@@ -36,7 +36,7 @@ import org.apache.hc.core5.http.nio.Hand
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -83,7 +83,7 @@ public class ClientHttpProtocolNegotiato
}
@Override
- public ClientHttpProtocolNegotiator createHandler(final IOSession ioSession, final Object attachment) {
+ public ClientHttpProtocolNegotiator createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
return new ClientHttpProtocolNegotiator(ioSession, httpProcessor, pushHandlerFactory,
charCodingConfig, h2Config, connectionListener, streamListener);
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexer.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexer.java Wed Apr 19 16:39:18 2017
@@ -39,7 +39,7 @@ import org.apache.hc.core5.http2.config.
import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
import org.apache.hc.core5.http2.frame.FrameFactory;
import org.apache.hc.core5.http2.frame.StreamIdGenerator;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -52,7 +52,7 @@ public class ServerHttp2StreamMultiplexe
private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
public ServerHttp2StreamMultiplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final FrameFactory frameFactory,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
@@ -66,7 +66,7 @@ public class ServerHttp2StreamMultiplexe
}
public ServerHttp2StreamMultiplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
final CharCodingConfig charCodingConfig,
@@ -81,6 +81,7 @@ public class ServerHttp2StreamMultiplexe
final HttpProcessor httpProcessor,
final BasicHttpConnectionMetrics connMetrics) throws IOException {
final HttpCoreContext context = HttpCoreContext.create();
+ context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
return new ServerHttp2StreamHandler(channel, httpProcessor, connMetrics, exchangeHandlerFactory, context);
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java Wed Apr 19 16:39:18 2017
@@ -32,6 +32,8 @@ import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.EndpointDetails;
@@ -48,6 +50,7 @@ import org.apache.hc.core5.http2.config.
import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -58,7 +61,7 @@ public class ServerHttpProtocolNegotiato
final static byte[] PREFACE = ClientHttpProtocolNegotiator.PREFACE;
- private final IOSession ioSession;
+ private final TlsCapableIOSession ioSession;
private final HttpProcessor httpProcessor;
private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
private final CharCodingConfig charCodingConfig;
@@ -68,7 +71,7 @@ public class ServerHttpProtocolNegotiato
private final Http2StreamListener streamListener;
public ServerHttpProtocolNegotiator(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
final CharCodingConfig charCodingConfig,
@@ -85,7 +88,7 @@ public class ServerHttpProtocolNegotiato
this.streamListener = streamListener;
}
- protected ServerHttp2StreamMultiplexer createStreamMultiplexer(final IOSession ioSession) {
+ protected ServerHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
return new ServerHttp2StreamMultiplexer(ioSession, DefaultFrameFactory.INSTANCE, httpProcessor,
exchangeHandlerFactory, charCodingConfig, h2Config, connectionListener, streamListener);
}
@@ -107,7 +110,7 @@ public class ServerHttpProtocolNegotiato
throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Unexpected HTTP/2 preface");
}
}
- final ServerHttp2StreamMultiplexer streamMultiplexer = createStreamMultiplexer(session);
+ final ServerHttp2StreamMultiplexer streamMultiplexer = createStreamMultiplexer(ioSession);
streamMultiplexer.onConnect(bytebuf.hasRemaining() ? bytebuf : null);
streamMultiplexer.onInput();
session.setHandler(new ServerHttp2IOEventHandler(streamMultiplexer));
@@ -142,6 +145,11 @@ public class ServerHttpProtocolNegotiato
}
@Override
+ public SSLSession getSSLSession() {
+ return ioSession.getSSLSession();
+ }
+
+ @Override
public EndpointDetails getEndpointDetails() {
return null;
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java Wed Apr 19 16:39:18 2017
@@ -37,8 +37,7 @@ import org.apache.hc.core5.http.nio.ssl.
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -82,10 +81,10 @@ public class ServerHttpProtocolNegotiato
}
@Override
- public ServerHttpProtocolNegotiator createHandler(final IOSession ioSession, final Object attachment) {
- if (tlsStrategy != null && ioSession instanceof TransportSecurityLayer) {
+ public ServerHttpProtocolNegotiator createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
+ if (tlsStrategy != null) {
tlsStrategy.upgrade(
- (TransportSecurityLayer) ioSession,
+ ioSession,
null,
ioSession.getLocalAddress(),
ioSession.getRemoteAddress());
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java Wed Apr 19 16:39:18 2017
@@ -94,7 +94,7 @@ public class H2ClientTlsStrategy impleme
final String... parameters) {
final String scheme = host != null ? host.getSchemeName() : null;
if ("https".equalsIgnoreCase(scheme)) {
- tlsSession.start(sslContext, sslBufferManagement,
+ tlsSession.startTls(sslContext, sslBufferManagement,
H2TlsSupport.decorateInitializer(initializer), verifier);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java Wed Apr 19 16:39:18 2017
@@ -101,7 +101,7 @@ public class H2ServerTlsStrategy impleme
final int port = ((InetSocketAddress) localAddress).getPort();
for (final int securePort: securePorts) {
if (port == securePort) {
- tlsSession.start(sslContext, sslBufferManagement,
+ tlsSession.startTls(sslContext, sslBufferManagement,
H2TlsSupport.decorateInitializer(initializer), verifier);
break;
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java Wed Apr 19 16:39:18 2017
@@ -33,12 +33,12 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLParameters;
+import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
-final class H2TlsSupport {
+public final class H2TlsSupport {
private final static String[] PROTOCOL_BLACKLIST = {
"TLSv1",
@@ -362,11 +362,11 @@ final class H2TlsSupport {
return new SSLSessionInitializer() {
@Override
- public void initialize(final SSLEngine sslengine) throws SSLException {
- sslengine.setEnabledProtocols(H2TlsSupport.excludeBlacklistedProtocols(sslengine.getEnabledProtocols()));
- sslengine.setEnabledCipherSuites(H2TlsSupport.excludeBlacklistedCiphers(sslengine.getEnabledCipherSuites()));
+ public void initialize(final NamedEndpoint endpoint, final SSLParameters sslParameters) {
+ sslParameters.setProtocols(H2TlsSupport.excludeBlacklistedProtocols(sslParameters.getProtocols()));
+ sslParameters.setCipherSuites(H2TlsSupport.excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
if (initializer != null) {
- initializer.initialize(sslengine);
+ initializer.initialize(endpoint, sslParameters);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java Wed Apr 19 16:39:18 2017
@@ -59,8 +59,7 @@ import org.apache.hc.core5.http.nio.NHtt
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -96,7 +95,7 @@ class InternalClientHttp1EventHandlerFac
}
protected ClientHttp1StreamDuplexer createClientHttp1StreamDuplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final H1Config h1Config,
final CharCodingConfig charCodingConfig,
@@ -114,10 +113,10 @@ class InternalClientHttp1EventHandlerFac
}
@Override
- public IOEventHandler createHandler(final IOSession ioSession, final Object attachment) {
+ public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
final String id = ioSession.getId();
- if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
- ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
+ if (sslContext != null) {
+ ioSession.startTls(sslContext, null ,null, null);
}
final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
final Logger wireLog = LogManager.getLogger("org.apache.hc.core5.http.wire");
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java Wed Apr 19 16:39:18 2017
@@ -41,8 +41,7 @@ import org.apache.hc.core5.http2.impl.ni
import org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiator;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -69,10 +68,10 @@ class InternalClientHttp2EventHandlerFac
}
@Override
- public IOEventHandler createHandler(final IOSession ioSession, final Object attachment) {
+ public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
final String id = ioSession.getId();
- if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
- ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
+ if (sslContext != null) {
+ ioSession.startTls(sslContext, null ,null, null);
}
final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
return new LoggingIOEventHandler(new ClientHttpProtocolNegotiator(
@@ -104,7 +103,7 @@ class InternalClientHttp2EventHandlerFac
}, new InternalHttp2StreamListener(id)) {
@Override
- protected ClientHttp2StreamMultiplexer createStreamMultiplexer(final IOSession ioSession) {
+ protected ClientHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
return super.createStreamMultiplexer(new LoggingIOSession(ioSession, sessionLog));
}
}, id, sessionLog);
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java Wed Apr 19 16:39:18 2017
@@ -61,8 +61,7 @@ import org.apache.hc.core5.http.nio.NHtt
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -101,7 +100,7 @@ class InternalServerHttp1EventHandlerFac
}
protected ServerHttp1StreamDuplexer createServerHttp1StreamDuplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
final H1Config h1Config,
@@ -119,10 +118,10 @@ class InternalServerHttp1EventHandlerFac
}
@Override
- public IOEventHandler createHandler(final IOSession ioSession, final Object attachment) {
+ public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
final String id = ioSession.getId();
- if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
- ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
+ if (sslContext != null) {
+ ioSession.startTls(sslContext, null ,null, null);
}
final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
final Logger wireLog = LogManager.getLogger("org.apache.hc.core5.http.wire");
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java Wed Apr 19 16:39:18 2017
@@ -41,8 +41,7 @@ import org.apache.hc.core5.http2.impl.ni
import org.apache.hc.core5.http2.impl.nio.ServerHttpProtocolNegotiator;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -69,10 +68,10 @@ class InternalServerHttp2EventHandlerFac
}
@Override
- public IOEventHandler createHandler(final IOSession ioSession, final Object attachment) {
+ public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
final String id = ioSession.getId();
- if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
- ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
+ if (sslContext != null) {
+ ioSession.startTls(sslContext, null ,null, null);
}
final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
return new LoggingIOEventHandler(new ServerHttpProtocolNegotiator(
@@ -104,7 +103,7 @@ class InternalServerHttp2EventHandlerFac
}, new InternalHttp2StreamListener(id)) {
@Override
- protected ServerHttp2StreamMultiplexer createStreamMultiplexer(final IOSession ioSession) {
+ protected ServerHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
return super.createStreamMultiplexer(new LoggingIOSession(ioSession, sessionLog));
}
}, id, sessionLog);
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java Wed Apr 19 16:39:18 2017
@@ -30,6 +30,8 @@ package org.apache.hc.core5.testing.nio;
import java.io.IOException;
import java.net.SocketAddress;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
@@ -98,6 +100,11 @@ public class LoggingIOEventHandler imple
}
@Override
+ public SSLSession getSSLSession() {
+ return handler.getSSLSession();
+ }
+
+ @Override
public EndpointDetails getEndpointDetails() {
return handler.getEndpointDetails();
}
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java Wed Apr 19 16:39:18 2017
@@ -39,21 +39,20 @@ import javax.net.ssl.SSLSession;
import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.IOEventHandler;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
import org.apache.hc.core5.testing.classic.Wire;
import org.apache.logging.log4j.Logger;
-public class LoggingIOSession implements IOSession, TransportSecurityLayer {
+public class LoggingIOSession implements TlsCapableIOSession {
private final Logger log;
private final Wire wirelog;
- private final IOSession session;
+ private final TlsCapableIOSession session;
private final ByteChannel channel;
- public LoggingIOSession(final IOSession session, final Logger log, final Logger wirelog) {
+ public LoggingIOSession(final TlsCapableIOSession session, final Logger log, final Logger wirelog) {
super();
this.session = session;
this.log = log;
@@ -61,7 +60,7 @@ public class LoggingIOSession implements
this.channel = wirelog != null ? new LoggingByteChannel() : session.channel();
}
- public LoggingIOSession(final IOSession session, final Logger log) {
+ public LoggingIOSession(final TlsCapableIOSession session, final Logger log) {
this(session, log, null);
}
@@ -198,25 +197,17 @@ public class LoggingIOSession implements
}
@Override
- public void start(
+ public void startTls(
final SSLContext sslContext,
final SSLBufferManagement sslBufferManagement,
final SSLSessionInitializer initializer,
final SSLSessionVerifier verifier) throws UnsupportedOperationException {
- if (session instanceof TransportSecurityLayer) {
- ((TransportSecurityLayer) session).start(sslContext, sslBufferManagement, initializer, verifier);
- } else {
- throw new UnsupportedOperationException();
- }
+ session.startTls(sslContext, sslBufferManagement, initializer, verifier);
}
@Override
public SSLSession getSSLSession() {
- if (session instanceof TransportSecurityLayer) {
- return ((TransportSecurityLayer) session).getSSLSession();
- } else {
- return null;
- }
+ return session.getSSLSession();
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java Wed Apr 19 16:39:18 2017
@@ -122,6 +122,7 @@ import org.apache.hc.core5.reactor.IOEve
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.SessionRequest;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.testing.ProtocolScheme;
import org.apache.hc.core5.util.CharArrayBuffer;
import org.apache.hc.core5.util.TextUtils;
@@ -1356,7 +1357,7 @@ public class Http1IntegrationTest extend
@Override
protected ServerHttp1StreamDuplexer createServerHttp1StreamDuplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
final H1Config h1Config,
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java Wed Apr 19 16:39:18 2017
@@ -43,6 +43,7 @@ import org.apache.hc.core5.reactor.IORea
import org.apache.hc.core5.reactor.IOReactorStatus;
import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.ListenerEndpoint;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -63,7 +64,7 @@ public class TestDefaultListeningIOReact
this.ioreactor = new DefaultListeningIOReactor(new IOEventHandlerFactory() {
@Override
- public IOEventHandler createHandler(final IOSession ioSession, final Object attachment) {
+ public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
return new IOEventHandler() {
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java Wed Apr 19 16:39:18 2017
@@ -30,6 +30,8 @@ package org.apache.hc.core5.http;
import java.io.IOException;
import java.net.SocketAddress;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.io.GracefullyCloseable;
/**
@@ -45,6 +47,11 @@ public interface HttpConnection extends
EndpointDetails getEndpointDetails();
/**
+ * Returns SSL session or {@code null} if TLS has not been activated.
+ */
+ SSLSession getSSLSession();
+
+ /**
* Closes this connection gracefully.
* This method will attempt to flush the internal output
* buffer prior to closing the underlying socket.
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java Wed Apr 19 16:39:18 2017
@@ -39,6 +39,9 @@ import java.nio.charset.CharsetEncoder;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
import org.apache.hc.core5.function.Supplier;
import org.apache.hc.core5.http.ConnectionClosedException;
import org.apache.hc.core5.http.ContentLengthStrategy;
@@ -317,6 +320,17 @@ class BHttpConnectionBase implements BHt
}
@Override
+ public SSLSession getSSLSession() {
+ final SocketHolder socketHolder = this.socketHolderRef.get();
+ if (socketHolder != null) {
+ final Socket socket = socketHolder.getSocket();
+ return socket instanceof SSLSocket ? ((SSLSocket) socket).getSession() : null;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
public EndpointDetails getEndpointDetails() {
if (endpointDetails == null) {
final SocketHolder socketHolder = this.socketHolderRef.get();
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java Wed Apr 19 16:39:18 2017
@@ -139,6 +139,7 @@ public class HttpRequestExecutor {
try {
ClassicHttpResponse response = null;
+ context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails());
conn.sendRequestHeader(request);
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java Wed Apr 19 16:39:18 2017
@@ -178,6 +178,7 @@ public class HttpService {
if (transportVersion != null) {
context.setProtocolVersion(transportVersion);
}
+ context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails());
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
this.processor.process(request, request.getEntity(), context);
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java Wed Apr 19 16:39:18 2017
@@ -30,6 +30,8 @@ package org.apache.hc.core5.http.impl.ni
import java.io.IOException;
import java.net.SocketAddress;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.io.ShutdownType;
@@ -111,6 +113,11 @@ class AbstractHttp1IOEventHandler implem
}
@Override
+ public SSLSession getSSLSession() {
+ return streamDuplexer.getSSLSession();
+ }
+
+ @Override
public EndpointDetails getEndpointDetails() {
return streamDuplexer.getEndpointDetails();
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java Wed Apr 19 16:39:18 2017
@@ -72,11 +72,10 @@ import org.apache.hc.core5.net.InetAddre
import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.EventMask;
import org.apache.hc.core5.reactor.IOEventHandler;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
import org.apache.hc.core5.util.Args;
abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage, OutgoingMessage extends HttpMessage>
@@ -84,7 +83,7 @@ abstract class AbstractHttp1StreamDuplex
private enum ConnectionState { READY, ACTIVE, GRACEFUL_SHUTDOWN, SHUTDOWN}
- private final IOSession ioSession;
+ private final TlsCapableIOSession ioSession;
private final H1Config h1Config;
private final SessionInputBufferImpl inbuf;
private final SessionOutputBufferImpl outbuf;
@@ -106,7 +105,7 @@ abstract class AbstractHttp1StreamDuplex
private volatile EndpointDetails endpointDetails;
AbstractHttp1StreamDuplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final H1Config h1Config,
final CharCodingConfig charCodingConfig,
final NHttpMessageParser<IncomingMessage> incomingMessageParser,
@@ -570,24 +569,16 @@ abstract class AbstractHttp1StreamDuplex
@Override
public SSLSession getSSLSession() {
- if (ioSession instanceof TransportSecurityLayer) {
- return ((TransportSecurityLayer) ioSession).getSSLSession();
- } else {
- return null;
- }
+ return ioSession.getSSLSession();
}
@Override
- public void start(
+ public void startTls(
final SSLContext sslContext,
final SSLBufferManagement sslBufferManagement,
final SSLSessionInitializer initializer,
final SSLSessionVerifier verifier) throws UnsupportedOperationException {
- if (ioSession instanceof TransportSecurityLayer) {
- ((TransportSecurityLayer) ioSession).start(sslContext, sslBufferManagement, initializer, verifier);
- } else {
- throw new UnsupportedOperationException();
- }
+ ioSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java Wed Apr 19 16:39:18 2017
@@ -44,7 +44,7 @@ import org.apache.hc.core5.http.nio.NHtt
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -116,11 +116,11 @@ public class ClientHttp1IOEventHandlerFa
}
@Override
- public IOEventHandler createHandler(final IOSession ioSession, final Object attachment) {
+ public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
return new ClientHttp1IOEventHandler(createStreamDuplexer(ioSession));
}
- protected ClientHttp1StreamDuplexer createStreamDuplexer(final IOSession ioSession) {
+ protected ClientHttp1StreamDuplexer createStreamDuplexer(final TlsCapableIOSession ioSession) {
return new ClientHttp1StreamDuplexer(
ioSession,
httpProcessor,
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java Wed Apr 19 16:39:18 2017
@@ -64,7 +64,7 @@ import org.apache.hc.core5.http.nio.comm
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.io.ShutdownType;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Asserts;
@@ -83,7 +83,7 @@ public class ClientHttp1StreamDuplexer e
private volatile ClientHttp1StreamHandler incoming;
public ClientHttp1StreamDuplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final H1Config h1Config,
final CharCodingConfig charCodingConfig,
@@ -327,6 +327,7 @@ public class ClientHttp1StreamDuplexer e
void execute(final ExecutionCommand executionCommand) throws HttpException, IOException {
final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext());
+ context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
final ClientHttp1StreamHandler handler = new ClientHttp1StreamHandler(
outputChannel,
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java Wed Apr 19 16:39:18 2017
@@ -48,8 +48,7 @@ import org.apache.hc.core5.http.nio.ssl.
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -136,14 +135,14 @@ public class ServerHttp1IOEventHandlerFa
}
@Override
- public IOEventHandler createHandler(final IOSession ioSession, final Object attachment) {
+ public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
return new ServerHttp1IOEventHandler(createStreamDuplexer(ioSession));
}
- protected ServerHttp1StreamDuplexer createStreamDuplexer(final IOSession ioSession) {
- if (tlsStrategy != null && ioSession instanceof TransportSecurityLayer) {
+ protected ServerHttp1StreamDuplexer createStreamDuplexer(final TlsCapableIOSession ioSession) {
+ if (tlsStrategy != null) {
tlsStrategy.upgrade(
- (TransportSecurityLayer) ioSession,
+ ioSession,
null,
ioSession.getLocalAddress(),
ioSession.getRemoteAddress());
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java Wed Apr 19 16:39:18 2017
@@ -63,7 +63,7 @@ import org.apache.hc.core5.http.nio.comm
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.io.ShutdownType;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Asserts;
@@ -83,7 +83,7 @@ public class ServerHttp1StreamDuplexer e
private volatile ServerHttp1StreamHandler incoming;
public ServerHttp1StreamDuplexer(
- final IOSession ioSession,
+ final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
final H1Config h1Config,
@@ -302,6 +302,7 @@ public class ServerHttp1StreamDuplexer e
}
final ServerHttp1StreamHandler streamHandler;
final HttpCoreContext context = HttpCoreContext.create();
+ context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
if (outgoing == null) {
streamHandler = new ServerHttp1StreamHandler(
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java Wed Apr 19 16:39:18 2017
@@ -93,7 +93,7 @@ public class BasicClientTlsStrategy impl
final String... parameters) {
final String scheme = host != null ? host.getSchemeName() : null;
if ("https".equalsIgnoreCase(scheme)) {
- tlsSession.start(sslContext, sslBufferManagement, initializer, verifier);
+ tlsSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java Wed Apr 19 16:39:18 2017
@@ -100,7 +100,7 @@ public class BasicServerTlsStrategy impl
final int port = ((InetSocketAddress) localAddress).getPort();
for (final int securePort: securePorts) {
if (port == securePort) {
- tlsSession.start(sslContext, sslBufferManagement, initializer, verifier);
+ tlsSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
break;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpCoreContext.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpCoreContext.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpCoreContext.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpCoreContext.java Wed Apr 19 16:39:18 2017
@@ -27,6 +27,8 @@
package org.apache.hc.core5.http.protocol;
+import javax.net.ssl.SSLSession;
+
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
@@ -48,6 +50,12 @@ public class HttpCoreContext implements
public static final String CONNECTION_ENDPOINT = HttpContext.RESERVED_PREFIX + "connection-endpoint";
/**
+ * Attribute name of a {@link SSLSession} object that
+ * represents the actual connection endpoint details.
+ */
+ public static final String SSL_SESSION = HttpContext.RESERVED_PREFIX + "ssl-ession";
+
+ /**
* Attribute name of a {@link HttpRequest} object that
* represents the actual HTTP request.
*/
@@ -126,6 +134,13 @@ public class HttpCoreContext implements
}
/**
+ * @since 5.0
+ */
+ public SSLSession getSSLSession() {
+ return getAttribute(SSL_SESSION, SSLSession.class);
+ }
+
+ /**
* @since 5.0
*/
public EndpointDetails getEndpointDetails() {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java Wed Apr 19 16:39:18 2017
@@ -34,6 +34,6 @@ package org.apache.hc.core5.reactor;
*/
public interface IOEventHandlerFactory {
- IOEventHandler createHandler(IOSession ioSession, Object attachment);
+ IOEventHandler createHandler(TlsCapableIOSession ioSession, Object attachment);
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java Wed Apr 19 16:39:18 2017
@@ -58,7 +58,7 @@ class IOReactorImpl implements IOReactor
private final IOReactorConfig reactorConfig;
private final IOEventHandlerFactory eventHandlerFactory;
private final Selector selector;
- private final Queue<ManagedIOSession> closedSessions;
+ private final Queue<InternalIOSession> closedSessions;
private final Queue<PendingSession> pendingSessions;
private final AtomicReference<IOReactorStatus> status;
private final AtomicBoolean shutdownInitiated;
@@ -207,7 +207,7 @@ class IOReactorImpl implements IOReactor
if (this.sessionShutdownCallback != null) {
final Set<SelectionKey> keys = this.selector.keys();
for (final SelectionKey key : keys) {
- final ManagedIOSession session = (ManagedIOSession) key.attachment();
+ final InternalIOSession session = (InternalIOSession) key.attachment();
if (session != null) {
this.sessionShutdownCallback.execute(session);
}
@@ -239,7 +239,7 @@ class IOReactorImpl implements IOReactor
}
private void processEvent(final SelectionKey key) {
- final ManagedIOSession session = (ManagedIOSession) key.attachment();
+ final InternalIOSession session = (InternalIOSession) key.attachment();
try {
if (key.isReadable()) {
session.updateAccessTime();
@@ -260,13 +260,13 @@ class IOReactorImpl implements IOReactor
private void processPendingSessions() throws IOReactorException {
PendingSession pendingSession;
while ((pendingSession = this.pendingSessions.poll()) != null) {
- final ManagedIOSession session;
+ final InternalIOSession session;
try {
final SocketChannel socketChannel = pendingSession.socketChannel;
final SessionRequestImpl sessionRequest = pendingSession.sessionRequest;
socketChannel.configureBlocking(false);
final SelectionKey key = socketChannel.register(this.selector, SelectionKey.OP_READ);
- session = new ManagedIOSession(
+ session = new InternalIOSession(
sessionRequest != null ? sessionRequest.getRemoteEndpoint() : null,
new IOSessionImpl(key, socketChannel),
closedSessions);
@@ -301,7 +301,7 @@ class IOReactorImpl implements IOReactor
private void processClosedSessions() {
for (;;) {
- final ManagedIOSession session = this.closedSessions.poll();
+ final InternalIOSession session = this.closedSessions.poll();
if (session == null) {
break;
}
@@ -316,7 +316,7 @@ class IOReactorImpl implements IOReactor
}
private void timeoutCheck(final SelectionKey key, final long now) {
- final ManagedIOSession session = (ManagedIOSession) key.attachment();
+ final InternalIOSession session = (InternalIOSession) key.attachment();
if (session != null) {
try {
final int timeout = session.getSocketTimeout();
@@ -349,7 +349,7 @@ class IOReactorImpl implements IOReactor
private void closeActiveChannels() {
final Set<SelectionKey> keys = this.selector.keys();
for (final SelectionKey key : keys) {
- final ManagedIOSession session = (ManagedIOSession) key.attachment();
+ final InternalIOSession session = (InternalIOSession) key.attachment();
closeQuietly(session);
}
closeQuietly(this.selector);
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java (from r1791755, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java&r1=1791755&r2=1791940&rev=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java Wed Apr 19 16:39:18 2017
@@ -39,6 +39,7 @@ import javax.net.ssl.SSLSession;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
@@ -46,31 +47,32 @@ import org.apache.hc.core5.reactor.ssl.S
import org.apache.hc.core5.reactor.ssl.SSLMode;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
import org.apache.hc.core5.util.Asserts;
/**
* @since 5.0
*/
@Contract(threading = ThreadingBehavior.SAFE)
-class ManagedIOSession implements IOSession, TransportSecurityLayer {
+class InternalIOSession implements TlsCapableIOSession {
private final NamedEndpoint namedEndpoint;
private final IOSession ioSession;
private final AtomicReference<SSLIOSession> tlsSessionRef;
- private final Queue<ManagedIOSession> closedSessions;
+ private final Queue<InternalIOSession> closedSessions;
+ private final AtomicBoolean connected;
private final AtomicBoolean closed;
private volatile long lastAccessTime;
- ManagedIOSession(
+ InternalIOSession(
final NamedEndpoint namedEndpoint,
final IOSession ioSession,
- final Queue<ManagedIOSession> closedSessions) {
+ final Queue<InternalIOSession> closedSessions) {
this.namedEndpoint = namedEndpoint;
this.ioSession = ioSession;
this.closedSessions = closedSessions;
this.tlsSessionRef = new AtomicReference<>(null);
+ this.connected = new AtomicBoolean(false);
this.closed = new AtomicBoolean(false);
updateAccessTime();
}
@@ -105,19 +107,21 @@ class ManagedIOSession implements IOSess
void onConnected() {
try {
- final IOEventHandler handler = getEventHandler();
final SSLIOSession tlsSession = tlsSessionRef.get();
if (tlsSession != null) {
try {
if (!tlsSession.isInitialized()) {
tlsSession.initialize();
}
- handler.connected(this);
} catch (final Exception ex) {
+ final IOEventHandler handler = getEventHandler();
handler.exception(tlsSession, ex);
}
} else {
- handler.connected(this);
+ if (connected.compareAndSet(false, true)) {
+ final IOEventHandler handler = getEventHandler();
+ handler.connected(ioSession);
+ }
}
} catch (final RuntimeException ex) {
shutdown(ShutdownType.IMMEDIATE);
@@ -127,7 +131,6 @@ class ManagedIOSession implements IOSess
void onInputReady() {
try {
- final IOEventHandler handler = getEventHandler();
final SSLIOSession tlsSession = tlsSessionRef.get();
if (tlsSession != null) {
try {
@@ -136,16 +139,19 @@ class ManagedIOSession implements IOSess
}
if (tlsSession.isAppInputReady()) {
do {
- handler.inputReady(this);
+ final IOEventHandler handler = getEventHandler();
+ handler.inputReady(tlsSession);
} while (tlsSession.hasInputDate());
}
tlsSession.inboundTransport();
} catch (final IOException ex) {
+ final IOEventHandler handler = getEventHandler();
handler.exception(tlsSession, ex);
tlsSession.shutdown(ShutdownType.IMMEDIATE);
}
} else {
- handler.inputReady(this);
+ final IOEventHandler handler = getEventHandler();
+ handler.inputReady(ioSession);
}
} catch (final RuntimeException ex) {
shutdown(ShutdownType.IMMEDIATE);
@@ -155,7 +161,6 @@ class ManagedIOSession implements IOSess
void onOutputReady() {
try {
- final IOEventHandler handler = getEventHandler();
final SSLIOSession tlsSession = tlsSessionRef.get();
if (tlsSession != null) {
try {
@@ -163,15 +168,18 @@ class ManagedIOSession implements IOSess
tlsSession.initialize();
}
if (tlsSession.isAppOutputReady()) {
- handler.outputReady(this);
+ final IOEventHandler handler = getEventHandler();
+ handler.outputReady(tlsSession);
}
tlsSession.outboundTransport();
} catch (final IOException ex) {
+ final IOEventHandler handler = getEventHandler();
handler.exception(tlsSession, ex);
tlsSession.shutdown(ShutdownType.IMMEDIATE);
}
} else {
- handler.outputReady(this);
+ final IOEventHandler handler = getEventHandler();
+ handler.outputReady(ioSession);
}
} catch (final RuntimeException ex) {
shutdown(ShutdownType.IMMEDIATE);
@@ -182,7 +190,7 @@ class ManagedIOSession implements IOSess
void onTimeout() {
try {
final IOEventHandler handler = getEventHandler();
- handler.timeout(this);
+ handler.timeout(ioSession);
final SSLIOSession tlsSession = tlsSessionRef.get();
if (tlsSession != null) {
if (tlsSession.isOutboundDone() && !tlsSession.isInboundDone()) {
@@ -198,11 +206,11 @@ class ManagedIOSession implements IOSess
void onDisconnected() {
final IOEventHandler handler = getEventHandler();
- handler.disconnected(this);
+ handler.disconnected(ioSession);
}
@Override
- public void start(
+ public void startTls(
final SSLContext sslContext,
final SSLBufferManagement sslBufferManagement,
final SSLSessionInitializer initializer,
@@ -214,7 +222,18 @@ class ManagedIOSession implements IOSess
sslContext,
sslBufferManagement,
initializer,
- verifier))) {
+ verifier,
+ new Callback<SSLIOSession>() {
+
+ @Override
+ public void execute(final SSLIOSession sslSession) {
+ if (connected.compareAndSet(false, true)) {
+ final IOEventHandler handler = getEventHandler();
+ handler.connected(sslSession);
+ }
+ }
+
+ }))) {
throw new IllegalStateException("TLS already activated");
}
}
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequest.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequest.java Wed Apr 19 16:39:18 2017
@@ -84,12 +84,12 @@ public interface SessionRequest extends
boolean isCompleted();
/**
- * Returns {@link IOSession} instance created as a result of this request
+ * Returns {@link TlsCapableIOSession} instance created as a result of this request
* or {@code null} if the request is still pending.
*
* @return I/O session or {@code null} if the request is still pending.
*/
- IOSession getSession();
+ TlsCapableIOSession getSession();
/**
* Returns {@link IOException} instance if the request could not be
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequestImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequestImpl.java?rev=1791940&r1=1791939&r2=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequestImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/SessionRequestImpl.java Wed Apr 19 16:39:18 2017
@@ -55,7 +55,7 @@ public class SessionRequestImpl implemen
private final SessionRequestCallback callback;
private volatile int connectTimeout;
- private volatile IOSession session = null;
+ private volatile TlsCapableIOSession session = null;
private volatile IOException exception = null;
public SessionRequestImpl(
@@ -115,7 +115,7 @@ public class SessionRequestImpl implemen
}
@Override
- public IOSession getSession() {
+ public TlsCapableIOSession getSession() {
synchronized (this) {
return this.session;
}
@@ -128,7 +128,7 @@ public class SessionRequestImpl implemen
}
}
- public void completed(final IOSession session) {
+ public void completed(final TlsCapableIOSession session) {
Args.notNull(session, "Session");
if (this.completed) {
return;
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/TlsCapableIOSession.java (from r1791755, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/TlsCapableIOSession.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/TlsCapableIOSession.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java&r1=1791755&r2=1791940&rev=1791940&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/TlsCapableIOSession.java Wed Apr 19 16:39:18 2017
@@ -27,13 +27,13 @@
package org.apache.hc.core5.reactor;
+import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+
/**
- * Factory interface to create {@link IOEventHandler} instances for the given connected endpoints.
+ * TLS capable {@link IOSession}.
*
* @since 5.0
*/
-public interface IOEventHandlerFactory {
-
- IOEventHandler createHandler(IOSession ioSession, Object attachment);
+public interface TlsCapableIOSession extends IOSession, TransportSecurityLayer {
}