How to route JAX-RS request conditionally, depending on the suffix?

走远了吗. 提交于 2019-12-11 20:14:27

问题


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

回答1:


Everything is fine with the code above except that I don't need @Path("/") annotation at info().



来源:https://stackoverflow.com/questions/4276882/how-to-route-jax-rs-request-conditionally-depending-on-the-suffix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!