0

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

Helmut Granda
  • 4,565
  • 7
  • 35
  • 51
  • Java or JavaScript? They are completely different languages, related only by a crazy marketing idea from the 90s. – Quentin Jun 11 '15 at 15:21
  • JavaScript, the Java reference is to what is available to Sightly through Java global objects. - What marketing idea you speak of? :) – Helmut Granda Jun 11 '15 at 15:26
  • Paraphrasing: "What shall we call our web language?" "Sun's got their new web language called Java and it is getting a lot of publicity" "Let's license the name" – Quentin Jun 11 '15 at 15:30

1 Answers1

2

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(), "/");
d33t
  • 1,143
  • 6
  • 15
  • Thanks @d33t, this definitely got me in the right track. In "request.getServerName()" got me what I need through the server side. I need to know the host before resolving the image paths to our components, our localhost environments are missing some features that our dev environments and this helps me make a check before rendering the right content. – Helmut Granda Jun 12 '15 at 16:56