From e954f0085f4ce489dc6dc91e0cf24ce05b3e6cba Mon Sep 17 00:00:00 2001 From: Michael Zilske Date: Wed, 20 Jun 2018 10:30:43 +0200 Subject: [PATCH] Exception Mapping (#1390) * Exception Mapping * Don't even need to create the Writer myself, even better. * Put "activation" back in. fixes #1388 * Rename filter so it resembles the actual query param * ...and the code comment * License headers --- .../java/com/graphhopper/MultiException.java | 40 +++++++ .../jackson/GraphHopperModule.java | 2 + .../jackson/MultiExceptionSerializer.java | 59 ++++++++++ .../graphhopper/http/GraphHopperBundle.java | 9 +- .../MultiExceptionGPXMessageBodyWriter.java | 99 +++++++++++++++++ .../http/MultiExceptionMapper.java | 33 ++++++ .../com/graphhopper/http/TypeGPXFilter.java | 40 +++++++ .../graphhopper/resources/RouteResource.java | 104 +++--------------- web/pom.xml | 5 + .../http/GraphHopperApplication.java | 14 --- 10 files changed, 299 insertions(+), 106 deletions(-) create mode 100644 web-api/src/main/java/com/graphhopper/MultiException.java create mode 100644 web-api/src/main/java/com/graphhopper/jackson/MultiExceptionSerializer.java create mode 100644 web-bundle/src/main/java/com/graphhopper/http/MultiExceptionGPXMessageBodyWriter.java create mode 100644 web-bundle/src/main/java/com/graphhopper/http/MultiExceptionMapper.java create mode 100644 web-bundle/src/main/java/com/graphhopper/http/TypeGPXFilter.java diff --git a/web-api/src/main/java/com/graphhopper/MultiException.java b/web-api/src/main/java/com/graphhopper/MultiException.java new file mode 100644 index 00000000000..6b59ce982e0 --- /dev/null +++ b/web-api/src/main/java/com/graphhopper/MultiException.java @@ -0,0 +1,40 @@ +/* + * Licensed to GraphHopper GmbH under one or more contributor + * license agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * GraphHopper GmbH licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.graphhopper; + +import java.util.Collections; +import java.util.List; + +public class MultiException extends RuntimeException { + + private final List errors; + + public MultiException(List errors) { + this.errors = errors; + } + + public MultiException(Throwable e) { + this(Collections.singletonList(e)); + } + + public List getErrors() { + return errors; + } + +} diff --git a/web-api/src/main/java/com/graphhopper/jackson/GraphHopperModule.java b/web-api/src/main/java/com/graphhopper/jackson/GraphHopperModule.java index ac45eeb1ec9..c26a46e2709 100644 --- a/web-api/src/main/java/com/graphhopper/jackson/GraphHopperModule.java +++ b/web-api/src/main/java/com/graphhopper/jackson/GraphHopperModule.java @@ -1,6 +1,7 @@ package com.graphhopper.jackson; import com.fasterxml.jackson.databind.module.SimpleModule; +import com.graphhopper.MultiException; import com.graphhopper.util.CmdArgs; import com.graphhopper.util.InstructionList; import com.graphhopper.util.details.PathDetail; @@ -18,6 +19,7 @@ public GraphHopperModule() { addSerializer(PathDetail.class, new PathDetailSerializer()); addSerializer(InstructionList.class, new InstructionListSerializer()); addDeserializer(CmdArgs.class, new CmdArgsDeserializer()); + addSerializer(MultiException.class, new MultiExceptionSerializer()); } } diff --git a/web-api/src/main/java/com/graphhopper/jackson/MultiExceptionSerializer.java b/web-api/src/main/java/com/graphhopper/jackson/MultiExceptionSerializer.java new file mode 100644 index 00000000000..b7798eb9a8f --- /dev/null +++ b/web-api/src/main/java/com/graphhopper/jackson/MultiExceptionSerializer.java @@ -0,0 +1,59 @@ +/* + * Licensed to GraphHopper GmbH under one or more contributor + * license agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * GraphHopper GmbH licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.graphhopper.jackson; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.graphhopper.MultiException; +import com.graphhopper.util.exceptions.GHException; + +import java.io.IOException; +import java.util.List; + +public class MultiExceptionSerializer extends JsonSerializer { + + @Override + public void serialize(MultiException e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + List errors = e.getErrors(); + ObjectNode json = JsonNodeFactory.instance.objectNode(); + json.put("message", getMessage(errors.get(0))); + ArrayNode errorHintList = json.putArray("hints"); + for (Throwable t : errors) { + ObjectNode error = errorHintList.addObject(); + error.put("message", getMessage(t)); + error.put("details", t.getClass().getName()); + if (t instanceof GHException) { + ((GHException) t).getDetails().forEach(error::putPOJO); + } + } + jsonGenerator.writeObject(json); + } + + private static String getMessage(Throwable t) { + if (t.getMessage() == null) + return t.getClass().getSimpleName(); + else + return t.getMessage(); + } + +} diff --git a/web-bundle/src/main/java/com/graphhopper/http/GraphHopperBundle.java b/web-bundle/src/main/java/com/graphhopper/http/GraphHopperBundle.java index e59e6ed75e1..104eb36631a 100644 --- a/web-bundle/src/main/java/com/graphhopper/http/GraphHopperBundle.java +++ b/web-bundle/src/main/java/com/graphhopper/http/GraphHopperBundle.java @@ -183,6 +183,14 @@ public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider public void run(GraphHopperBundleConfiguration configuration, Environment environment) { configuration.getGraphHopperConfiguration().merge(CmdArgs.readFromSystemProperties()); + // If the "?type=gpx" parameter is present, sets a corresponding media type header + environment.jersey().register(new TypeGPXFilter()); + + // Together, these two take care that MultiExceptions thrown from RouteResource + // come out as JSON or GPX, depending on the media type + environment.jersey().register(new MultiExceptionMapper()); + environment.jersey().register(new MultiExceptionGPXMessageBodyWriter()); + if (configuration.getGraphHopperConfiguration().has("gtfs.file")) { // switch to different API implementation when using Pt runPtGraphHopper(configuration.getGraphHopperConfiguration(), environment); @@ -263,7 +271,6 @@ protected void configure() { environment.jersey().register(IsochroneResource.class); environment.jersey().register(I18NResource.class); environment.jersey().register(InfoResource.class); - environment.healthChecks().register("graphhopper", new GraphHopperHealthCheck(graphHopperManaged.getGraphHopper())); } diff --git a/web-bundle/src/main/java/com/graphhopper/http/MultiExceptionGPXMessageBodyWriter.java b/web-bundle/src/main/java/com/graphhopper/http/MultiExceptionGPXMessageBodyWriter.java new file mode 100644 index 00000000000..2f53c12107b --- /dev/null +++ b/web-bundle/src/main/java/com/graphhopper/http/MultiExceptionGPXMessageBodyWriter.java @@ -0,0 +1,99 @@ +/* + * Licensed to GraphHopper GmbH under one or more contributor + * license agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * GraphHopper GmbH licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.graphhopper.http; + +import com.graphhopper.MultiException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +@Provider +@Produces("application/gpx+xml") +public class MultiExceptionGPXMessageBodyWriter implements MessageBodyWriter { + + @Override + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return true; + } + + @Override + public long getSize(MultiException e, Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return -1; + } + + @Override + public void writeTo(MultiException e, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { + if (e.getErrors().isEmpty()) + throw new RuntimeException("errorsToXML should not be called with an empty list"); + + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.newDocument(); + Element gpxElement = doc.createElement("gpx"); + gpxElement.setAttribute("creator", "GraphHopper"); + gpxElement.setAttribute("version", "1.1"); + doc.appendChild(gpxElement); + + Element mdElement = doc.createElement("metadata"); + gpxElement.appendChild(mdElement); + + Element extensionsElement = doc.createElement("extensions"); + mdElement.appendChild(extensionsElement); + + Element messageElement = doc.createElement("message"); + extensionsElement.appendChild(messageElement); + messageElement.setTextContent(e.getErrors().iterator().next().getMessage()); + + Element hintsElement = doc.createElement("hints"); + extensionsElement.appendChild(hintsElement); + + for (Throwable t : e.getErrors()) { + Element error = doc.createElement("error"); + hintsElement.appendChild(error); + error.setAttribute("message", t.getMessage()); + error.setAttribute("details", t.getClass().getName()); + } + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.transform(new DOMSource(doc), new StreamResult(entityStream)); + } catch (ParserConfigurationException | TransformerException e2) { + throw new RuntimeException(e2); + } + + } +} diff --git a/web-bundle/src/main/java/com/graphhopper/http/MultiExceptionMapper.java b/web-bundle/src/main/java/com/graphhopper/http/MultiExceptionMapper.java new file mode 100644 index 00000000000..237daee611c --- /dev/null +++ b/web-bundle/src/main/java/com/graphhopper/http/MultiExceptionMapper.java @@ -0,0 +1,33 @@ +/* + * Licensed to GraphHopper GmbH under one or more contributor + * license agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * GraphHopper GmbH licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.graphhopper.http; + +import com.graphhopper.MultiException; + +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +@Provider +public class MultiExceptionMapper implements ExceptionMapper { + @Override + public Response toResponse(MultiException exception) { + return Response.status(400).entity(exception).build(); + } +} diff --git a/web-bundle/src/main/java/com/graphhopper/http/TypeGPXFilter.java b/web-bundle/src/main/java/com/graphhopper/http/TypeGPXFilter.java new file mode 100644 index 00000000000..7c38043c3df --- /dev/null +++ b/web-bundle/src/main/java/com/graphhopper/http/TypeGPXFilter.java @@ -0,0 +1,40 @@ +/* + * Licensed to GraphHopper GmbH under one or more contributor + * license agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * GraphHopper GmbH licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.graphhopper.http; + +import javax.annotation.Priority; +import javax.ws.rs.Priorities; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.container.PreMatching; +import javax.ws.rs.core.HttpHeaders; + +@PreMatching +@Priority(Priorities.HEADER_DECORATOR) +public class TypeGPXFilter implements ContainerRequestFilter { + + @Override + public void filter(ContainerRequestContext rc) { + String maybeType = rc.getUriInfo().getQueryParameters().getFirst("type"); + if (maybeType != null && maybeType.equals("gpx")) { + rc.getHeaders().putSingle(HttpHeaders.ACCEPT, "application/gpx+xml"); + } + } + +} diff --git a/web-bundle/src/main/java/com/graphhopper/resources/RouteResource.java b/web-bundle/src/main/java/com/graphhopper/resources/RouteResource.java index 3314fa81fda..aca3bdbfcb2 100644 --- a/web-bundle/src/main/java/com/graphhopper/resources/RouteResource.java +++ b/web-bundle/src/main/java/com/graphhopper/resources/RouteResource.java @@ -17,33 +17,26 @@ */ package com.graphhopper.resources; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.graphhopper.GHRequest; import com.graphhopper.GHResponse; import com.graphhopper.GraphHopperAPI; +import com.graphhopper.MultiException; import com.graphhopper.http.WebHelper; import com.graphhopper.routing.util.EncodingManager; import com.graphhopper.routing.util.HintsMap; import com.graphhopper.util.Constants; import com.graphhopper.util.Parameters; import com.graphhopper.util.StopWatch; -import com.graphhopper.util.exceptions.GHException; import com.graphhopper.util.shapes.GHPoint; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; import javax.inject.Inject; import javax.inject.Named; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; +import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.*; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; import java.util.*; import static com.graphhopper.util.Parameters.Routing.*; @@ -76,7 +69,8 @@ public RouteResource(GraphHopperAPI graphHopper, EncodingManager encodingManager public Response doGet( @Context HttpServletRequest httpReq, @Context UriInfo uriInfo, - @QueryParam(WAY_POINT_MAX_DISTANCE) @DefaultValue("1") double minPathPrecision, + @Context ContainerRequestContext rc, + @QueryParam(WAY_POINT_MAX_DISTANCE)@DefaultValue("1") double minPathPrecision, @QueryParam("point") List requestPoints, @QueryParam("type") @DefaultValue("json") String type, @QueryParam(INSTRUCTIONS) @DefaultValue("true") boolean instructions, @@ -101,20 +95,20 @@ public Response doGet( StopWatch sw = new StopWatch().start(); if(requestPoints.isEmpty()) { - throw new WebApplicationException(errorResponse(new IllegalArgumentException("You have to pass at least one point"), writeGPX)); + throw new MultiException(new IllegalArgumentException("You have to pass at least one point")); } if (!encodingManager.supports(vehicleStr)) { - throw new WebApplicationException(errorResponse(new IllegalArgumentException("Vehicle not supported: " + vehicleStr), writeGPX)); + throw new MultiException(new IllegalArgumentException("Vehicle not supported: " + vehicleStr)); } else if (enableElevation && !hasElevation) { - throw new WebApplicationException(errorResponse(new IllegalArgumentException("Elevation not supported!"), writeGPX)); + throw new MultiException(new IllegalArgumentException("Elevation not supported!")); } else if (favoredHeadings.size() > 1 && favoredHeadings.size() != requestPoints.size()) { - throw new WebApplicationException(errorResponse(new IllegalArgumentException("The number of 'heading' parameters must be <= 1 " - + "or equal to the number of points (" + requestPoints.size() + ")"), writeGPX)); + throw new MultiException(new IllegalArgumentException("The number of 'heading' parameters must be <= 1 " + + "or equal to the number of points (" + requestPoints.size() + ")")); } if (pointHints.size() > 0 && pointHints.size() != requestPoints.size()) { - throw new WebApplicationException(errorResponse(new IllegalArgumentException("If you pass " + POINT_HINT + ", you need to pass a hint for every point, empty hints will be ignored"), writeGPX)); + throw new MultiException(new IllegalArgumentException("If you pass " + POINT_HINT + ", you need to pass a hint for every point, empty hints will be ignored")); } GHRequest request; @@ -153,7 +147,7 @@ public Response doGet( if (ghResponse.hasErrors()) { logger.error(logStr + ", errors:" + ghResponse.getErrors()); - throw new WebApplicationException(errorResponse(ghResponse.getErrors(), writeGPX)); + throw new MultiException(ghResponse.getErrors()); } else { logger.info(logStr + ", alternatives: " + ghResponse.getAll().size() + ", distance0: " + ghResponse.getBest().getDistance() @@ -173,7 +167,7 @@ public Response doGet( private static Response.ResponseBuilder gpxSuccessResponseBuilder(GHResponse ghRsp, String timeString, String trackName, boolean enableElevation, boolean withRoute, boolean withTrack, boolean withWayPoints, String version) { if (ghRsp.getAll().size() > 1) { - throw new WebApplicationException("Alternatives are currently not yet supported for GPX"); + throw new MultiException(new IllegalArgumentException("Alternatives are currently not yet supported for GPX")); } long time = timeString != null ? Long.parseLong(timeString) : System.currentTimeMillis(); @@ -181,72 +175,7 @@ private static Response.ResponseBuilder gpxSuccessResponseBuilder(GHResponse ghR header("Content-Disposition", "attachment;filename=" + "GraphHopper.gpx"); } - private static Response xmlErrorResponse(Collection list) { - if (list.isEmpty()) - throw new RuntimeException("errorsToXML should not be called with an empty list"); - - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document doc = builder.newDocument(); - Element gpxElement = doc.createElement("gpx"); - gpxElement.setAttribute("creator", "GraphHopper"); - gpxElement.setAttribute("version", "1.1"); - doc.appendChild(gpxElement); - - Element mdElement = doc.createElement("metadata"); - gpxElement.appendChild(mdElement); - - Element extensionsElement = doc.createElement("extensions"); - mdElement.appendChild(extensionsElement); - - Element messageElement = doc.createElement("message"); - extensionsElement.appendChild(messageElement); - messageElement.setTextContent(list.iterator().next().getMessage()); - - Element hintsElement = doc.createElement("hints"); - extensionsElement.appendChild(hintsElement); - - for (Throwable t : list) { - Element error = doc.createElement("error"); - hintsElement.appendChild(error); - error.setAttribute("message", t.getMessage()); - error.setAttribute("details", t.getClass().getName()); - } - return Response.status(400).entity(doc).build(); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } - } - - private static Response errorResponse(List t, boolean writeGPX) { - if (writeGPX) { - return xmlErrorResponse(t); - } else { - return jsonErrorResponse(t); - } - } - - private static Response errorResponse(Throwable t, boolean writeGPX) { - return errorResponse(Collections.singletonList(t), writeGPX); - } - - private static Response jsonErrorResponse(List errors) { - ObjectNode json = JsonNodeFactory.instance.objectNode(); - json.put("message", getMessage(errors.get(0))); - ArrayNode errorHintList = json.putArray("hints"); - for (Throwable t : errors) { - ObjectNode error = errorHintList.addObject(); - error.put("message", getMessage(t)); - error.put("details", t.getClass().getName()); - if (t instanceof GHException) { - ((GHException) t).getDetails().forEach(error::putPOJO); - } - } - return Response.status(400).entity(json).build(); - } - - public static void initHints(HintsMap m, MultivaluedMap parameterMap) { + static void initHints(HintsMap m, MultivaluedMap parameterMap) { for (Map.Entry> e : parameterMap.entrySet()) { if (e.getValue().size() == 1) { m.put(e.getKey(), e.getValue().get(0)); @@ -267,11 +196,4 @@ public static void initHints(HintsMap m, MultivaluedMap paramete } } - private static String getMessage(Throwable t) { - if (t.getMessage() == null) - return t.getClass().getSimpleName(); - else - return t.getMessage(); - } - } diff --git a/web/pom.xml b/web/pom.xml index e5685e99054..c9e48ef4b73 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -20,6 +20,11 @@ + + javax.activation + activation + 1.1.1 + io.dropwizard dropwizard-core diff --git a/web/src/main/java/com/graphhopper/http/GraphHopperApplication.java b/web/src/main/java/com/graphhopper/http/GraphHopperApplication.java index 7035bb772c2..825343644d1 100644 --- a/web/src/main/java/com/graphhopper/http/GraphHopperApplication.java +++ b/web/src/main/java/com/graphhopper/http/GraphHopperApplication.java @@ -17,19 +17,8 @@ */ package com.graphhopper.http; -import com.bedatadriven.jackson.datatype.jts.JtsModule; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.BeanDescription; -import com.fasterxml.jackson.databind.SerializationConfig; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; -import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; -import com.fasterxml.jackson.databind.util.ISO8601DateFormat; import com.graphhopper.http.cli.ImportCommand; import com.graphhopper.http.resources.RootResource; -import com.graphhopper.jackson.GraphHopperModule; import io.dropwizard.Application; import io.dropwizard.bundles.assets.ConfiguredAssetsBundle; import io.dropwizard.setup.Bootstrap; @@ -37,8 +26,6 @@ import javax.servlet.DispatcherType; import java.util.EnumSet; -import java.util.List; -import java.util.stream.Collectors; public final class GraphHopperApplication extends Application { @@ -55,7 +42,6 @@ public void initialize(Bootstrap bootstrap) { @Override public void run(GraphHopperServerConfiguration configuration, Environment environment) throws Exception { - environment.jersey().register(new RootResource()); environment.servlets().addFilter("cors", CORSFilter.class).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "*"); environment.servlets().addFilter("ipfilter", new IPFilter(configuration.getGraphHopperConfiguration().get("jetty.whiteips", ""), configuration.getGraphHopperConfiguration().get("jetty.blackips", ""))).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "*");