Skip to content

Commit

Permalink
Finally get dropwizard 4.0.7 working
Browse files Browse the repository at this point in the history
  • Loading branch information
ratrun committed Aug 1, 2024
1 parent 856fddc commit 0d3be2c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.graphhopper.http;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.graphhopper.jackson.Gpx;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.ext.Provider;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyReader;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.io.IOException;

@Provider
@Consumes({"application/gpx+xml", "application/xml"})
public class GpxMessageBodyReader implements MessageBodyReader<Gpx> {
final private XmlMapper xmlMapper = new XmlMapper();
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type == Gpx.class;
}

@Override
public Gpx readFrom(Class<Gpx> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException
{
return xmlMapper.readValue(entityStream, Gpx.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.graphhopper.application.cli.MatchCommand;
import com.graphhopper.application.resources.RootResource;
import com.graphhopper.http.CORSFilter;
import com.graphhopper.http.GpxMessageBodyReader;
import com.graphhopper.http.GraphHopperBundle;
import com.graphhopper.http.RealtimeBundle;
import com.graphhopper.navigation.NavigateResource;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void initialize(Bootstrap<GraphHopperServerConfiguration> bootstrap) {
public void run(GraphHopperServerConfiguration configuration, Environment environment) {
environment.jersey().register(new RootResource());
environment.jersey().register(NavigateResource.class);
environment.jersey().register(GpxMessageBodyReader.class);
environment.servlets().addFilter("cors", CORSFilter.class).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "*");
}
}

0 comments on commit 0d3be2c

Please sign in to comment.