Skip to content

Commit

Permalink
Issue eclipse-ee4j#2016 Add support for JDK11 ALPN
Browse files Browse the repository at this point in the history
Create new phase in the handshake listener to allow registration of the
custom ALPN logic. This allows the HTTP/2 filter to work correctly.

Signed-off-by: Matthew Gill <matthew.gill@live.co.uk>
Signed-off-by: David Matějček <dmatej@seznam.cz>
  • Loading branch information
dmatej committed Nov 20, 2020
1 parent f4866af commit a2f7f4c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.glassfish.grizzly.ssl;

import javax.net.ssl.SSLEngine;

import org.glassfish.grizzly.Connection;

public interface HandshakeListener {
void onInit(Connection<?> connection, SSLEngine sslEngine);
void onStart(Connection<?> connection);
void onComplete(Connection<?> connection);
void onFailure(Connection<?> connection, Throwable t);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*
*
* Contributors:
* Payara Services - Add support for JDK 9 ALPN API
* - Propagate stop action on a closed SSL connection
Expand Down Expand Up @@ -193,7 +193,7 @@ public long getHandshakeTimeout(final TimeUnit timeUnit) {

/**
* Sets the handshake timeout.
*
*
* @param handshakeTimeout timeout value, or <code>-1</code> means for non-blocking handshake mode.
* @param timeUnit {@link TimeUnit}
*/
Expand Down Expand Up @@ -892,14 +892,6 @@ public void onComplete(final Context context, Object data) throws IOException {

} // END InternalProcessingHandler

public interface HandshakeListener {
void onStart(Connection<?> connection);

void onComplete(Connection<?> connection);

void onFailure(Connection<?> connection, Throwable t);
}

protected static class SSLTransportFilterWrapper extends TransportFilter {
protected final TransportFilter wrappedFilter;
protected final SSLBaseFilter sslBaseFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*
*
* Contributors:
* Payara Services - Add support for JDK 9 ALPN API
*/
Expand Down Expand Up @@ -56,7 +56,7 @@ public class AlpnSupport {

private static final AlpnSupport INSTANCE;
private static final Method nativeHandshakeMethod;

static {
boolean isExtensionFound = false;
Method setHandshakeAlpnSelector = null;
Expand Down Expand Up @@ -109,8 +109,7 @@ private static void setConnection(final SSLEngine engine, final Connection<?> co
private final Map<Object, AlpnClientNegotiator> clientSideNegotiators = new WeakHashMap<>();
private final ReadWriteLock clientSideLock = new ReentrantReadWriteLock();

private final HandshakeListener handshakeListener =
new HandshakeListener() {
private final HandshakeListener handshakeListener = new HandshakeListener() {

@Override
public void onInit(final Connection<?> connection, final SSLEngine sslEngine) {
Expand All @@ -136,7 +135,7 @@ public void onStart(final Connection<?> connection) {

if (sslEngine.getUseClientMode()) {
AlpnClientNegotiator negotiator = getClientNegotiator(connection);

if (negotiator != null) {
// add a CloseListener to ensure we remove the
// negotiator associated with this SSLEngine
Expand All @@ -152,7 +151,7 @@ public void onClosed(Closeable closeable, CloseType type) throws IOException {
}
} else {
AlpnServerNegotiator negotiator = getServerNegotiator(connection);

if (negotiator != null) {

// add a CloseListener to ensure we remove the
Expand Down Expand Up @@ -180,6 +179,7 @@ public void onFailure(Connection<?> connection, Throwable t) {
}
};


private AlpnSupport() {
}

Expand Down Expand Up @@ -222,12 +222,11 @@ private void putClientSideNegotiator(final Object object, final AlpnClientNegoti
clientSideLock.writeLock().unlock();
}
}


private AlpnClientNegotiator getClientNegotiator(Connection<?> connection) {
AlpnClientNegotiator negotiator;
clientSideLock.readLock().lock();

try {
negotiator = clientSideNegotiators.get(connection);
if (negotiator == null) {
Expand All @@ -243,7 +242,7 @@ private AlpnClientNegotiator getClientNegotiator(Connection<?> connection) {
private AlpnServerNegotiator getServerNegotiator(Connection<?> connection) {
AlpnServerNegotiator negotiator;
serverSideLock.readLock().lock();

try {
negotiator = serverSideNegotiators.get(connection);
if (negotiator == null) {
Expand Down

0 comments on commit a2f7f4c

Please sign in to comment.