in impl/src/main/java/org/apache/peeco/impl/PeecoExtension.java [76:127]
void afterDeploymentValidation(@Observes AfterDeploymentValidation adv, HttpServer httpServer) throws Exception
{
if (!enabled)
{
return;
}
for (HttpHandlerInfo info : httpHandlerInfos)
{
info.bean = CDI.current().select(info.clazz).get();
}
logger.log(Level.INFO, "----AFTER DEPLOYMENT VALIDATION----");
SslContext sslCtx = null;
if (httpServer.isSsl())
{
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
}
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
NioEventLoopGroup workerGroup = new NioEventLoopGroup();
try
{
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(loggingHandler)
.childHandler(new PeecoChannelInitializer(sslCtx, httpHandlerInfos));
Channel ch = b.bind(httpServer.getPort()).sync().channel();
String[] localAddressSplitted = ch.localAddress().toString().split(":");
String port = localAddressSplitted[localAddressSplitted.length - 1];
System.out.println(port);
httpServer.setPort(Integer.parseInt(port));
//TODO set host in Configuration
logger.log(Level.INFO, "Peeco started successfully on " + (httpServer.isSsl() ? "https" : "http") +
"://127.0.0.1:" + httpServer.getPort() + '/');
ch.closeFuture().sync();
}
finally
{
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}