xybrek xybrek - 7 months ago 45
Java Question

In-app handling of SubDomain with GAE

How to handle subdomain in a GAE application? Is it possible that the app to distinguish from:


? using Java code? Or should this be done with my domain hosting, like GoDaddy? Or this can be done with a web framework like Spring or Restlet? Or I need to use both (GoDaddy + Spring or Restlet)?

I am using Restlet framework for my web app is it possible to do something like:

public class RootServerResource extends ServerResource {
public String represent() {
String username = getRequest().getSubDomain(); // here!
return "";

Here are my questions:

  • Is it possible for a single GAE app to handle multiple sub domains?

  • If yes, is it possible to to set GAE subdomain to be a wildcard (*)

  • Using Restlet how do I achieve to get subdomains?


From the HttpServletRequest class you can use getServerName() to know the hostname that the client requested. See the documentation here.

This question explains how to obtain the HttpServletRequest with Restlet :

You can use the utility class org.restlet.ext.servlet.ServletUtils to get to the HttpServletRequest.

Now the complete code will be :

org.restlet.Request restletRequest = getRequest();
HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);
String serverName = servletRequest.getServerName();