Iam implementing Dropwizard client in a Dropwizard REST Application. I am following their User Manual.

While trying to register the client to jersey environment but cannot find the class ExternalServiceResource

@Override
public void run(ExampleConfiguration config,
            Environment environment) {
final HttpClient httpClient = new HttpClientBuilder(environment).using(config.getHttpClientConfiguration())
                                                                .build();
environment.jersey().register(new ExternalServiceResource(httpClient));
}
1

There are 1 best solutions below

1
On

I think that ExternalServiceResource was an example but it would look like:

@Path("/your/path")
public class ExternalServiceResource {

    private final HttpClient client;

    public ExternalServiceResource(HttpClient client) {
        this.client = client;
    }

    @GET
    public String doStuff() {
        return /* use client to make some call */;
    }
}

You can put whatever name you want. The only requirement to create a resource is the @Path annotation, that you must put at class level, and some methods @GET, @POST...