Samuel Raghunath
Samuel Raghunath

Reputation: 155

Dropwizard Programmatic Endpoints

I am looking to programmatically create endpoints for dropwizard. Such is available via jersey as can be seen here.

Any Idea how to do this? Here is some example code I have tried, that has NOT worked:

Resource.Builder resourceBuilder = Resource.builder();

    resourceBuilder.path("helloworld");
    ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod("GET");
    methodBuilder.produces(MediaType.APPLICATION_JSON).handledBy(new Inflector<ContainerRequestContext, Object>() {
        @Override
        public Object apply(ContainerRequestContext containerRequestContext) {
            return "HELLO";
        }
    });

    environment.jersey().register(resourceBuilder.build());

Upvotes: 0

Views: 968

Answers (1)

Patrick Eigenmann
Patrick Eigenmann

Reputation: 11

I had the same problem.

When I register the resource in the ResourceConfig, it works.

Resource.Builder resourceBuilder = Resource.builder();
 resourceBuilder.path("helloworld");
 ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod("GET");
 methodBuilder.produces(MediaType.APPLICATION_JSON).handledBy(new Inflector<ContainerRequestContext, Object>() {
        @Override
        public Object apply(ContainerRequestContext containerRequestContext) {
            return "HELLO";
        }
    });
environment.jersey().getResourceConfig().registerResources(resource);

Upvotes: 1

Related Questions