It is very easy with SmartGears:
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
...
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
String rootContext = "/"+ctx.container().configuration().infrastructure();