public WebServer(ProxyConfiguration config, AuthenticationService authenticationService) { this.webServiceExecutor = Executors.newFixedThreadPool(32, new DefaultThreadFactory("pulsar-external-web")); this.server = new Server(new ExecutorThreadPool(webServiceExecutor)); this.externalServicePort = config.getWebServicePort(); this.authenticationService = authenticationService; this.config = config; List<ServerConnector> connectors = Lists.newArrayList(); ServerConnector connector = new ServerConnector(server, 1, 1); connector.setPort(externalServicePort); connectors.add(connector); if (config.isTlsEnabledInProxy()) { try { SslContextFactory sslCtxFactory = SecurityUtility.createSslContextFactory( config.isTlsAllowInsecureConnection(), config.getTlsTrustCertsFilePath(), config.getTlsCertificateFilePath(), config.getTlsKeyFilePath(), config.getTlsRequireTrustedClientCertOnConnect()); ServerConnector tlsConnector = new ServerConnector(server, 1, 1, sslCtxFactory); tlsConnector.setPort(config.getWebServicePortTls()); connectors.add(tlsConnector); } catch (GeneralSecurityException e) { throw new RuntimeException(e); } } // Limit number of concurrent HTTP connections to avoid getting out of file descriptors connectors.stream().forEach(c -> c.setAcceptQueueSize(1024 / connectors.size())); server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()])); }
public ServerManager(ServiceConfig config) { this.webServiceExecutor = Executors.newFixedThreadPool(32, new DefaultThreadFactory("pulsar-external-web")); this.server = new Server(new ExecutorThreadPool(webServiceExecutor)); this.externalServicePort = config.getWebServicePort(); List<ServerConnector> connectors = Lists.newArrayList(); ServerConnector connector = new ServerConnector(server, 1, 1); connector.setPort(externalServicePort); connectors.add(connector); if (config.isTlsEnabled()) { try { SslContextFactory sslCtxFactory = SecurityUtility.createSslContextFactory( config.isTlsAllowInsecureConnection(), config.getTlsTrustCertsFilePath(), config.getTlsCertificateFilePath(), config.getTlsKeyFilePath(), config.getTlsRequireTrustedClientCertOnConnect()); ServerConnector tlsConnector = new ServerConnector(server, 1, 1, sslCtxFactory); tlsConnector.setPort(config.getWebServicePortTls()); connectors.add(tlsConnector); } catch (GeneralSecurityException e) { throw new RestException(e); } } // Limit number of concurrent HTTP connections to avoid getting out of file descriptors connectors.stream().forEach(c -> c.setAcceptQueueSize(1024 / connectors.size())); server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()])); }
SslContextFactory sslCtxFactory = SecurityUtility.createSslContextFactory( config.isTlsAllowInsecureConnection(), config.getTlsTrustCertsFilePath(),
public WebService(PulsarService pulsar) throws PulsarServerException { this.handlers = Lists.newArrayList(); this.pulsar = pulsar; this.webServiceExecutor = Executors.newFixedThreadPool(WebService.NUM_ACCEPTORS, new DefaultThreadFactory("pulsar-web")); this.server = new Server(new ExecutorThreadPool(webServiceExecutor)); List<ServerConnector> connectors = new ArrayList<>(); ServerConnector connector = new PulsarServerConnector(server, 1, 1); connector.setPort(pulsar.getConfiguration().getWebServicePort()); connector.setHost(pulsar.getBindAddress()); connectors.add(connector); if (pulsar.getConfiguration().isTlsEnabled()) { try { SslContextFactory sslCtxFactory = SecurityUtility.createSslContextFactory( pulsar.getConfiguration().isTlsAllowInsecureConnection(), pulsar.getConfiguration().getTlsTrustCertsFilePath(), pulsar.getConfiguration().getTlsCertificateFilePath(), pulsar.getConfiguration().getTlsKeyFilePath(), pulsar.getConfiguration().getTlsRequireTrustedClientCertOnConnect()); ServerConnector tlsConnector = new PulsarServerConnector(server, 1, 1, sslCtxFactory); tlsConnector.setPort(pulsar.getConfiguration().getWebServicePortTls()); tlsConnector.setHost(pulsar.getBindAddress()); connectors.add(tlsConnector); } catch (GeneralSecurityException e) { throw new PulsarServerException(e); } } // Limit number of concurrent HTTP connections to avoid getting out of file descriptors connectors.forEach(c -> c.setAcceptQueueSize(WebService.MAX_CONCURRENT_REQUESTS / connectors.size())); server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()])); }