in baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java [69:135]
public Integer call() throws Exception {
var configReader = new ConfigReader();
var objectMapper = objectMapper();
var tileset = objectMapper.readValue(configReader.read(this.tilesetPath), Tileset.class);
var datasource = PostgresUtils.createDataSource(tileset.getDatabase());
var tileStoreType = new TypeLiteral<Supplier<TileStore>>() {};
var tileStoreSupplier = (Supplier<TileStore>) () -> {
try {
var tilesetObject =
objectMapper.readValue(configReader.read(this.tilesetPath), Tileset.class);
return new PostgresTileStore(datasource, tilesetObject);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
var styleSupplierType = new TypeLiteral<Supplier<Style>>() {};
var styleSupplier = (Supplier<Style>) () -> {
try {
var config = configReader.read(stylePath);
return objectMapper.readValue(config, Style.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
var tileJSONSupplierType = new TypeLiteral<Supplier<TileJSON>>() {};
var tileJSONSupplier = (Supplier<TileJSON>) () -> {
try {
var config = configReader.read(tilesetPath);
return objectMapper.readValue(config, TileJSON.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
var application = new ResourceConfig()
.register(CorsFilter.class)
.register(ChangeResource.class)
.register(TileResource.class)
.register(StyleResource.class)
.register(TilesetResource.class)
.register(ChangeResource.class)
.register(ClassPathResource.class)
.register(newContextResolver(objectMapper))
.register(new AbstractBinder() {
@Override
protected void configure() {
bind("assets").to(String.class).named("directory");
bind("viewer.html").to(String.class).named("index");
bind(tilesetPath).to(Path.class).named("tileset");
bind(stylePath).to(Path.class).named("style");
bind(tileStoreSupplier).to(tileStoreType);
bind(styleSupplier).to(styleSupplierType);
bind(tileJSONSupplier).to(tileJSONSupplierType);
}
});
var httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
var serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
logger.info("Listening on {}", serverContext.listenAddress());
serverContext.awaitShutdown();
return 0;
}