Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get domain name of app on Google App Engine

I have an app running on Google App Engine on domainX. This allows users to enter data, stores it and displays it.

I also want this app running on DomainY. I want to use the domain name of the 2 apps to generate a key for the DataStoreService so that data is not shared between the 2 domain names.

How do I get hold of the domain name? I know I can use HttpServletRequest to get the url on the DoPost method of one of my servlets but how do I get hold of the domain? I also need to get hold of the domain on a RemoteServiceServlet which does not have a HttpServletRequest to get the url.

Thanks

like image 245
Roaders Avatar asked Nov 23 '25 01:11

Roaders


1 Answers

You can introduce a special Filter, mapped to /*, that will get current domain from HTTP request, and store it into an request storage to reuse later.

And I suggest to use getServerName() (it's Host header), instead of URL.

For example:

class RememberDomain implements Filter {
  doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {  
    DomainHolder.getInstance().setDomain(request.getServerName());    
    chain.doFilter(request, response);
  }
  ... init and destroy
}


class DomainHolder {

  //store domain here
  pricate ThreadLocal<String> domain = new ThreadLocal<String>(); 

  DomainHolder getInstance() { ... sigleton ... }

  ... get/set domain name
}
like image 94
Igor Artamonov Avatar answered Nov 24 '25 14:11

Igor Artamonov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!