如何有条件地路由JAX-RS请求,具体取决于后缀?

时间:2010-11-25 12:08:39

标签: java jersey jax-rs

这就是我要做的事情:

@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;
  }
}

我正在尝试启用:

GET /finder/alpha -> Proxy.info()
GET /finder/alpha/something -> obj.something()

我走对了路吗?同时,泽西岛说:

WARNING: A sub-resource method, public final java.lang.String com.XXX.Proxy.info(), 
with URI template, "/", is treated as a resource method

1 个答案:

答案 0 :(得分:2)

上述代码一切正常,但我@Path("/")处不需要info()注释。