programmatically get base url from inside google app engine endpoint method

65 views
Skip to first unread message

Katedral Pillon via StackOverflow

unread,
Apr 22, 2014, 7:32:19 AM4/22/14
to google-appengin...@googlegroups.com

I am creating a Google Appengine endpoint api. In one of the endpoint methods, I need to detect the base url. How might I do that in Java?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/23218228/programmatically-get-base-url-from-inside-google-app-engine-endpoint-method

Romin via StackOverflow

unread,
Apr 22, 2014, 11:37:29 AM4/22/14
to google-appengin...@googlegroups.com

As per the documentation, you can pass an injected type into your API Methods. For e.g. you could inject the HTTPServletRequest object into your API Method. https://developers.google.com/appengine/docs/java/endpoints/paramreturn_types#injected_types

Once you have the Request object, you can then get the base url as needed. For e.g.

StringBuffer url = req.getRequestURL();
String uri = req.getRequestURI();
String ctx = req.getContextPath();
String base = url.substring(0, url.length() - uri.length() + ctx.length()) + "/";


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/23218228/programmatically-get-base-url-from-inside-google-app-engine-endpoint-method/23223988#23223988
Reply all
Reply to author
Forward
0 new messages