1

I'm trying to check callers to a method in Google Cloud Endpoint against a whitelist. How to get the remote address of a client? (And how to get the request object?)

UPDATE: Thanks to @ikerlasaga:

@ApiMethod(name = "echo")
public Message echo(HttpServletRequest req, Message message, @Named("n") @Nullable Integer n) {

  String remote = req.getRemoteAddr();

  return doEcho(message, n);
}
uan
  • 857
  • 7
  • 17
  • This post is quite old, but I think its solution could work https://stackoverflow.com/questions/15056830/getting-raw-http-data-headers-cookies-etc-in-google-cloud-endpoints – iker lasaga Oct 07 '19 at 09:59
  • I'm glad to know that it worked. However, could you post an answer instead of editing the question? that will help the community to see the answer. – iker lasaga Oct 09 '19 at 13:37

1 Answers1

1

From this post: Getting raw HTTP Data (Headers, Cookies, etc) in Google Cloud Endpoints

@ApiMethod(name = "echo")
public Message echo(HttpServletRequest req, Message message, @Named("n") @Nullable Integer n) {

  String remote = req.getRemoteAddr();

  return doEcho(message, n);
}

Thanks to @ikerlasaga

uan
  • 857
  • 7
  • 17