Resource.builder() - Resource not registered?

566 views
Skip to first unread message

Carlos Estrada

unread,
Sep 30, 2015, 7:40:15 AM9/30/15
to dropwizard-user
Hi,

I would like to programatic create the API resources as in https://jersey.java.net/documentation/latest/resource-builder.html
I'm using DW 0.8.4.

but it does not get registered? I have try with both
environment.jersey().register() and environment.jersey().getResourceConfig().registerResources
 
This is my simple code:
@Override
public void run(ApplicationConfiguration applicationConfiguration, Environment environment) throws Exception {
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());
environment.jersey().getResourceConfig().registerResources(resourceBuilder.build());
}


This is th eoutput when I start DW:
INFO  [2015-09-30 11:31:08,757] io.dropwizard.jersey.DropwizardResourceConfig: The following paths were found for the configured resources:

    NONE

INFO  [2015-09-30 11:31:08,759] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@585c13de{/,null,AVAILABLE}
INFO  [2015-09-30 11:31:08,781] io.dropwizard.setup.AdminEnvironment: tasks =

    POST    /tasks/log-level (io.dropwizard.servlets.tasks.LogConfigurationTask)
    POST    /tasks/gc (io.dropwizard.servlets.tasks.GarbageCollectionTask)


Koen Roevens

unread,
Oct 15, 2015, 8:40:31 AM10/15/15
to dropwizard-user
Hi, 

Option 2:  environment.jersey().getResourceConfig().registerResources(resourceBuilder.build());
is working.

But since we're bypassing Dropwizard by directly calling the registerResources method on Jersey's ResourceConfig class, DropWizard does not have the chance to log the registered resource.
(But you can do this in your own code) 

Carlos Estrada

unread,
Oct 17, 2015, 8:06:48 AM10/17/15
to dropwizard-user
Hi,

Yes, as you say, the resource is registered but is not log. Did not notice that :-(

/C
Reply all
Reply to author
Forward
0 new messages