io.dropwizard.jetty.ConnectorFactory Java Examples
The following examples show how to use
io.dropwizard.jetty.ConnectorFactory.
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: SelfHostAndPortModule.java From emodb with Apache License 2.0 | 6 votes |
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); } }
Example #2
Source File: ServiceUtil.java From helios with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: ServerUtils.java From foxtrot with Apache License 2.0 | 6 votes |
public static int port(ServerFactory serverFactory) { if(serverFactory instanceof SimpleServerFactory) { SimpleServerFactory simpleServerFactory = (SimpleServerFactory)serverFactory; return getPortFromConnector(simpleServerFactory.getConnector()); } if(serverFactory instanceof DefaultServerFactory) { DefaultServerFactory defaultServerFactory = (DefaultServerFactory)serverFactory; for(ConnectorFactory connectorFactory : defaultServerFactory.getApplicationConnectors()) { if(connectorFactory instanceof HttpConnectorFactory) { return getPortFromConnector(connectorFactory); } } } throw new PortExtractionException("Cannot extract port from connector"); }
Example #4
Source File: ScanUploadTest.java From emodb with Apache License 2.0 | 5 votes |
private static void updatePortsToAvoidCollision(Collection<ConnectorFactory> connectorFactoryCollection) { for (ConnectorFactory connectorFactory : connectorFactoryCollection) { if (connectorFactory instanceof HttpConnectorFactory) { HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory)connectorFactory; httpConnectorFactory.setPort(httpConnectorFactory.getPort() + 100); } } }
Example #5
Source File: BaseRoleConnectHelper.java From emodb with Apache License 2.0 | 5 votes |
protected String getAdminBaseURI () { int httpPort = 0; for(ConnectorFactory connector: ((DefaultServerFactory)_config.getServerFactory()).getAdminConnectors()) { if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) { httpPort = ((HttpConnectorFactory) connector).getPort(); break; } } return format("http://localhost:%d", httpPort); }
Example #6
Source File: BaseRoleConnectHelper.java From emodb with Apache License 2.0 | 5 votes |
protected String getServiceBaseURI () { int port = 0; for(ConnectorFactory connector: ((DefaultServerFactory)_config.getServerFactory()).getApplicationConnectors()) { if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) { port = ((HttpConnectorFactory) connector).getPort(); break; } } return format("http://localhost:%d", port); }
Example #7
Source File: BaseRoleConnectHelper.java From emodb with Apache License 2.0 | 5 votes |
protected int getServiceBasePort () { int port = 0; for(ConnectorFactory connector: ((DefaultServerFactory)_config.getServerFactory()).getApplicationConnectors()) { if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) { port = ((HttpConnectorFactory) connector).getPort(); break; } } return port; }
Example #8
Source File: SelfHostAndPortModule.java From emodb with Apache License 2.0 | 5 votes |
@Provides @Singleton @SelfHostAndPort public HostAndPort provideSelfHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> appConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { appConnectorFactories = ((DefaultServerFactory) serverFactory).getApplicationConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { appConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(appConnectorFactories); }
Example #9
Source File: SelfHostAndPortModule.java From emodb with Apache License 2.0 | 5 votes |
@Provides @Singleton @SelfAdminHostAndPort public HostAndPort provideSelfAdminHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> adminConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { adminConnectorFactories = ((DefaultServerFactory) serverFactory).getAdminConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { adminConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(adminConnectorFactories); }
Example #10
Source File: SoaBundle.java From soabase with Apache License 2.0 | 5 votes |
private static HostAndPort portFromConnectorFactories(List<ConnectorFactory> applicationConnectors) { if ( applicationConnectors.size() > 0 ) { return portFromConnectorFactory(applicationConnectors.get(0)); } return defaultHostAndPort; }
Example #11
Source File: SoaBundle.java From soabase with Apache License 2.0 | 5 votes |
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; }
Example #12
Source File: ServerUtils.java From foxtrot with Apache License 2.0 | 4 votes |
private static int getPortFromConnector(ConnectorFactory connectorFactory) { if(connectorFactory instanceof HttpConnectorFactory) { return ((HttpConnectorFactory)connectorFactory).getPort(); } throw new PortExtractionException("Cannot extract port from connector"); }