Search in sources :

Example 1 with Jackson2Plugin

use of org.jdbi.v3.jackson2.Jackson2Plugin in project baremaps by baremaps.

the class TilesetsResourceIntegrationTest method configure.

@Override
protected ResourceConfig configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    // Create a data source with a throwaway postgres database
    DataSource dataSource = PostgresUtils.datasource("jdbc:tc:postgresql:13:///test");
    jdbi = Jdbi.create(dataSource).installPlugin(new Jackson2Plugin());
    jdbi.useHandle(handle -> handle.execute("create table tilesets (id uuid primary key, tileset jsonb)"));
    // Configure the service
    return new ResourceConfig().registerClasses(JacksonFeature.class, TilesetsResource.class).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(dataSource).to(DataSource.class);
            bind(jdbi).to(Jdbi.class);
        }
    });
}
Also used : JacksonFeature(com.fasterxml.jackson.core.util.JacksonFeature) Jdbi(org.jdbi.v3.core.Jdbi) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) Jackson2Plugin(org.jdbi.v3.jackson2.Jackson2Plugin) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) DataSource(javax.sql.DataSource)

Example 2 with Jackson2Plugin

use of org.jdbi.v3.jackson2.Jackson2Plugin in project baremaps by baremaps.

the class Studio method call.

@Override
public Integer call() throws Exception {
    // Configure serialization
    ObjectMapper mapper = defaultObjectMapper();
    // Configure jdbi and set the ObjectMapper
    DataSource datasource = PostgresUtils.datasource(this.database);
    Jdbi jdbi = Jdbi.create(datasource).installPlugin(new PostgresPlugin()).installPlugin(new Jackson2Plugin()).configure(Jackson2Config.class, config -> config.setMapper(mapper));
    // Initialize the application
    ResourceConfig application = new ResourceConfig().registerClasses(SwaggerResource.class, RootResource.class, CorsFilter.class, ConformanceResource.class, CollectionsResource.class, StylesResource.class, TilesetsResource.class, StudioResource.class, ImportResource.class, MultiPartFeature.class).register(new ApiResource("studio-openapi.yaml")).register(contextResolverFor(mapper)).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(datasource).to(DataSource.class);
            bind(jdbi).to(Jdbi.class);
        }
    });
    BlockingStreamingHttpService httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
    ServerContext serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
    logger.info("Listening on {}", serverContext.listenAddress());
    serverContext.awaitShutdown();
    return 0;
}
Also used : SwaggerResource(com.baremaps.server.ogcapi.SwaggerResource) RootResource(com.baremaps.server.ogcapi.RootResource) CorsFilter(com.baremaps.server.common.CorsFilter) Jdbi(org.jdbi.v3.core.Jdbi) ApiResource(com.baremaps.server.ogcapi.ApiResource) ConformanceResource(com.baremaps.server.ogcapi.ConformanceResource) StylesResource(com.baremaps.server.ogcapi.StylesResource) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) Jackson2Plugin(org.jdbi.v3.jackson2.Jackson2Plugin) PostgresPlugin(org.jdbi.v3.postgres.PostgresPlugin) DataSource(javax.sql.DataSource) HttpJerseyRouterBuilder(io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder) BlockingStreamingHttpService(io.servicetalk.http.api.BlockingStreamingHttpService) ServerContext(io.servicetalk.transport.api.ServerContext) ImportResource(com.baremaps.server.studio.ImportResource) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) CollectionsResource(com.baremaps.server.ogcapi.CollectionsResource) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) StudioResource(com.baremaps.server.studio.StudioResource) TilesetsResource(com.baremaps.server.ogcapi.TilesetsResource) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Jackson2Plugin

use of org.jdbi.v3.jackson2.Jackson2Plugin in project baremaps by baremaps.

the class CollectionsResourceIntegrationTest method configure.

@Override
protected ResourceConfig configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    // Create a connection to a throwaway postgres database
    Connection connection;
    try {
        connection = DriverManager.getConnection("jdbc:tc:postgresql:13:///test");
    } catch (SQLException throwables) {
        throw new RuntimeException("Unable to connect to the database");
    }
    // Initialize the database
    jdbi = Jdbi.create(connection).installPlugin(new Jackson2Plugin());
    jdbi.useHandle(handle -> handle.execute("create table collections (id uuid primary key, collection jsonb)"));
    // Configure the service
    return new ResourceConfig().register(CollectionsResource.class).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(jdbi).to(Jdbi.class);
        }
    });
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) SQLException(java.sql.SQLException) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) Connection(java.sql.Connection) Jackson2Plugin(org.jdbi.v3.jackson2.Jackson2Plugin) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 4 with Jackson2Plugin

use of org.jdbi.v3.jackson2.Jackson2Plugin in project baremaps by baremaps.

the class StylesResourceIntegrationTest method configure.

@Override
protected ResourceConfig configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    // Create a connection to a throwaway postgres database
    Connection connection;
    try {
        connection = DriverManager.getConnection("jdbc:tc:postgresql:13:///test");
    } catch (SQLException throwables) {
        throw new RuntimeException("Unable to connect to the database");
    }
    // Initialize the database
    jdbi = Jdbi.create(connection).installPlugin(new Jackson2Plugin());
    jdbi.useHandle(handle -> handle.execute("create table styles (id uuid primary key, style jsonb)"));
    // Configure the service
    return new ResourceConfig().register(StylesResource.class).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(jdbi).to(Jdbi.class);
        }
    });
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) SQLException(java.sql.SQLException) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) Connection(java.sql.Connection) Jackson2Plugin(org.jdbi.v3.jackson2.Jackson2Plugin) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 5 with Jackson2Plugin

use of org.jdbi.v3.jackson2.Jackson2Plugin in project baremaps by baremaps.

the class ImportResourceIntegrationTest method configure.

@Override
protected ResourceConfig configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    // Create a datasource to a throwaway postgis database
    DataSource dataSource = PostgresUtils.datasource(DATABASE_URL);
    // Initialize the database
    jdbi = Jdbi.create(dataSource).installPlugin(new Jackson2Plugin()).installPlugin(new PostgisPlugin());
    jdbi.useHandle(handle -> handle.execute("create extension if not exists hstore;" + "create table collections (id uuid primary key, collection jsonb)"));
    // Configure the service
    return new ResourceConfig().registerClasses(MultiPartFeature.class, ImportResource.class).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(jdbi).to(Jdbi.class);
        }
    });
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) Jackson2Plugin(org.jdbi.v3.jackson2.Jackson2Plugin) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) PostgisPlugin(com.baremaps.postgres.jdbi.PostgisPlugin) DataSource(javax.sql.DataSource)

Aggregations

AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)6 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)6 Jdbi (org.jdbi.v3.core.Jdbi)6 Jackson2Plugin (org.jdbi.v3.jackson2.Jackson2Plugin)6 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 DataSource (javax.sql.DataSource)3 MultiPartFeature (org.glassfish.jersey.media.multipart.MultiPartFeature)2 PostgisPlugin (com.baremaps.postgres.jdbi.PostgisPlugin)1 CorsFilter (com.baremaps.server.common.CorsFilter)1 DefaultObjectMapper.defaultObjectMapper (com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper)1 ApiResource (com.baremaps.server.ogcapi.ApiResource)1 CollectionsResource (com.baremaps.server.ogcapi.CollectionsResource)1 ConformanceResource (com.baremaps.server.ogcapi.ConformanceResource)1 RootResource (com.baremaps.server.ogcapi.RootResource)1 StylesResource (com.baremaps.server.ogcapi.StylesResource)1 SwaggerResource (com.baremaps.server.ogcapi.SwaggerResource)1 TilesetsResource (com.baremaps.server.ogcapi.TilesetsResource)1 ImportResource (com.baremaps.server.studio.ImportResource)1 StudioResource (com.baremaps.server.studio.StudioResource)1