Top Description Inners Fields Constructors Methods
org.eclipse.jetty.alpn

public Class ALPN

extends Object
Class Inheritance
Imports
java.util.List, .Map, java.util.concurrent.ConcurrentHashMap, javax.net.ssl.SSLEngine, .SSLException, .SSLSocket

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 ClientProvider or with a 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:

final SSLSocket sslSocket = ...;
ALPN.put(sslSocket, new ALPN.ClientProvider()
{
    @Override
    public List<String> protocols()
    {
        return Arrays.asList("spdy/3", "http/1.1");
    }

    @Override
    public void unsupported()
    {
        ALPN.remove(sslSocket);
    }

    @Override
    public void selected(String protocol) throws SSLException
    {
        System.out.println("Selected protocol: " + protocol);
        ALPN.remove(sslSocket);
    }
 });

Server side typical usage:

final SSLSocket sslSocket = ...;
ALPN.put(sslSocket, new ALPN.ServerProvider()
{
    @Override
    public void unsupported()
    {
        ALPN.remove(sslSocket);
    }

    @Override
    public String select(List<String> protocols) throws SSLException
    {
        ALPN.remove(sslSocket);
        return protocols.get(0);
    }
 });

Applications must ensure to deregister SSLSocket or SSLEngine instances, because they are kept in a JVM 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 ALPN#debug field to true to have debug code printed to System#err.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ALPN.ClientProvider

The client-side provider interface that applications must implement to interact with the negotiation of the protocol.

public static interface
ALPN.Provider

Base, empty, interface for providers.

public static interface
ALPN.ServerProvider

The server-side provider interface that applications must implement to interact with the negotiation of the protocol.

Field Summary

Modifier and TypeField and Description
public static boolean
debug

Flag that enables printing of debug statements to System#err.

private static Map<Object, ALPN.Provider>

Constructor Summary

AccessConstructor and Description
private
ALPN()

Method Summary

Modifier and TypeMethod and Description
public static ALPN.Provider

Returns:

the provider registered with the given socket
get
(SSLSocket
a socket registered with put(SSLSocket, Provider)
socket
)

public static ALPN.Provider

Returns:

the provider registered with the given engine
get
(SSLEngine
an engine registered with put(SSLEngine, Provider)
engine
)

public static void
put(SSLSocket
the socket to register with the provider
socket
,
ALPN.Provider
the provider to register with the socket
provider
)

Registers a SSLSocket with a provider.

public static void
put(SSLEngine
the engine to register with the provider
engine
,
ALPN.Provider
the provider to register with the engine
provider
)

Registers a SSLEngine with a provider.

public static ALPN.Provider

Returns:

the provider registered with the socket
remove
(SSLSocket
the socket to unregister
socket
)

Unregisters the given SSLSocket.

public static ALPN.Provider

Returns:

the provider registered with the engine
remove
(SSLEngine
the engine to unregister
engine
)

Unregisters the given SSLEngine.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
public static boolean debug

Flag that enables printing of debug statements to System#err.

objectsback to summary
private static Map<Object, ALPN.Provider> objects

Constructor Detail

ALPNback to summary
private ALPN()

Method Detail

getback to summary
public static ALPN.Provider get(SSLSocket socket)
Parameters
socket:SSLSocket

a socket registered with put(SSLSocket, Provider)

Returns:ALPN.Provider

the provider registered with the given socket

getback to summary
public static ALPN.Provider get(SSLEngine engine)
Parameters
engine:SSLEngine

an engine registered with put(SSLEngine, Provider)

Returns:ALPN.Provider

the provider registered with the given engine

putback to summary
public static void put(SSLSocket socket, ALPN.Provider provider)

Registers a SSLSocket with a provider.

Parameters
socket:SSLSocket

the socket to register with the provider

provider:ALPN.Provider

the provider to register with the socket

See Also
remove(SSLSocket)
putback to summary
public static void put(SSLEngine engine, ALPN.Provider provider)

Registers a SSLEngine with a provider.

Parameters
engine:SSLEngine

the engine to register with the provider

provider:ALPN.Provider

the provider to register with the engine

See Also
remove(SSLEngine)
removeback to summary
public static ALPN.Provider remove(SSLSocket socket)

Unregisters the given SSLSocket.

Parameters
socket:SSLSocket

the socket to unregister

Returns:ALPN.Provider

the provider registered with the socket

See Also
put(SSLSocket, Provider)
removeback to summary
public static ALPN.Provider remove(SSLEngine engine)

Unregisters the given SSLEngine.

Parameters
engine:SSLEngine

the engine to unregister

Returns:ALPN.Provider

the provider registered with the engine

See Also
put(SSLEngine, Provider)
org.eclipse.jetty.alpn back to summary

public Interface ALPN.ClientProvider

extends Provider

The client-side provider interface that applications must implement to interact with the negotiation of the protocol.

Method Summary

Modifier and TypeMethod and Description
public List<String>

Returns:

the list of protocols supported by the client; if null or empty, the ALPN extension is not sent
protocols
()

Callback invoked to let the implementation know the list of protocols that should be added to the ALPN extension in a ClientHello TLS message.

public void
selected(String
the protocol selected by the server.
protocol
)

Callback invoked to let the client application know the protocol chosen by the server.

public void
unsupported()

Callback invoked to let the client application know that the server does not support ALPN.

Method Detail

protocolsback to summary
public List<String> protocols()

Callback invoked to let the implementation know the list of protocols that should be added to the ALPN extension in a ClientHello TLS message.

Returns:List<String>

the list of protocols supported by the client; if null or empty, the ALPN extension is not sent

selectedback to summary
public void selected(String protocol) throws SSLException

Callback invoked to let the client application know the protocol chosen by the server.

The implementation may throw an exception to indicate that the protocol selected by the server is not acceptable, causing the connection to be closed with a TLS alert of type no_application_protocol(120).

Parameters
protocol:String

the protocol selected by the server.

Exceptions
SSLException:
if the protocol negotiation failed.
unsupportedback to summary
public void unsupported()

Callback invoked to let the client application know that the server does not support ALPN.

org.eclipse.jetty.alpn back to summary

public Interface ALPN.Provider

Known Direct Subinterfaces
org.eclipse.jetty.alpn.ALPN.ClientProvider, org.eclipse.jetty.alpn.ALPN.ServerProvider

Base, empty, interface for providers.
org.eclipse.jetty.alpn back to summary

public Interface ALPN.ServerProvider

extends Provider

The server-side provider interface that applications must implement to interact with the negotiation of the protocol.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the protocol selected by the server application. A null value will indicate the server will not include the ALPN extension message in the ServerHello message. This means the server appears as though it doesn't support ALPN and lets the client decide how to handle the situation.
select
(List<String>
the protocols sent by the client.
protocols
)

Callback invoked to let the server application select a protocol among the ones sent by the client.

public void
unsupported()

Callback invoked to let the server application know that the client does not support ALPN.

Method Detail

selectback to summary
public String select(List<String> protocols) throws SSLException

Callback invoked to let the server application select a protocol among the ones sent by the client.

The implementation may throw an exception to indicate that the protocol negotiation is not possible, causing the connection to be closed with a TLS alert of type no_application_protocol(120).

Parameters
protocols:List<String>

the protocols sent by the client.

Returns:String

the protocol selected by the server application. A null value will indicate the server will not include the ALPN extension message in the ServerHello message. This means the server appears as though it doesn't support ALPN and lets the client decide how to handle the situation.

Exceptions
SSLException:
if the protocol negotiation failed.
unsupportedback to summary
public void unsupported()

Callback invoked to let the server application know that the client does not support ALPN.