|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.streamhub.nio.NIOServer
com.streamhub.nio.SecureNIOServer
public class SecureNIOServer
A HTTPS version of NIOServer.
A SSLContext is passed to every constructor which defines where to
load the certificate from and which protocol to use. The SSLContext
must be initialized before being passed to the constructor.
This example shows how to load a keystore named .keystore from the
current directory, which is protected by the password changeit. The
protocol chosen in this case is SSL.
SSLContext context = SSLContext.getInstance("SSL");
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
Builder builder = Builder.newInstance(KeyStore.getDefaultType(), null, new File(".keystore"), new KeyStore.PasswordProtection("changeit"));
KeyStore keystore = builder.getKeyStore();
kmf.init(keystore, "changeit");
// MUST initialize the SSLContext before passing to SecureNIOServer
context.init(kmf.getKeyManagers(), null, null);
PushServer server = new SecureNIOServer(443, context);
server.start();
System.out.println("HTTPS server started on port 443");
System.out.println("Press any key to stop...");
System.in.read();
server.stop();
System.out.println("Server stopped");
For more information on importing SSL certificates in to keystores and using SSL in Java refer to some of the following resources:
NIOServer| Constructor Summary | |
|---|---|
SecureNIOServer(InetSocketAddress address,
InetSocketAddress streamingAdapterAddress,
SSLContext sslContext)
Creates a new HTTPS server bound to address and a streaming adapter bound to streamingAdapterAddress |
|
SecureNIOServer(InetSocketAddress address,
InetSocketAddress streamingAdapterAddress,
String licenseDir,
SSLContext sslContext)
Creates a new HTTPS server bound to address and a streaming adapter bound to streamingAdapterAddress. |
|
SecureNIOServer(InetSocketAddress address,
InetSocketAddress streamingAdapterAddress,
URL licenseUrl,
URL log4jConfigurationUrl,
SSLContext sslContext)
Creates a new HTTPS server bound to address and a streaming adapter bound to streamingAdapterAddress, loading the license and log4j xml configuration from the alternative locations specified by licenseUrl
and log4jConfigurationUrl respectively. |
|
SecureNIOServer(InetSocketAddress address,
SSLContext sslContext)
Creates a new HTTPS server bound to address. |
|
SecureNIOServer(int port,
SSLContext sslContext)
Creates a new HTTPS server bound to the wildcard address. |
|
| Method Summary |
|---|
| Methods inherited from class com.streamhub.nio.NIOServer |
|---|
addStaticContent, addStaticContent, getSubscriptionManager, isStarted, main, publish, start, stop |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.streamhub.api.PushServer |
|---|
addStaticContent, addStaticContent, getSubscriptionManager, isStarted, start, stop |
| Methods inherited from interface com.streamhub.api.Publisher |
|---|
publish |
| Constructor Detail |
|---|
public SecureNIOServer(int port,
SSLContext sslContext)
port - the port to listen onsslContext - an initiated SSLContext defining the
characteristics of the HTTPS certificate
public SecureNIOServer(InetSocketAddress address,
SSLContext sslContext)
address - the address to bind tosslContext - an initiated SSLContext defining the
characteristics of the HTTPS certificate
public SecureNIOServer(InetSocketAddress address,
InetSocketAddress streamingAdapterAddress,
SSLContext sslContext)
address - the address to bind the server tostreamingAdapterAddress - the address to listen for streaming adapterssslContext - an initiated SSLContext defining the
characteristics of the HTTPS certificate
public SecureNIOServer(InetSocketAddress address,
InetSocketAddress streamingAdapterAddress,
String licenseDir,
SSLContext sslContext)
null as the second argument.
address - the address to bind the server tostreamingAdapterAddress - the address to listen for streaming adapters or null if
a streaming adapter is not requiredlicenseDir - an alternative directory to load the license from. The
license file must be called "license.txt"sslContext - an initiated SSLContext defining the
characteristics of the HTTPS certificate
public SecureNIOServer(InetSocketAddress address,
InetSocketAddress streamingAdapterAddress,
URL licenseUrl,
URL log4jConfigurationUrl,
SSLContext sslContext)
licenseUrl
and log4jConfigurationUrl respectively. To choose not to start a streaming
adapter, pass null as the second argument.
The following URL formats are supported for the licenseUrl and
log4jConfigurationUrl parameters:
file:///C:/licenses/license.txthttp://www.example.com/logging/log4j.xmljar:file:///C:/lib/streamhub-license.jar!/license.txt or jar:http://www.example.com/logging/streamhub-logging.jar!/log4j.xmlcom.streamhub.util.UrlLoader e.g. UrlLoader.load("classpath:/license.txt"), or UrlLoader.load("classpath:/conf/log4j.xml")The default location for the license file is a file named "license.txt" in the current working directory (or "."). The default location for the log4j configuration is "conf/log4j.xml" relative to the current working directory.
address - the address to bind the server tostreamingAdapterAddress - the address to listen for streaming adapters or null if
a streaming adapter is not requiredlicenseUrl - an alternative URL to load the license fromlog4jConfigurationUrl - an alternative URL to load the log4j xml configuration fromsslContext - an initiated SSLContext defining the
characteristics of the HTTPS certificate
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||