Package org.eclipse.jetty.alpn
Class ALPN
java.lang.Object
org.eclipse.jetty.alpn.ALPN
ALPN
provides an API to applications that want to make use of the
Application Layer Protocol Negotiation.
The ALPN extension is only available when using the TLS protocol, therefore applications must
ensure that the TLS protocol is used:
SSLContext context = SSLContext.getInstance("TLSv1");Refer to the list of standard SSLContext protocol names for further information on TLS protocol versions supported. Applications must register instances of either
SSLSocket
or SSLEngine
with a
ALPN.ClientProvider
or with a ALPN.ServerProvider
, depending whether they are on client or
server side.
The ALPN implementation will invoke the provider callbacks to allow applications to interact
with the negotiation of the protocol.
Client side typical usage:
SSLSocket sslSocket = ...; ALPN.put(sslSocket, new ALPN.ClientProvider() { @Override public boolean supports() { return true; } @Override public List<String> protocols() { return Arrays.asList("spdy/3", "http/1.1"); } @Override public void unsupported() { } @Override public void selected(String protocol) { System.out.println("Selected protocol: " + protocol); } });Server side typical usage:
SSLSocket sslSocket = ...; ALPN.put(sslSocket, new ALPN.ServerProvider() { @Override public void unsupported() { } @Override public String select(List<String> protocols) { return protocols.get(0); } });Applications must ensure to deregister
SSLSocket
or SSLEngine
instances,
because they are kept in a global map.
Deregistration should typically happen when the application detects the end of the protocol
negotiation, and/or when the associated socket connection is closed.
In order to help application development, you can set the debug
field
to true
to have debug code printed to System.err
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The client-side provider interface that applications must implement to interact with the negotiation of the protocol.static interface
Base, empty, interface for providers.static interface
The server-side provider interface that applications must implement to interact with the negotiation of the protocol. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic boolean
Flag that enables printing of debug statements toSystem.err
. -
Method Summary
Modifier and TypeMethodDescriptionstatic ALPN.Provider
static ALPN.Provider
static void
put
(SSLEngine engine, ALPN.Provider provider) Registers a SSLEngine with a provider.static void
put
(SSLSocket socket, ALPN.Provider provider) Registers a SSLSocket with a provider.static ALPN.Provider
Unregisters the given SSLEngine.static ALPN.Provider
Unregisters the given SSLSocket.
-
Field Details
-
debug
public static boolean debugFlag that enables printing of debug statements toSystem.err
.
-
-
Method Details
-
put
Registers a SSLSocket with a provider.- Parameters:
socket
- the socket to register with the providerprovider
- the provider to register with the socket- See Also:
-
get
- Parameters:
socket
- a socket registered withput(SSLSocket, Provider)
- Returns:
- the provider registered with the given socket
-
remove
Unregisters the given SSLSocket.- Parameters:
socket
- the socket to unregister- Returns:
- the provider registered with the socket
- See Also:
-
put
Registers a SSLEngine with a provider.- Parameters:
engine
- the engine to register with the providerprovider
- the provider to register with the engine- See Also:
-
get
- Parameters:
engine
- an engine registered withput(SSLEngine, Provider)
- Returns:
- the provider registered with the given engine
-
remove
Unregisters the given SSLEngine.- Parameters:
engine
- the engine to unregister- Returns:
- the provider registered with the engine
- See Also:
-