List of usage examples for org.apache.http.impl.nio SSLServerIOEventDispatch SSLServerIOEventDispatch
public SSLServerIOEventDispatch(final NHttpServiceHandler handler, final SSLContext sslcontext, final HttpParams params)
From source file:org.frameworkset.spi.remote.http.HttpServer.java
private void startHttps() throws Exception { try {// w ww .j a v a 2s . c o m this.ioReactor = new DefaultListeningIOReactor(workerCount, serverParams); EventListener serverEventListener = new EventListener() { // @Override public void connectionClosed(NHttpConnection conn) { // closedServerConns.decrement(); // super.connectionClosed(conn); // System.out.println("connectionClosed:" + conn); } public void connectionOpen(NHttpConnection conn) { // System.out.println("connectionOpen:" + conn); } public void connectionTimeout(NHttpConnection conn) { System.out.println("connectionTimeout:" + conn); } public void fatalIOException(IOException ex, NHttpConnection conn) { // System.out.println("fatalIOException:" + conn); ex.printStackTrace(); } public void fatalProtocolException(HttpException ex, NHttpConnection conn) { // System.out.println("fatalProtocolException:" + conn); ex.printStackTrace(); } }; final NHttpServiceHandler serviceHandler = createHttpServiceHandler(HttpUtil.getHttpBaseRPCIOHandler(), null, serverEventListener); this.endpoint = this.ioReactor.listen(new InetSocketAddress(ip, port)); ProMap ssls = ApplicationContext.getApplicationContext().getMapProperty("rpc.protocol.http.ssl.server"); if (ssls == null) { throw new Exception( "?ssl? rpc.protocol.http.ssl.server ?org/frameworkset/spi/manager-rpc-http.xml??"); } String keyStore = ssls.getString("keyStore"); String keyStorePassword = ssls.getString("keyStorePassword"); String trustStore = ssls.getString("trustStore"); String trustStorePassword = ssls.getString("trustStorePassword"); SSLContext sslcontext = SSLHelper.createSSLContext(keyStore, keyStorePassword, trustStore, trustStorePassword); IOEventDispatch ioEventDispatch = new SSLServerIOEventDispatch(serviceHandler, sslcontext, serverParams); // IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch( // serviceHandler, serverParams); // this.execute(serviceHandler, ioEventDispatch); this.thread = new IOReactorThread(ioEventDispatch); this.thread.start(); try { thread.join(1000); this.started = true; } catch (InterruptedException e) { e.printStackTrace(); } // ClassLoader cl = this.getClass().getClassLoader(); // URL url = cl.getResource("test.keystore"); // KeyStore keystore = KeyStore.getInstance("jks"); // keystore.load(url.openStream(), "nopassword".toCharArray()); // KeyManagerFactory kmfactory = KeyManagerFactory.getInstance( // KeyManagerFactory.getDefaultAlgorithm()); // kmfactory.init(keystore, "nopassword".toCharArray()); // KeyManager[] keymanagers = kmfactory.getKeyManagers(); // SSLContext sslcontext = SSLContext.getInstance("TLS"); // sslcontext.init(keymanagers, null, null); // // Set up request handlers // HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry(); // reqistry.register("*", new HttpFileHandler(args[0])); // // handler.setHandlerResolver(reqistry); // // // Provide an event logger // handler.setEventListener(new EventLogger()); // // // // ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params); // try { // ioReactor.listen(new InetSocketAddress(8080)); // ioReactor.execute(ioEventDispatch); // } catch (InterruptedIOException ex) { // System.err.println("Interrupted"); // } catch (IOException e) { // System.err.println("I/O error: " + e.getMessage()); // } // System.out.println("Shutdown"); } catch (IOReactorException e) { // TODO Auto-generated catch block e.printStackTrace(); } }