public static DefaultServerFactory createServerFactory(final InetSocketAddress httpEndpoint, final InetSocketAddress adminEndpoint, final boolean noHttp) { final DefaultServerFactory serverFactory = new DefaultServerFactory(); if (noHttp) { serverFactory.setApplicationConnectors(Collections.<ConnectorFactory>emptyList()); serverFactory.setAdminConnectors(Collections.<ConnectorFactory>emptyList()); } else { final HttpConnectorFactory serviceConnector = new HttpConnectorFactory(); serviceConnector.setPort(httpEndpoint.getPort()); serviceConnector.setBindHost(httpEndpoint.getHostString()); serverFactory.setApplicationConnectors(ImmutableList.<ConnectorFactory>of(serviceConnector)); final HttpConnectorFactory adminConnector = new HttpConnectorFactory(); adminConnector.setPort(adminEndpoint.getPort()); adminConnector.setBindHost(adminEndpoint.getHostString()); serverFactory.setAdminConnectors(ImmutableList.<ConnectorFactory>of(adminConnector)); } return serverFactory; } }
@Override public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) { final HttpConfiguration httpConfig = buildHttpConfiguration(); final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig); final Scheduler scheduler = new ScheduledExecutorScheduler(); final ByteBufferPool bufferPool = buildBufferPool(); return buildConnector(server, scheduler, bufferPool, name, threadPool, new Jetty93InstrumentedConnectionFactory(httpConnectionFactory, metrics.timer(httpConnections()))); }
@Inject SingularityHostAndPortProvider(final SingularityConfiguration configuration, @Named(HOST_NAME_PROPERTY) String hostname) { checkNotNull(configuration, "configuration is null"); this.hostname = configuration.getHostname().or(hostname); Integer port = null; if (configuration.getServerFactory() instanceof SimpleServerFactory) { SimpleServerFactory simpleServerFactory = (SimpleServerFactory) configuration.getServerFactory(); HttpConnectorFactory httpFactory = (HttpConnectorFactory) simpleServerFactory.getConnector(); port = httpFactory.getPort(); } else { DefaultServerFactory defaultServerFactory = (DefaultServerFactory) configuration.getServerFactory(); for (ConnectorFactory connectorFactory : defaultServerFactory.getApplicationConnectors()) { // Currently we will default to needing an http connector for service -> service communication if (connectorFactory instanceof HttpConnectorFactory && !(connectorFactory instanceof HttpsConnectorFactory)) { HttpConnectorFactory httpFactory = (HttpConnectorFactory) connectorFactory; port = httpFactory.getPort(); } } } if (port == null) { throw new RuntimeException("Could not determine http port"); } this.httpPort = port; }
@Override public void run(Configuration configuration, Environment environment) { final SimpleServerFactory serverConfig = new SimpleServerFactory(); configuration.setServerFactory(serverConfig); final HttpConnectorFactory connectorConfig = (HttpConnectorFactory) serverConfig.getConnector(); connectorConfig.setPort(0); environment.healthChecks().register("dummy", new DummyHealthCheck()); for (Object resource : resources) { if (resource instanceof Class<?>) { environment.jersey().register((Class<?>) resource); } else { environment.jersey().register(resource); } } } }
private static HostAndPort portFromConnectorFactory(ConnectorFactory connectorFactory) { if ( (connectorFactory != null) && HttpConnectorFactory.class.isAssignableFrom(connectorFactory.getClass()) ) { HttpConnectorFactory factory = (HttpConnectorFactory)connectorFactory; String bindHost = MoreObjects.firstNonNull(factory.getBindHost(), "localhost"); return HostAndPort.fromParts(bindHost, factory.getPort()); } return defaultHostAndPort; }
private void configureServerRuntime(DoctorKafkaAppConfig configuration, DoctorKafkaConfig config) { DefaultServerFactory defaultServerFactory = (DefaultServerFactory) configuration.getServerFactory(); // Disable gzip compression for HTTP, this is required in-order to make // Server-Sent-Events work, else due to GZIP the browser waits for entire chunks // to arrive thereby the UI receiving no events // We are programmatically disabling it here so it makes it easy to launch // Firefly GzipHandlerFactory gzipHandlerFactory = new GzipHandlerFactory(); gzipHandlerFactory.setEnabled(false); defaultServerFactory.setGzipFilterFactory(gzipHandlerFactory); // Note that if someone explicitly enables gzip in the Dropwizard config YAML // then // this setting will be over-ruled causing the UI to stop working // Disable HTTP request logging LogbackAccessRequestLogFactory accessRequestLogFactory = new LogbackAccessRequestLogFactory(); accessRequestLogFactory.setAppenders(ImmutableList.of()); defaultServerFactory.setRequestLogFactory(accessRequestLogFactory); // Disable admin connector defaultServerFactory.setAdminConnectors(ImmutableList.of()); // Configure bind host and port number HttpConnectorFactory application = (HttpConnectorFactory) HttpConnectorFactory.application(); application.setPort(config.getWebserverPort()); defaultServerFactory.setApplicationConnectors(Collections.singletonList(application)); }
public static ConnectorFactory application() { final HttpConnectorFactory factory = new HttpConnectorFactory(); factory.port = 8080; return factory; }
@Override protected ServerConnector buildConnector(Server server, Scheduler scheduler, ByteBufferPool bufferPool, String name, ThreadPool threadPool, ConnectionFactory... factories) { // Intercept any buildConnector() calls and wrap the provided ConnectionFactory instances with our InstrumentedConnectionFactoryWrapper InstrumentedConnectionFactoryWrapper connectionFactoryWrappers[] = new InstrumentedConnectionFactoryWrapper[factories.length]; for (int i = 0; i < factories.length; ++i) { connectionFactoryWrappers[i] = new InstrumentedConnectionFactoryWrapper(factories[i], _metricRegistry.get(), getBindHost(), getPort()); } return super.buildConnector(server, scheduler, bufferPool, name, threadPool, connectionFactoryWrappers); }
public int getAdminPort() { AbstractServerFactory sf = serverFactory(); if (sf instanceof SimpleServerFactory) { SimpleServerFactory ssf = (SimpleServerFactory) sf; return ((HttpConnectorFactory)ssf.getConnector()).getPort(); } if (sf instanceof DefaultServerFactory) { DefaultServerFactory dsf = (DefaultServerFactory) sf; return ((HttpConnectorFactory)dsf.getAdminConnectors().get(0)).getPort(); } throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName()); }
@SuppressWarnings("unchecked") public THIS overrideHttpPort(int p) { AbstractServerFactory sf = serverFactory(); if (sf instanceof SimpleServerFactory) { SimpleServerFactory ssf = (SimpleServerFactory) sf; ((HttpConnectorFactory)ssf.getConnector()).setPort(p); } else if (sf instanceof DefaultServerFactory) { DefaultServerFactory dsf = (DefaultServerFactory) sf; ((HttpConnectorFactory)dsf.getApplicationConnectors().get(0)).setPort(p); } else { throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName()); } return (THIS) this; }
private HostAndPort getHostAndPortFromConnectorFactories(List<ConnectorFactory> connectors) { // find the first connector that matches and return it host/port information (in practice there should // be one, and just one, match) try { HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory) Iterables.find(connectors, Predicates.instanceOf(HttpConnectorFactory.class)); String host = httpConnectorFactory.getBindHost(); if (host == null) { host = getLocalHost().getHostAddress(); } int port = httpConnectorFactory.getPort(); return HostAndPort.fromParts(host, port); } catch (NoSuchElementException ex) { throw new IllegalStateException("Did not find a valid HttpConnector for the server", ex); } }
public static ConnectorFactory admin() { final HttpConnectorFactory factory = new HttpConnectorFactory(); factory.port = 8081; return factory; }
@Override protected ServerConnector buildConnector(Server server, Scheduler scheduler, ByteBufferPool bufferPool, String name, ThreadPool threadPool, ConnectionFactory... factories) { // Intercept any buildConnector() calls and wrap the provided ConnectionFactory instances with our InstrumentedConnectionFactoryWrapper InstrumentedConnectionFactoryWrapper connectionFactoryWrappers[] = new InstrumentedConnectionFactoryWrapper[factories.length]; for (int i = 0; i < factories.length; ++i) { connectionFactoryWrappers[i] = new InstrumentedConnectionFactoryWrapper(factories[i], _metricRegistry.get(), getBindHost(), getPort()); } return super.buildConnector(server, scheduler, bufferPool, name, threadPool, connectionFactoryWrappers); }
public int getApplicationPort() { AbstractServerFactory sf = serverFactory(); if (sf instanceof SimpleServerFactory) { SimpleServerFactory ssf = (SimpleServerFactory) sf; return ((HttpConnectorFactory)ssf.getConnector()).getPort(); } if (sf instanceof DefaultServerFactory) { DefaultServerFactory dsf = (DefaultServerFactory) sf; return ((HttpConnectorFactory)dsf.getApplicationConnectors().get(0)).getPort(); } throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName()); }
@SuppressWarnings("unchecked") public THIS overrideAdminPort(int p) { AbstractServerFactory sf = serverFactory(); if (sf instanceof SimpleServerFactory) { // no admin port; just ignore } else if (sf instanceof DefaultServerFactory) { DefaultServerFactory dsf = (DefaultServerFactory) sf; ((HttpConnectorFactory)dsf.getAdminConnectors().get(0)).setPort(p); } else { throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName()); } return (THIS) this; }
private HostAndPort getHostAndPortFromConnectorFactories(List<ConnectorFactory> connectors) { // find the first connector that matches and return it host/port information (in practice there should // be one, and just one, match) try { HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory) Iterables.find(connectors, Predicates.instanceOf(HttpConnectorFactory.class)); String host = httpConnectorFactory.getBindHost(); if (host == null) { host = getLocalHost().getHostAddress(); } int port = httpConnectorFactory.getPort(); return HostAndPort.fromParts(host, port); } catch (NoSuchElementException ex) { throw new IllegalStateException("Did not find a valid HttpConnector for the server", ex); } }
public static DefaultServerFactory createServerFactory(final InetSocketAddress httpEndpoint, final int adminPort, final boolean noHttp) { // TODO(drewc) be more flexible on the httpEndpoint -- make it a URI -- so if/when we support // SSL, it'll *just work* final DefaultServerFactory serverFactory = new DefaultServerFactory(); if (noHttp) { serverFactory.setApplicationConnectors(Collections.<ConnectorFactory>emptyList()); serverFactory.setAdminConnectors(Collections.<ConnectorFactory>emptyList()); } else { final HttpConnectorFactory serviceConnector = new HttpConnectorFactory(); serviceConnector.setPort(httpEndpoint.getPort()); serviceConnector.setBindHost(httpEndpoint.getHostString()); serverFactory.setApplicationConnectors(ImmutableList.<ConnectorFactory>of(serviceConnector)); final HttpConnectorFactory adminConnector = new HttpConnectorFactory(); adminConnector.setPort(adminPort); serverFactory.setAdminConnectors(ImmutableList.<ConnectorFactory>of(adminConnector)); } return serverFactory; } }
@Override public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) { final HttpConfiguration httpConfig = buildHttpConfiguration(); final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig); final Scheduler scheduler = new ScheduledExecutorScheduler(); final ByteBufferPool bufferPool = buildBufferPool(); return buildConnector(server, scheduler, bufferPool, name, threadPool, new Jetty93InstrumentedConnectionFactory(httpConnectionFactory, metrics.timer(httpConnections()))); }
public static ConnectorFactory admin() { final HttpConnectorFactory factory = new HttpConnectorFactory(); factory.port = 8081; return factory; }
private int getPort(Configuration config) { int httpPort = 0; final SimpleServerFactory serverFactory = (SimpleServerFactory) config.getServerFactory(); final HttpConnectorFactory connector = (HttpConnectorFactory) serverFactory.getConnector(); if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) { httpPort = connector.getPort(); } return httpPort; } }