简体   繁体   中英

caller URL in Restful Java

I have a Restful post method that answers to any client. when called, it runs a standard query and returns the result to the caller-- whoever that might be.

i'm looking to log the caller URL in this method. how to get the caller URL?

following is the method in a nutshell (error/edge conditions removed):

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

You can inject UriInfo object and inspect the request URL including 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 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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