Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropwizard Path: Get all paths in app

Does anyone know how to get the same information, about what paths are used, like at the start of dw application. I mean the output after this line:

io.dropwizard.jersey.DropwizardResourceConfig: The following paths were found for the configured resources:
GET     /path/of/res/test (this.is.the.class.package.info.MyRessource)
POST     /path/of/res/test2 (this.is.the.class.package.info.MyRessource2)

I have to check if specific path exists.

like image 542
user3280180 Avatar asked Oct 10 '14 10:10

user3280180


People also ask

Does Dropwizard use Jetty?

Because you can't be a web application without HTTP, Dropwizard uses the Jetty HTTP library to embed an incredibly tuned HTTP server directly into your project.

Does Dropwizard use Log4j?

Dropwizard uses Logback for its logging backend. It provides an slf4j implementation, and even routes all java. util. logging , Log4j, and Apache Commons Logging usage through Logback.

What is bootstrap in Dropwizard?

Bootstrap is the pre-start (temp) application environment, containing everything required to bootstrap a Dropwizard command. Here is a simplified code snippet to illustrate its structure: Bootstrap(application: Application<T>) { this. application = application; this. objectMapper = Jackson.


1 Answers

You'll have to do this on your own. Take a look at the logEndpoints method (which is what actually logs this information - with private methods). You should be able to adapt this method to handle the resources from your environment.jersey().getResourceConfig() after you configure your resources in your run method.

Something like:

final ImmutableList.Builder<Class<?>> builder = ImmutableList.builder();
for (Object o : environment.jersey().getResourceConfig().getSingletons()) {
  if (o.getClass().isAnnotationPresent(Path.class)) {
    builder.add(o.getClass());
  }
}
for (Class<?> klass : environment.jersey().getResourceConfig().getClasses()) {
  if (klass.isAnnotationPresent(Path.class)) {
    builder.add(klass);
  }
}
final List<String> endpoints = Lists.newArrayList();
for (Class<?> klass : builder.build()) {
  AbstractResource resource = IntrospectionModeller.createResource(klass);
  endpoints.add(resource.getPath().getValue());
}

Note that what's in master is slightly ahead of what's in Maven - the above example shows how to get the AbstractResource which will work with 0.7.1. You'll have to be sure to adapt your method as dropwizard evolves. This example also doesn't normalize the path but I you can easily add that based on logEndpoints.

like image 189
condit Avatar answered Oct 07 '22 09:10

condit