简体   繁体   English

如何根据后缀有条件地路由JAX-RS请求?

[英]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

除了我在info()不需要@Path("/")注释外,上面的代码一切都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM