use of org.apache.hc.core5.http.impl.bootstrap.AsyncServerBootstrap in project commons-vfs by apache.
the class NHttpFileServer method start.
private NHttpFileServer start() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, InterruptedException, ExecutionException {
final AsyncServerBootstrap bootstrap = AsyncServerBootstrap.bootstrap();
SSLContext sslContext = null;
if (port == 8443 || port == 443) {
// Initialize SSL context
final URL url = NHttpFileServer.class.getResource("/test.keystore");
if (url == null) {
println("Keystore not found");
System.exit(1);
}
println("Loading keystore " + url);
sslContext = SSLContexts.custom().loadKeyMaterial(url, "nopassword".toCharArray(), "nopassword".toCharArray()).build();
bootstrap.setTlsStrategy(new BasicServerTlsStrategy(sslContext, new FixedPortStrategy(port)));
}
// @formatter:off
final IOReactorConfig config = IOReactorConfig.custom().setSoTimeout(15, TimeUnit.SECONDS).setTcpNoDelay(true).build();
// @formatter:on
server = bootstrap.setIOReactorConfig(config).register("*", new HttpFileHandler(docRoot)).create();
Runtime.getRuntime().addShutdownHook(new Thread(() -> close()));
server.start();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(port));
listenerEndpoint = future.get();
println("Serving " + docRoot + " on " + listenerEndpoint.getAddress() + (sslContext == null ? "" : " with " + sslContext.getProvider() + " " + sslContext.getProtocol()));
return this;
}
Aggregations