Java Code Examples for org.glassfish.grizzly.http.server.NetworkListener#setSecure()
The following examples show how to use
org.glassfish.grizzly.http.server.NetworkListener#setSecure() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RpcServerManager.java From nuls-v2 with MIT License | 5 votes |
public void startServer(String ip, int port) { URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build(); // Create test web application context. WebappContext webappContext = new WebappContext("NULS-V2-SDK-PROVIDER-SERVER", "/"); ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class); servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.provider.api.config.NulsResourceConfig"); servletRegistration.addMapping("/*"); httpServer = new HttpServer(); NetworkListener listener = new NetworkListener("grizzly2", ip, port); TCPNIOTransport transport = listener.getTransport(); ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig() .setCorePoolSize(4) .setMaxPoolSize(4) .setQueueLimit(1000) .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build()); transport.configureBlocking(false); transport.setSelectorRunnersCount(2); transport.setWorkerThreadPoolConfig(workerPool); transport.setIOStrategy(WorkerThreadIOStrategy.getInstance()); transport.setTcpNoDelay(true); listener.setSecure(false); httpServer.addListener(listener); ServerConfiguration config = httpServer.getServerConfiguration(); config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET); webappContext.deploy(httpServer); try { ClassLoader loader = this.getClass().getClassLoader(); httpServer.start(); Log.info("http restFul server is started!url is " + serverURI.toString()); } catch (IOException e) { Log.error(e); httpServer.shutdownNow(); } }
Example 2
Source File: GrizzlyApplication.java From micro-server with Apache License 2.0 | 5 votes |
private NetworkListener createSSLListener(int port, SSLProperties sslProperties) { SSLConfigurationBuilder sslBuilder = new SSLConfigurationBuilder(); NetworkListener listener = new NetworkListener("grizzly", "0.0.0.0", Integer.valueOf(port)); listener.getFileCache().setEnabled(false); listener.setSecure(true); listener.setSSLEngineConfig(sslBuilder.build(sslProperties)); return listener; }
Example 3
Source File: ControllerAdminApiApplication.java From incubator-pinot with Apache License 2.0 | 5 votes |
private void configureListener(ListenerConfig listenerConfig, HttpServer httpServer) { final NetworkListener listener = new NetworkListener(listenerConfig.getName() + "-" + listenerConfig.getPort(), listenerConfig.getHost(), listenerConfig.getPort()); listener.getTransport().getWorkerThreadPoolConfig() .setThreadFactory(new ThreadFactoryBuilder().setNameFormat("grizzly-http-server-%d") .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build()); listener.setSecure(listenerConfig.getTlsConfiguration() != null); if (listener.isSecure()) { listener.setSSLEngineConfig(buildSSLEngineConfigurator(listenerConfig.getTlsConfiguration())); } httpServer.addListener(listener); }
Example 4
Source File: GrizzlyHttpService.java From linstor-server with GNU General Public License v3.0 | 4 votes |
private void initGrizzly(final String bindAddress, final String httpsBindAddress) { if (keyStoreFile != null) { final URI httpsUri = URI.create(String.format("https://%s", httpsBindAddress)); // only install a redirect handler for http httpServer = GrizzlyHttpServerFactory.createHttpServer( URI.create(String.format("http://%s", bindAddress)), false ); addHTTPSRedirectHandler(httpServer, httpsUri.getPort()); httpsServer = GrizzlyHttpServerFactory.createHttpServer( httpsUri, restResourceConfig, false ); SSLContextConfigurator sslCon = new SSLContextConfigurator(); sslCon.setSecurityProtocol("TLS"); sslCon.setKeyStoreFile(keyStoreFile.toString()); sslCon.setKeyStorePass(keyStorePassword); boolean hasClientAuth = trustStoreFile != null; if (hasClientAuth) { sslCon.setTrustStoreFile(trustStoreFile.toString()); sslCon.setTrustStorePass(trustStorePassword); } for (NetworkListener netListener : httpsServer.getListeners()) { netListener.setSecure(true); SSLEngineConfigurator ssle = new SSLEngineConfigurator(sslCon); ssle.setWantClientAuth(hasClientAuth); ssle.setClientMode(false); ssle.setNeedClientAuth(hasClientAuth); netListener.setSSLEngineConfig(ssle); } enableCompression(httpsServer); } else { httpsServer = null; httpServer = GrizzlyHttpServerFactory.createHttpServer( URI.create(String.format("http://%s", bindAddress)), restResourceConfig, false ); } // configure access logging if (restAccessLogMode == null) { errorReporter.logWarning("Unknown rest_access_log_mode set, fallback to append"); restAccessLogMode = LinstorConfig.RestAccessLogMode.APPEND; } if (restAccessLogMode != LinstorConfig.RestAccessLogMode.NO_LOG) { final Path accessLogPath = restAccessLogPath.isAbsolute() ? restAccessLogPath : errorReporter.getLogDirectory().resolve(restAccessLogPath); final AccessLogBuilder builder = new AccessLogBuilder(accessLogPath.toFile()); switch (restAccessLogMode) { case ROTATE_HOURLY: errorReporter.logDebug("Rest-access log set to rotate hourly."); builder.rotatedHourly(); break; case ROTATE_DAILY: errorReporter.logDebug("Rest-access log set to rotate daily."); builder.rotatedDaily(); break; case APPEND: case NO_LOG: default: } if (httpServer != null) { builder.instrument(httpServer.getServerConfiguration()); } if (httpsServer != null) { builder.instrument(httpsServer.getServerConfiguration()); } } else { errorReporter.logDebug("Rest-access log turned off."); } if (httpServer != null) { enableCompression(httpServer); } }