It's possible to register multiple resources that have the same path. 
However, only one of them will actually be exposed through the API. 

Example: In the dropwizard example project 
<https://github.com/dropwizard/dropwizard/tree/master/dropwizard-example>, 
ProtectedResource and ProtectedClassResource share the same paths. 
Currently, only ProtectedResource is registered in 
HelloWorldApplication::run. When ProtectedClassResource is registered as 
well, DropwizardResourceConfig will tell you that these paths were 
configured:

    GET     /protected (com.example.helloworld.resources.ProtectedResource)
    GET     /protected/admin 
(com.example.helloworld.resources.ProtectedResource)
    GET     /protected/guest 
(com.example.helloworld.resources.ProtectedClassResource)

In larger projects, it's easy to accidentally define a resource with a path 
that is already taken by another resource. Of course this kind of error can 
be avoided with integration tests (at least to some degree). However, it 
would be nice to have a validator that complains about such conflicts at 
compile time. I'm guessing that such a validator already exists, so maybe 
you can point me in the right direction?

I added integration tests that exemplify this problem to the example 
application 
<https://github.com/florian-f/dropwizard/blob/master/dropwizard-example/src/test/java/com/example/helloworld/IntegrationTest.java>.
 
Another issue that I noticed while doing so is that even though /protected 
is supposedly associated with ProtectedResource, the corresponding 
IntegrationTest::testProtectedEndpoint fails - and debugging with a 
breakpoint in ProtectedResource::showSecret revealed that the method is 
never called. Instead, ProtectedClassResource::showSecret is called, 
despite DropwizardResourceConfig telling you otherwise. I'm not sure if 
this is a bug or if I missed something, so it would be nice if someone else 
could weigh in on this.

Best,
Florian

  


-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to