Restful Java中的呼叫者URL

问题描述:

我有一个Restful post方法可以解答任何客户端。当被调用时,它会运行一个标准查询并将结果返回给调用者 - 无论是谁。Restful Java中的呼叫者URL

我正在寻找以此方法记录调用者URL。如何获取来电者的网址?

下面是概括地说(除去错误/边缘条件)的方法:

@POST 
public static Response makeQuery() { 
     return Response.ok(query()).build(); // invoke query() and hand in the result 
} 
+0

duplicate http://*.com/questions/5118752/how-do-i-access-the-http-request? – numX

可以注入UriInfo对象和检查请求URL包括PARAMS。

@POST 
public static Response makeQuery(@Context UriInfo uriInfo) { 
     System.out.println(uriInfo.getAbsolutePath()); 
     return Response.ok(query()).build(); // invoke query() and hand in the result 
} 
+0

看起来不服从它。将检查出来。 – user6762070