You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by Heather Sterling <hs...@gmail.com> on 2013/09/24 22:37:20 UTC

resource path matching question

Hi,

I have two wink applications that are registered via the ApplicationPath
annotation.  They are located at myapp/api/* and myapp/test/*.  The reason
I am using two distinct applications is that one is packaged as a test
library that is optionally deployed with the war file.

I have two resources, ServerResource and TestServerResource that are both
given the same path "origins" but declared in their respective
applications.  The reason for this is that the methods that are public API
differ from some test methods we exposed.  So we have two distinct URIs
which should resolve to two different resources.

myapp/api/servers:

@Path("/servers")
public class ServerResource {

    //delete single server
    @DELETE
    @Path("{serverId}")
    public Response deleteOrigin(@PathParam("serverId") String serverId)

myapp/test/servers:

@Path("/servers")
public class TestServerResource {

    //delete all servers
    @DELETE
    public void deleteAllServers()

I was seeing intermittent 405 errors that I couldn't explain.  I enabled
wink tracing and tracked it down to the FindRootResourceHandler matching
the wrong resource.  A request to DELETE (no param) to mypass/test/servers
was matched to ServerResource instead of TestServerResource.  Thus, the 405
was correct because ServerResource does not have a DELETE all method.  In
matching the URIs, it appears that the application path "api" or "test" is
stripped off and thus both resources are registered under "servers" even
though they are defined in different applications.  According to the
specification, only one match is returned.  I think that I can override
this behavior with wink.continuedSearch config property, but the ambiguity
is error-prone.

The behavior is entirely dependent on the order in which resources are
registered.  Because I am doing it dynamically via annotation and not
through the web.xml, the order changes across restarts.  If
TestServerResource is registered before ServerResource, the DELETE all call
works.  If it's the other way around, it gets routed to the wrong guy and I
get a 405.

I consulted the JAX-RS spec on path-matching and I cannot find anything
that talks about stripping off the application path.  Is this behaving
as-designed or have I found a bug?

Thanks,
Heather S