Java Code Examples for io.dropwizard.setup.Environment#getObjectMapper()

The following examples show how to use io.dropwizard.setup.Environment#getObjectMapper() . 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: DropwizardService.java    From katharsis-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void run(DropwizardConfiguration dropwizardConfiguration, Environment environment) throws Exception {
    environment.lifecycle().manage(guiceBundle.getInjector().getInstance(MongoManaged.class));


    environment.jersey().property(KatharsisProperties.RESOURCE_SEARCH_PACKAGE, "io.katharsis.example.dropwizard.domain");
    environment.jersey().property(KatharsisProperties.RESOURCE_DEFAULT_DOMAIN, "http://localhost:8080");

    KatharsisFeature katharsisFeature = new KatharsisFeature(environment.getObjectMapper(),
            new QueryParamsBuilder(new DefaultQueryParamsParser()),
            new JsonServiceLocator() {
                @Override
                public <T> T getInstance(Class<T> aClass) {
                    return guiceBundle.getInjector().getInstance(aClass);
                }
            });
    environment.jersey().register(katharsisFeature);
}
 
Example 2
Source File: BreakerboxService.java    From breakerbox with Apache License 2.0 6 votes vote down vote up
private static void setupInstanceDiscovery(BreakerboxServiceConfiguration configuration,
                                           Environment environment) {
    final Optional<InstanceDiscovery> customInstanceDiscovery = createInstanceDiscovery(configuration, environment);
    if (customInstanceDiscovery.isPresent()) {
        if(configuration.getHystrixStreamSuffix().isPresent()){
            PluginsFactory.setInstanceDiscovery(RegisterClustersInstanceDiscoveryWrapper.wrap(
                    customInstanceDiscovery.get(),configuration.getHystrixStreamSuffix().get()));
        } else {
            PluginsFactory.setInstanceDiscovery(RegisterClustersInstanceDiscoveryWrapper.wrap(
                    customInstanceDiscovery.get()));
        }
    } else {
        final YamlInstanceDiscovery yamlInstanceDiscovery = new YamlInstanceDiscovery(
                configuration.getTurbine(), environment.getValidator(), environment.getObjectMapper());
        PluginsFactory.setInstanceDiscovery(RegisterClustersInstanceDiscoveryWrapper.wrap(yamlInstanceDiscovery));
    }
}
 
Example 3
Source File: StreamBroadcasterFactory.java    From cqrs-eventsourcing-kafka with Apache License 2.0 5 votes vote down vote up
public StreamBroadcaster build(Environment environment) {
    StreamBroadcaster broadcaster =
            new KafkaTopicBroadcaster(environment.getName(),
                    environment.getObjectMapper(),
                    bootstrap);

    environment.lifecycle().manage(broadcaster);

    return broadcaster;
}
 
Example 4
Source File: InventoryItemApi.java    From cqrs-eventsourcing-kafka with Apache License 2.0 5 votes vote down vote up
private static void configureObjectMapper(Environment environment) {
    ObjectMapper mapper = environment.getObjectMapper();
    mapper.findAndRegisterModules();

    SimpleModule module = new SimpleModule();
    module.addSerializer(ID.class, new IDSerializer());
    mapper.registerModule(module);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
 
Example 5
Source File: CommandListenerFactory.java    From cqrs-eventsourcing-kafka with Apache License 2.0 5 votes vote down vote up
public CommandListener build(Environment environment,
                             EventPublisher applicationEventPublisher, Class aggregateRoot) {
    KafkaCommandListener listener =
            new KafkaCommandListener(boostrap,
                    environment.getName(),
                    environment.getObjectMapper(),
                    applicationEventPublisher,
                    aggregateRoot.getSimpleName());

    environment.lifecycle().manage(listener);

    return listener;
}
 
Example 6
Source File: EventStoreFactory.java    From cqrs-eventsourcing-kafka with Apache License 2.0 5 votes vote down vote up
private EventStore buildJdbcEventStore(EventPublisher publisher, Environment environment) {
    ManagedDataSource ds = database.build(environment.metrics(), "eventstore");
    DBI jdbi = new DBIFactory().build(environment, database, "eventstore");
    updateDatabaseSchema(ds);
    EventStore eventStore = new JdbcEventStore(jdbi, environment.getObjectMapper(), publisher);
    return eventStore;
}
 
Example 7
Source File: InventoryItemDomain.java    From cqrs-eventsourcing-kafka with Apache License 2.0 5 votes vote down vote up
private static void configureObjectMapper(Environment environment) {
    ObjectMapper mapper = environment.getObjectMapper();
    mapper.findAndRegisterModules();

    SimpleModule module = new SimpleModule();
    module.addSerializer(ID.class, new IDSerializer());
    mapper.registerModule(module);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
 
Example 8
Source File: MetadataResource.java    From alchemy with MIT License 5 votes vote down vote up
@Inject
public MetadataResource(Environment environment, IdentitiesMetadata metadata, Mappers mapper) {
    this.metadata = metadata;
    this.identityTypesByName = Maps.transformValues(metadata, DTO_TYPES_MAPPER);
    this.schemaGenerator = new JsonSchemaGenerator(environment.getObjectMapper());
    this.mapper = mapper;
}
 
Example 9
Source File: ProductCatalogApplication.java    From bookstore-cqrs-example with Apache License 2.0 5 votes vote down vote up
@Override
public void run(ProductCatalogConfig configuration, Environment environment) {
  ObjectMapper objectMapper = environment.getObjectMapper();
  objectMapper.enable(INDENT_OUTPUT);
  objectMapper.enable(WRITE_DATES_AS_TIMESTAMPS);

  environment.jersey().register(new ProductResource(new InMemoryProductRepository()));
  configureCors(environment);
  logger.info("ProductCatalogApplication started!");
}
 
Example 10
Source File: OrderApplication.java    From bookstore-cqrs-example with Apache License 2.0 5 votes vote down vote up
@Override
public void run(OrderApplicationConfiguration configuration, Environment environment) throws Exception {
  ObjectMapper objectMapper = environment.getObjectMapper();
  objectMapper.enable(INDENT_OUTPUT);
  objectMapper.enable(WRITE_DATES_AS_TIMESTAMPS);

  OrderProjectionRepository orderRepository = new InMemOrderProjectionRepository();
  DomainEventBus domainEventBus = new GuavaDomainEventBus();
  OrderListDenormalizer orderListDenormalizer = domainEventBus.register(new OrderListDenormalizer(orderRepository));
  OrdersPerDayAggregator ordersPerDayAggregator = domainEventBus.register(new OrdersPerDayAggregator());

  ProductCatalogClient catalogClient = ProductCatalogClient.create(ClientBuilder.newClient(), configuration.productCatalogServiceUrl);

  DomainEventStore domainEventStore = (DomainEventStore) configuration.eventStore.newInstance();
  QueryService queryService = new QueryService(orderListDenormalizer, ordersPerDayAggregator, catalogClient);

  logger.info("Using eventStore: " + domainEventStore.getClass().getName());
  Repository aggregateRepository = new DefaultRepository(domainEventBus, domainEventStore);

  CommandBus commandBus = GuavaCommandBus.asyncGuavaCommandBus();
  commandBus.register(new OrderCommandHandler(aggregateRepository));
  commandBus.register(new PublisherContractCommandHandler(aggregateRepository));

  // Create and register Sagas
  PurchaseRegistrationSaga purchaseRegistrationSaga = new PurchaseRegistrationSaga(queryService, commandBus);
  domainEventBus.register(purchaseRegistrationSaga);

  environment.jersey().register(new QueryResource(queryService, domainEventStore));
  environment.jersey().register(new OrderResource(commandBus));
  environment.jersey().register(new PublisherContractResource(commandBus));
  environment.jersey().setUrlPattern("/service/*");

  environment.admin().addTask(new ReplayEventsTask(domainEventStore, domainEventBus));
  configureCors(environment);
  logger.info("OrderApplication started!");
}
 
Example 11
Source File: BreakerboxService.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
private static InstanceDiscovery createClassInstance(Class<InstanceDiscovery> instanceDiscoveryClass,
                                                BreakerboxServiceConfiguration configuration,
                                                Environment environment) throws Exception {
    if(instanceDiscoveryClass.equals(RancherInstanceDiscovery.class)
          && configuration.getRancherInstanceConfiguration().isPresent()) {
        return new RancherInstanceDiscovery(configuration.getRancherInstanceConfiguration().get(), environment.getObjectMapper());
    } else if (instanceDiscoveryClass.equals(YamlInstanceDiscovery.class)) {
        return new YamlInstanceDiscovery(configuration.getTurbine(), environment.getValidator(), environment.getObjectMapper());
    }
    else if (instanceDiscoveryClass.equals(MarathonInstanceDiscovery.class) && configuration.getMarathonClientConfiguration().isPresent()){
        return new MarathonInstanceDiscovery(environment.getObjectMapper(),configuration.getMarathonClientConfiguration().get());
    }
    return instanceDiscoveryClass.getConstructor().newInstance();
}
 
Example 12
Source File: NiPingMonitorApplication.java    From SAPNetworkMonitor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run(ServerConfiguration configuration, Environment environment) throws Exception {

    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "sapData");

    ObjectMapper objectMapper = environment.getObjectMapper();
    SapConfiguration sapConfiguration = configuration.getSapConfig();
    JobConfiguration jobConfiguration = configuration.getJobConfig();
    NiPingServiceBinder niPingServiceBinder = new NiPingServiceBinder(jdbi, objectMapper, sapConfiguration, jobConfiguration);

    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(niPingServiceBinder);
    SapBasicAuthenticator sapBasicAuthenticator = ServiceLocatorUtilities.getService(serviceLocator, SapBasicAuthenticator.class
            .getName());
    SapOAuthenticator sapOAuthenticator = ServiceLocatorUtilities.getService(serviceLocator, SapOAuthenticator.class.getName());

    final BasicCredentialAuthFilter basicAuthFilter = new BasicCredentialAuthFilter.Builder<BasicAuthUser>()
            .setAuthenticator(sapBasicAuthenticator)
            .buildAuthFilter();
    final AuthFilter oAuthFilter = new OAuthCredentialAuthFilter.Builder<OAuthUser>()
            .setAuthenticator(sapOAuthenticator)
            .setPrefix("Bearer")
            .buildAuthFilter();

    final PolymorphicAuthDynamicFeature feature = new PolymorphicAuthDynamicFeature<UserPrincipal>(ImmutableMap.of(BasicAuthUser
            .class, basicAuthFilter, OAuthUser.class, oAuthFilter));
    final AbstractBinder binder = new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(BasicAuthUser.class, OAuthUser
            .class));
    environment.jersey().register(new AuthFilterDynamicBinding());
    environment.jersey().register(feature);
    environment.jersey().register(binder);

    environment.jersey().register(niPingServiceBinder);
    environment.jersey().packages("com.cloudwise.sap.niping.auth");
    environment.jersey().packages("com.cloudwise.sap.niping.service");
    environment.jersey().packages("com.cloudwise.sap.niping.dao");
    environment.jersey().packages("com.cloudwise.sap.niping.common.vo.converter");
    environment.jersey().packages("com.cloudwise.sap.niping.resource");

    environment.jersey().register(SessionFactoryProvider.class);
    environment.servlets().setSessionHandler(new SessionHandler());
}
 
Example 13
Source File: CommandDispatcherFactory.java    From cqrs-eventsourcing-kafka with Apache License 2.0 4 votes vote down vote up
public CommandDispatcher build(Environment environment) {
    return new KafkaCommandDispatcher(boostrap, environment.getObjectMapper());
}
 
Example 14
Source File: EventPublisherFactory.java    From cqrs-eventsourcing-kafka with Apache License 2.0 4 votes vote down vote up
public EventPublisher build(Environment environment) {
    return new KafkaEventPublisher(bootstrap, environment.getObjectMapper());
}
 
Example 15
Source File: ServiceModule.java    From keywhiz with Apache License 2.0 4 votes vote down vote up
@Provides ObjectMapper configuredObjectMapper(Environment environment) {
  return environment.getObjectMapper();
}
 
Example 16
Source File: FoxtrotModule.java    From foxtrot with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
public ObjectMapper objectMapper(Environment environment) {
    return environment.getObjectMapper();
}