开发者

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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜