Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Externalizer returning wrong host name

Avatar

Level 4

Hi,

I have externalizer configuration in AEM for publish as publish http://www.a.com. We have also many subdomains under a.com as b.a.com or c.a.com. We use mappings for both websites and its sub domains.

When i am trying to do externalizer.publishLink(resourceResolver, url) i am getting b.a.com instead of a.com. Everything looks correct with externalizer configuration. If i remove b.a.com mappings from map.local.publish then i am getting a.com as value. I am not sure why this is happening.

My assumption is when i do externalizer.publishLink then it goes to OSGI configuration and get the value present behind "publish". I am not sure from where subdomain host name is showing up.

Any thoughts are welcome.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

As long you have correct config deployed to your instance, externalizer code work fine. You may want to ensure that configs in felix are deployed properly,

Also try using this externalizer.externalLink(resolver, "mydomain", "/my/page") for any custom domain

View solution in original post

3 Replies

Avatar

Level 10

Your understanding is correct, it picks the osgi config in front of publish.

Can you share your externalizer configs?

Avatar

Level 4

Hi,

Below are the configs present in the externalizer OSGI configuration.

local https://localhost:5433

author http://author.a.com

publish http://www.a.com

mobile http://www.a.com

Technically, it should pick up link beside publish, but it is not picking up this.

Below is the code i have written for extracting link

package com.a.com.app;

import com.day.cq.commons.Externalizer;

import org.apache.sling.api.SlingHttpServletRequest;

import org.apache.sling.models.annotations.DefaultInjectionStrategy;

import org.apache.sling.models.annotations.Model;

import org.apache.sling.models.annotations.injectorspecific.OSGiService;

import org.apache.sling.models.annotations.injectorspecific.Self;

import javax.annotation.PostConstruct;

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

public class component {

   @Self
   SlingHttpServletRequest request;

   @OSGiService
   Externalizer externalizer;

   private String externalizedPath;

   private static final String LOCATION = "/location";

   @PostConstruct
   protected void init() {

  setExternalizedPath(externalizer.publishLink(request.getResourceResolver(), LOCATION));

  }

   public String getExternalizedPath() {

   return externalizedPath;

  }

   public void setExternalizedPath(String externalizedPath) {

   this.externalizedPath = externalizedPath;

  }

}

The output should be "http://www.a.com/location" but instead i am getting "http://b.a.com/location"

Thanks for any help

Avatar

Correct answer by
Level 10

As long you have correct config deployed to your instance, externalizer code work fine. You may want to ensure that configs in felix are deployed properly,

Also try using this externalizer.externalLink(resolver, "mydomain", "/my/page") for any custom domain