2016-09-26 92 views
0

我有一個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://stackoverflow.com/questions/5118752/how-do-i-access-the-http-request? – numX

回答

0

可以注入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