How to route JAX-RS request conditionally, depending on the suffix?
This is what I'm trying to do:
@Path("/finder")
public class Finder {
@Path("/{name}")
public Proxy find(@PathParam("name") String name) {
Object found = /* some object found by name */
return new Proxy(found);
}
}
public class Proxy {
private Object obj;
public Proxy(Object found) {
this.obj = found;
}
@GET
@Path("/")
public String info() {
return /* some meta-information about the object */
}
@Path("/")
public Object passthru() {
return this.obj;
}
}
I'm trying to enable:
GET /finder/alpha -> Proxy.info()
GET 开发者_如何学运维/finder/alpha/something -> obj.something()
Am I going the right way? Meanwhile, Jersey says:
WARNING: A sub-resource method, public final java.lang.String com.XXX.Proxy.info(),
with URI template, "/", is treated as a resource method
Everything is fine with the code above except that I don't need @Path("/")
annotation at info()
.
精彩评论