Skip to content

Commit

Permalink
Adapt geocoder and iploc command
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Jun 17, 2023
1 parent 4d7ff05 commit e299868
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import org.apache.baremaps.server.ClassPathResource;
import org.apache.baremaps.server.CorsFilter;
import org.apache.baremaps.server.GeocoderResource;
import org.apache.lucene.search.SearcherFactory;
Expand Down Expand Up @@ -51,11 +52,16 @@ public Integer call() throws Exception {
try (
var directory = MMapDirectory.open(indexDirectory);
var searcherManager = new SearcherManager(directory, new SearcherFactory())) {
// Configure the application
var application = new ResourceConfig().register(CorsFilter.class)
.register(GeocoderResource.class).register(new AbstractBinder() {

var application = new ResourceConfig()
.register(CorsFilter.class)
.register(GeocoderResource.class)
.register(ClassPathResource.class)
.register(new AbstractBinder() {
@Override
protected void configure() {
bind("geocoder").to(String.class).named("directory");
bind("index.html").to(String.class).named("index");
bind(searcherManager).to(SearcherManager.class).named("searcherManager");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.Callable;
import javax.sql.DataSource;
import org.apache.baremaps.iploc.IpLocRepository;
import org.apache.baremaps.server.ClassPathResource;
import org.apache.baremaps.server.CorsFilter;
import org.apache.baremaps.server.IpLocResource;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
Expand Down Expand Up @@ -56,16 +57,19 @@ public Integer call() throws Exception {
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
// config.setReadOnly(true);
DataSource dataSource = new HikariDataSource(config);

IpLocRepository ipLocRepository = new IpLocRepository(dataSource);

// Configure the application
var application = new ResourceConfig().register(CorsFilter.class).register(IpLocResource.class)
var application = new ResourceConfig()
.register(CorsFilter.class)
.register(IpLocResource.class)
.register(ClassPathResource.class)
.register(new AbstractBinder() {
@Override
protected void configure() {
bind("iploc").to(String.class).named("directory");
bind("index.html").to(String.class).named("index");
bind(ipLocRepository).to(IpLocRepository.class).named("iplocRepository");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ public Integer call() throws Exception {
.register(new AbstractBinder() {
@Override
protected void configure() {
bind(tilesetPath).to(Path.class).named("tileset");
bind(stylePath).to(Path.class).named("style");
bind("assets").to(String.class).named("directory");
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.nio.file.*;
import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -104,8 +105,9 @@ public void run() {
}
key.reset();
}
} catch (Exception e) {
logger.error("Error while watching for changes", e);
} catch (InterruptedException | IOException e) {
logger.error(e.getMessage());
Thread.currentThread().interrupt();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -94,19 +93,4 @@ private GeocoderResult asResult(IndexSearcher indexSearcher, ScoreDoc scoreDoc)
throw new RuntimeException(e);
}
}

@GET
@javax.ws.rs.Path("/{path:.*}")
public Response get(@PathParam("path") String path) {
if (path.equals("") || path.endsWith("/")) {
path += "index.html";
}
path = String.format("geocoder/%s", path);
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path)) {
var bytes = inputStream.readAllBytes();
return Response.ok().entity(bytes).build();
} catch (NullPointerException | IOException e) {
return Response.status(404).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
import com.google.common.net.InetAddresses;
import io.servicetalk.http.api.StreamingHttpRequest;
import io.servicetalk.transport.api.ConnectionContext;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.*;
import org.apache.baremaps.iploc.IpLocObject;
Expand Down Expand Up @@ -99,21 +96,6 @@ public Response iploc(
}
}

@GET
@javax.ws.rs.Path("/{path:.*}")
public Response get(@PathParam("path") String path) {
if (path.equals("") || path.endsWith("/")) {
path += "index.html";
}
path = String.format("iploc/%s", path);
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path)) {
var bytes = inputStream.readAllBytes();
return Response.ok().entity(bytes).build();
} catch (NullPointerException | IOException e) {
return Response.status(404).build();
}
}

public record InetnumLocationDto(
String address,
String inetStart,
Expand Down

0 comments on commit e299868

Please sign in to comment.