AEM ServerSide JavaScript host

1.5k views Asked by At

I am trying to find the current host of my application in order to make some implementations, I went through different Java Backend objects (resource, request, resourcePage..) but all the properties that I have found give me relative paths. What is the best way to get the host where the call was initiated?

Here is a list of global objects that I have been looking through: http://docs.adobe.com/docs/en/aem/6-0/develop/sightly/global-objects.html

1

There are 1 answers

1
d33t On BEST ANSWER

I'm little bit confused if you try to resolve the host through java or javascript, that's why I'll post both of the solutions. If you mean something else than please extend your question or create new one.

Javascript:

window.location.hostname

Java:

org.apache.sling.api.SlingHttpServletRequest request = ...; // you have instance of the request if you are in a context of a servlet
String domain = request.getRemoteHost() // e.g. stackoverflow.com

or if you try to resolve some resource url in Java, you can use the com.day.cq.commons.Externalizer which can be adapted from the org.apache.sling.api.resource.ResourceResolver and uses the settings in your map file /etc/map

Externalizer externalizer = resourceResolver.adaptTo(Externalizer.class);
externalizer.externalLink(resourceResolver, Externalizer.PUBLISH, getRequest().getScheme(), "/");