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:
final SSLSocket sslSocket = ...;
NextProtoNego.put(sslSocket, new NextProtoNego.ClientProvider()
{
@Override
public boolean supports()
{
return true;
}
@Override
public void unsupported()
{
NextProtoNego.remove(sslSocket);
}
@Override
public String selectProtocol(List<String> protocols)
{
NextProtoNego.remove(sslSocket);
return protocols.get(0);
}
});
Server side typical usage:
final SSLSocket sslSocket = ...;
NextProtoNego.put(sslSocket, new NextProtoNego.ServerProvider()
{
@Override
public void unsupported()
{
NextProtoNego.remove(sslSocket);
}
@Override
public List<String> protocols()
{
return Arrays.asList("http/1.1");
}
@Override
public void protocolSelected(String protocol)
{
NextProtoNego.remove(sslSocket);
System.out.println("Protocol Selected is: " + protocol);
}
});
The implementation must make sure to remove the SSLSocket or SSLEngine
instances when the NPN interaction is completed.
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.
|
static NextProtoNego.Provider |
remove(SSLEngine engine)
Unregisters the given SSLEngine.
|
static NextProtoNego.Provider |
remove(SSLSocket socket)
Unregisters the given SSLSocket.
|
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 socketremove(SSLSocket)public static NextProtoNego.Provider get(SSLSocket socket)
socket - a socket registered with put(SSLSocket, Provider)public static NextProtoNego.Provider remove(SSLSocket socket)
Unregisters the given SSLSocket.
socket - the socket to unregisterput(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 engineremove(SSLEngine)public static NextProtoNego.Provider get(SSLEngine engine)
engine - an engine registered with put(SSLEngine, Provider)public static NextProtoNego.Provider remove(SSLEngine engine)
Unregisters the given SSLEngine.
engine - the engine to unregisterput(SSLEngine, Provider)Copyright © 1995-2014 Mort Bay Consulting. All Rights Reserved.