public class NextProtoNego extends Object
NextProtoNego provides an API to applications that want to make use of the
Next Protocol Negotiation.
The NPN 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
NextProtoNego.ClientProvider or with a NextProtoNego.ServerProvider, depending whether they are on client or
server side.
The NPN implementation will invoke the provider callbacks to allow applications to interact with the negotiation of the next protocol.
Client side typical usage:
SSLSocket sslSocket = ...;
NextProtoNego.put(sslSocket, new NextProtoNego.ClientProvider()
{
@Override
public boolean supports()
{
return true;
}
@Override
public void unsupported()
{
}
@Override
public String selectProtocol(List<String> protocols)
{
return protocols.get(0);
}
});
Server side typical usage:
SSLSocket sslSocket = ...;
NextProtoNego.put(sslSocket, new NextProtoNego.ServerProvider()
{
@Override
public void unsupported()
{
}
@Override
public List protocols()
{
return Arrays.asList("http/1.1");
}
@Override
public void protocolSelected(String protocol)
{
System.out.println("Protocol Selected is: " + protocol);
}
});
There is no need to unregister SSLSocket or SSLEngine instances, as they
are kept in a WeakHashMap and will be garbage collected when the application does not
hard reference them anymore.
In order to help application development, you can set the debug field
to true to have debug code printed to System.err.
| Modifier and Type | Class and Description |
|---|---|
static interface |
NextProtoNego.ClientProvider
The client-side provider interface that applications must implement to interact
with the negotiation of the next protocol.
|
static interface |
NextProtoNego.Provider
Base, empty, interface for providers.
|
static interface |
NextProtoNego.ServerProvider
The server-side provider interface that applications must implement to interact
with the negotiation of the next protocol.
|
| Modifier and Type | Field and Description |
|---|---|
static boolean |
debug
Enables debug logging on
System.err. |
| Modifier and Type | Method and Description |
|---|---|
static NextProtoNego.Provider |
get(SSLEngine engine) |
static NextProtoNego.Provider |
get(SSLSocket socket) |
static void |
put(SSLEngine engine,
NextProtoNego.Provider provider)
Registers a SSLEngine with a provider.
|
static void |
put(SSLSocket socket,
NextProtoNego.Provider provider)
Registers a SSLSocket with a provider.
|
public static boolean debug
Enables debug logging on System.err.
public static void put(SSLSocket socket, NextProtoNego.Provider provider)
Registers a SSLSocket with a provider.
socket - the socket to register with the providerprovider - the provider to register with the socketpublic static NextProtoNego.Provider get(SSLSocket socket)
socket - a socket registered with put(SSLSocket, Provider)public static void put(SSLEngine engine, NextProtoNego.Provider provider)
Registers a SSLEngine with a provider.
engine - the engine to register with the providerprovider - the provider to register with the enginepublic static NextProtoNego.Provider get(SSLEngine engine)
engine - an engine registered with put(SSLEngine, Provider)Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.