List of usage examples for io.netty.handler.ssl SslContext newServerContext
@Deprecated public static SslContext newServerContext(SslProvider provider, File certChainFile, File keyFile) throws SSLException
From source file:HttpSnoopServer.java
License:Apache License
public static void main(String[] args) throws Exception { SslContext sslCtx = null;//from w w w . j av a 2s.co m try { File certChainFile = new File("/Users/hyecheon/netty.cst"); File keyFile = new File("/Users/hyecheon/privatekey.pem"); keyFile.exists(); sslCtx = SslContext.newServerContext(certChainFile, keyFile, "HELLO"); } catch (SSLException e) { e.printStackTrace(); System.out.println("Can not create SSL context! \n Server will be stop!"); } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpSnoopServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.github.nettybook.ch8.HttpSnoopServer.java
License:Apache License
@SuppressWarnings("deprecation") public static void main(String[] args) throws Exception { SslContext sslCtx = null;/* ww w .j av a2s . c o m*/ try { File certChainFile = new File("netty.crt"); File keyFile = new File("privatekey.pem"); keyFile.exists(); sslCtx = SslContext.newServerContext(certChainFile, keyFile, "1234"); } catch (SSLException e) { e.printStackTrace(); System.out.println("Can not create SSL context! \n Server will be stop!"); } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpSnoopServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.netty.fileTest.http.download.HttpStaticFileServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {// w w w . j a v a 2s . co m SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newServerContext(SslProvider.JDK, ssc.certificate(), ssc.privateKey()); } else { sslCtx = null; } EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpStaticFileServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:fr.meuret.web.HttpServer.java
License:Apache License
/** * @throws Exception if anything goes wrong when starting the server. *//*from w w w . j ava2 s . c o m*/ public void start() throws Exception { logger.info("Starting HTTP server on port {}, ssl = {}, rootPath = {}", configuration.getPort(), configuration.useSSL(), configuration.getRootPath().toString()); // Configure SSL. final SslContext sslCtx; if (configuration.useSSL()) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newServerContext(SslProvider.JDK, ssc.certificate(), ssc.privateKey()); } else { sslCtx = null; } final EventLoopGroup bossGroup = new NioEventLoopGroup(1); final EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpStaticFileServerInitializer(sslCtx, configuration.getRootPath())); Channel ch = b.bind(configuration.getPort()).sync().channel(); logger.info("Open your web browser and navigate to " + (configuration.useSSL() ? "https" : "http") + "://127.0.0.1:" + configuration.getPort() + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:me.jesonlee.jjfsserver.httpserver.HttpStaticFileServer.java
License:Apache License
public static void main(String[] args) throws Exception { port = Integer.parseInt(System.getProperty("httpPort")); if (port < 1000 || port > 65535) { logger.error("port can not less than 1000 or beyond 65535"); System.exit(1);/*from w w w .j a v a2 s . com*/ } // Configure SSL. final SslContext sslCtx; if (SSL) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newServerContext(SslProvider.JDK, ssc.certificate(), ssc.privateKey()); } else { sslCtx = null; } EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpStaticFileServerInitializer(sslCtx)); Channel ch = b.bind(port).sync().channel(); System.out.println("http??" + port); logger.info("http??" + port); System.out.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:" + port + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:net.NettyEngine4.file.HttpStaticFileServer.java
License:Apache License
public static void main(String[] args) throws Exception { PropertyConfigurator.configure(Config.DEFAULT_VALUE.FILE_PATH.LOG4J); // Configure SSL. final SslContext sslCtx; if (SSL) {// ww w. j ava2s . c om SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newServerContext(SslProvider.JDK, ssc.certificate(), ssc.privateKey()); } else { sslCtx = null; } EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpStaticFileServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); LOGGER.debug("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }