io.dropwizard.server.SimpleServerFactory Java Examples
The following examples show how to use
io.dropwizard.server.SimpleServerFactory.
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: ComplianceToolModeConfigurationFactory.java From verify-service-provider with MIT License | 6 votes |
private ComplianceToolModeConfiguration createComplianceToolModeConfiguration() throws IOException { String serviceEntityId = UUID.randomUUID().toString(); KeysAndCert signingKeysAndCert = createKeysAndCert(serviceEntityId); KeysAndCert encryptionKeysAndCert = createKeysAndCert(serviceEntityId); ComplianceToolModeConfiguration complianceToolModeConfiguration = new ComplianceToolModeConfiguration(serviceEntityId, signingKeysAndCert, encryptionKeysAndCert); HttpConnectorFactory httpConnectorFactory = new HttpConnectorFactory(); httpConnectorFactory.setPort(port); httpConnectorFactory.setBindHost(bindHost); SimpleServerFactory simpleServerFactory = new SimpleServerFactory(); simpleServerFactory.setApplicationContextPath("/"); simpleServerFactory.setConnector(httpConnectorFactory); complianceToolModeConfiguration.setServerFactory(simpleServerFactory); complianceToolModeConfiguration.setLoggingFactory(new DefaultLoggingFactory()); return complianceToolModeConfiguration; }
Example #2
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 #3
Source File: BaragonAgentServiceModule.java From Baragon with Apache License 2.0 | 6 votes |
@Provides @Singleton public BaragonAgentMetadata providesAgentMetadata(BaragonAgentConfiguration config) throws Exception { final SimpleServerFactory simpleServerFactory = (SimpleServerFactory) config.getServerFactory(); final HttpConnectorFactory httpFactory = (HttpConnectorFactory) simpleServerFactory.getConnector(); final int httpPort = httpFactory.getPort(); final String hostname = config.getHostname().or(JavaUtils.getHostAddress()); final Optional<String> domain = config.getLoadBalancerConfiguration().getDomain(); final String appRoot = simpleServerFactory.getApplicationContextPath(); final String baseAgentUri = String.format(config.getBaseUrlTemplate(), hostname, httpPort, appRoot); final String agentId = String.format("%s:%s", hostname, httpPort); return new BaragonAgentMetadata(baseAgentUri, agentId, domain, BaragonAgentEc2Metadata.fromEnvironment(config.getPrivateIp(), config.isSkipPrivateIp()), config.getGcloudMetadata(), config.getExtraAgentData(), true); }
Example #4
Source File: ScanUploadTest.java From emodb with Apache License 2.0 | 5 votes |
private static void updatePortsToAvoidCollision(ServerFactory serverFactory) { if (serverFactory instanceof DefaultServerFactory) { DefaultServerFactory defaultServerFactory = (DefaultServerFactory)serverFactory; updatePortsToAvoidCollision(defaultServerFactory.getApplicationConnectors()); updatePortsToAvoidCollision(defaultServerFactory.getAdminConnectors()); } else if (serverFactory instanceof SimpleServerFactory) { SimpleServerFactory simpleServerFactory = (SimpleServerFactory)serverFactory; updatePortsToAvoidCollision(Collections.singleton(simpleServerFactory.getConnector())); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } }
Example #5
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 #6
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 #7
Source File: RandomPortsListener.java From dropwizard-guicey with MIT License | 5 votes |
@Override public void onRun(final Configuration configuration, final Environment environment, final DropwizardTestSupport<Configuration> rule) throws Exception { final ServerFactory server = configuration.getServerFactory(); if (server instanceof SimpleServerFactory) { ((HttpConnectorFactory) ((SimpleServerFactory) server).getConnector()).setPort(0); } else { final DefaultServerFactory dserv = (DefaultServerFactory) server; ((HttpConnectorFactory) dserv.getApplicationConnectors().get(0)).setPort(0); ((HttpConnectorFactory) dserv.getAdminConnectors().get(0)).setPort(0); } }
Example #8
Source File: SingularityMainModule.java From Singularity with Apache License 2.0 | 5 votes |
@Provides @Named(SingularityServiceUIModule.SINGULARITY_URI_BASE) String getSingularityUriBase(final SingularityConfiguration configuration) { final String singularityUiPrefix; if (configuration.getServerFactory() instanceof SimpleServerFactory) { singularityUiPrefix = configuration .getUiConfiguration() .getBaseUrl() .orElse( ( (SimpleServerFactory) configuration.getServerFactory() ).getApplicationContextPath() ); } else { singularityUiPrefix = configuration .getUiConfiguration() .getBaseUrl() .orElse( ( (DefaultServerFactory) configuration.getServerFactory() ).getApplicationContextPath() ); } return (singularityUiPrefix.endsWith("/")) ? singularityUiPrefix.substring(0, singularityUiPrefix.length() - 1) : singularityUiPrefix; }
Example #9
Source File: CasBlobStoreTest.java From emodb with Apache License 2.0 | 4 votes |
@BeforeClass public void setup() throws Exception { _lifeCycle = new SimpleLifeCycleRegistry(); _healthChecks = mock(HealthCheckRegistry.class); // Start test instance of ZooKeeper in the current JVM TestingServer testingServer = new TestingServer(); _lifeCycle.manage(testingServer); // Connect to ZooKeeper RetryPolicy retry = new BoundedExponentialBackoffRetry(100, 1000, 5); final CuratorFramework curator = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), retry); _lifeCycle.manage(curator).start(); Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(LifeCycleRegistry.class).toInstance(_lifeCycle); bind(HealthCheckRegistry.class).toInstance(_healthChecks); bind(TaskRegistry.class).toInstance(mock(TaskRegistry.class)); bind(BlobStoreConfiguration.class).toInstance(new BlobStoreConfiguration() .setValidTablePlacements(ImmutableSet.of(TABLE_PLACEMENT)) .setCassandraClusters(ImmutableMap.of( "media_global", new TestCassandraConfiguration("media_global", "ugc_blob")))); DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration() .setValidTablePlacements(ImmutableSet.of("app_global:sys", "ugc_global:ugc")) .setCassandraClusters(ImmutableMap.of( "ugc_global", new TestCassandraConfiguration("ugc_global", "ugc_delta_v2"), "app_global", new TestCassandraConfiguration("app_global", "sys_delta_v2"))) .setHistoryTtl(Duration.ofDays(2)); bind(DataStoreConfiguration.class).toInstance(dataStoreConfiguration); bind(String.class).annotatedWith(SystemTablePlacement.class).toInstance("app_global:sys"); bind(DataStore.class).annotatedWith(SystemDataStore.class).toInstance(mock(DataStore.class)); bind(BlobStore.class).annotatedWith(SystemBlobStore.class).toInstance(mock(BlobStore.class)); bind(JobService.class).toInstance(mock(JobService.class)); bind(JobHandlerRegistry.class).toInstance(mock(JobHandlerRegistry.class)); bind(DataCenterConfiguration.class).toInstance(new DataCenterConfiguration() .setCurrentDataCenter("datacenter1") .setSystemDataCenter("datacenter1") .setDataCenterServiceUri(URI.create("http://localhost:8080")) .setDataCenterAdminUri(URI.create("http://localhost:8080"))); bind(CqlDriverConfiguration.class).toInstance(new CqlDriverConfiguration()); bind(String.class).annotatedWith(ServerCluster.class).toInstance("local_default"); bind(String.class).annotatedWith(InvalidationService.class).toInstance("emodb-cachemgr"); bind(CuratorFramework.class).annotatedWith(Global.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(BlobStoreZooKeeper.class) .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-blob")); bind(CuratorFramework.class).annotatedWith(DataStoreZooKeeper.class) .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-sor")); bind(CuratorFramework.class).annotatedWith(GlobalFullConsistencyZooKeeper.class) .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-fct")); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForScans.class) .toInstance(Suppliers.ofInstance(true)); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForMultiGets.class) .toInstance(Suppliers.ofInstance(true)); bind(ServerFactory.class).toInstance(new SimpleServerFactory()); bind(ServiceRegistry.class).toInstance(mock(ServiceRegistry.class)); bind(Clock.class).toInstance(Clock.systemDefaultZone()); bind(String.class).annotatedWith(CompControlApiKey.class).toInstance("CompControlApiKey"); bind(CompactionControlSource.class).annotatedWith(LocalCompactionControl.class).toInstance(mock(CompactionControlSource.class)); bind(Environment.class).toInstance(mock(Environment.class)); EmoServiceMode serviceMode = EmoServiceMode.STANDARD_ALL; install(new SelfHostAndPortModule()); install(new DataCenterModule(serviceMode)); install(new CacheManagerModule()); install(new DataStoreModule(serviceMode)); install(new BlobStoreModule(serviceMode, "bv.emodb.blob", new MetricRegistry())); } }); _store = injector.getInstance(BlobStore.class); _lifeCycle.start(); TableOptions options = new TableOptionsBuilder().setPlacement(TABLE_PLACEMENT).build(); Audit audit = new AuditBuilder().setLocalHost().build(); _store.createTable(TABLE, options, ImmutableMap.of(), audit); }
Example #10
Source File: CasDataStoreTest.java From emodb with Apache License 2.0 | 4 votes |
@BeforeClass public void setup() throws Exception { _lifeCycle = new SimpleLifeCycleRegistry(); _healthChecks = mock(HealthCheckRegistry.class); // Start test instance of ZooKeeper in the current JVM TestingServer testingServer = new TestingServer(); _lifeCycle.manage(testingServer); // Connect to ZooKeeper final CuratorFramework curator = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new BoundedExponentialBackoffRetry(100, 1000, 5)); _lifeCycle.manage(curator).start(); // Setup the DataStoreModule Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(LifeCycleRegistry.class).toInstance(_lifeCycle); bind(HealthCheckRegistry.class).toInstance(_healthChecks); bind(TaskRegistry.class).toInstance(mock(TaskRegistry.class)); DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration() .setValidTablePlacements(ImmutableSet.of("app_global:sys", "ugc_global:ugc")) .setCassandraClusters(ImmutableMap.<String, CassandraConfiguration>of( "ugc_global", new TestCassandraConfiguration("ugc_global", "ugc_delta_v2"), "app_global", new TestCassandraConfiguration("app_global", "sys_delta_v2"))) .setHistoryTtl(Duration.ofDays(2)); bind(DataStoreConfiguration.class).toInstance(dataStoreConfiguration); bind(String.class).annotatedWith(SystemTablePlacement.class).toInstance("app_global:sys"); bind(DataStore.class).annotatedWith(SystemDataStore.class).toInstance(mock(DataStore.class)); bind(JobService.class).toInstance(mock(JobService.class)); bind(JobHandlerRegistry.class).toInstance(mock(JobHandlerRegistry.class)); bind(DataCenterConfiguration.class).toInstance(new DataCenterConfiguration() .setCurrentDataCenter("datacenter1") .setSystemDataCenter("datacenter1") .setDataCenterServiceUri(URI.create("http://localhost:8080")) .setDataCenterAdminUri(URI.create("http://localhost:8080"))); bind(CqlDriverConfiguration.class).toInstance(new CqlDriverConfiguration()); bind(KeyspaceDiscovery.class).annotatedWith(Names.named("blob")).toInstance(mock(KeyspaceDiscovery.class)); bind(String.class).annotatedWith(ServerCluster.class).toInstance("local_default"); bind(String.class).annotatedWith(ReplicationKey.class).toInstance("password"); bind(String.class).annotatedWith(InvalidationService.class).toInstance("emodb-cachemgr"); bind(CuratorFramework.class).annotatedWith(Global.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(DataStoreZooKeeper.class) .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-sor")); bind(CuratorFramework.class).annotatedWith(GlobalFullConsistencyZooKeeper.class) .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-fct")); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForScans.class) .toInstance(Suppliers.ofInstance(true)); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForMultiGets.class) .toInstance(Suppliers.ofInstance(true)); bind(ServerFactory.class).toInstance(new SimpleServerFactory()); bind(ServiceRegistry.class).toInstance(mock(ServiceRegistry.class)); bind(Clock.class).toInstance(Clock.systemDefaultZone()); bind(String.class).annotatedWith(CompControlApiKey.class).toInstance("CompControlApiKey"); bind(CompactionControlSource.class).annotatedWith(LocalCompactionControl.class).toInstance(mock(CompactionControlSource.class)); bind(Environment.class).toInstance(new Environment("emodb", Jackson.newObjectMapper(), Validation.buildDefaultValidatorFactory().getValidator(), new MetricRegistry(), ClassLoader.getSystemClassLoader())); EmoServiceMode serviceMode = EmoServiceMode.STANDARD_ALL; install(new SelfHostAndPortModule()); install(new DataCenterModule(serviceMode)); install(new CacheManagerModule()); install(new DataStoreModule(serviceMode)); } }); _store = injector.getInstance(DataStore.class); _lifeCycle.start(); Map<String, Object> template = Collections.emptyMap(); _store.createTable(TABLE, new TableOptionsBuilder().setPlacement("ugc_global:ugc").build(), template, newAudit("create table")); }