Links are not externalized while exporting experience fragment to Target

Avatar

Avatar

nagarjunkool

Avatar

nagarjunkool

nagarjunkool

12-11-2020

Hi All,

 

I followed the below link to externalize links while exporting experience fragments to Target 

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/implementing/configuring-an...

 

I have also included the custom resource type used for experience fragment in the Sling rewriter defined in the below path /libs/experience-fragments/config/rewriter. The custom service doesn't invoke while exporting the experience fragment to target. 

 

Please share your thoughts and let me know if we have any resolution.

 

Please find the below sample used. 

 

 

(service = ExperienceFragmentLinkRewriterProvider.class)
public class GeneralExperienceFragmentLinkRewriter implements ExperienceFragmentLinkRewriterProvider {

    private static final Logger LOGGER = LoggerFactory.getLogger(GeneralExperienceFragmentLinkRewriter.class);
    
    private Externalizer externalizer;

    
    ResourceResolverFactory resourceResolverFactory;

    
    public String rewriteLink(String link, String tag, String attribute) {
        LOGGER.debug("Enter rewrite link method in GeneralExperienceFragmentLinkRewriter");
        ResourceResolver serviceResolver = null;
        String rewriteLink= link;

        if(externalizer == null) {
            // if there was an error, then we do not modify the link
            return link;
        }
        try {
            serviceResolver = getServiceResolver(resourceResolverFactory); // Getting the service resolver
            Locale locale = getLocale(serviceResolver, link); // gets the page locale
            if (locale != null) {
                String publishLocaleDomain = "publish";
                if (StringUtils.isNotEmpty(locale.getCountry())) {
                    publishLocaleDomain = "publish-" + locale.getCountry();
                }
                rewriteLink = externalizer.externalLink(serviceResolver, publishLocaleDomain, link);
            } else {
                rewriteLink = externalizer.externalLink(serviceResolver, "publish", link);
            }
            LOGGER.debug("Rewrite link in ExperienceFragmentLinkRewriter", rewriteLink);
        } catch (LoginException e) {
            LOGGER.error("Encountered login exception attempting to Rewrite Link", e);
        } finally{
            if(serviceResolver != null && serviceResolver.isLive()){
                serviceResolver.close();
            }
        }
        return rewriteLink;

    }

    
    public boolean shouldRewrite(ExperienceFragmentVariation experienceFragment) {
        LOGGER.debug("Checking if it is eligible for rewrite");
        return experienceFragment.getPath().equals("/content/experience-fragments/general/");
    }

    
    public int getPriority() {
        return 0;
    }

}

 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Vaibhavi

MVP

Avatar

Vaibhavi

MVP

Vaibhavi
MVP

17-11-2020

Hi @nagarjunkool , 

 

You need to invoke above function when you are exporting a fragment. You should overlay a rewriter config and call custom transformer factory. 

 

To give more information, on click of 'export to target' ExtendedtransformerFactory (OOTB)will be called with a selector call 'atOffer'. 

Overlay a above transformer and call the externalizer method in overlayed transformer. That should work. 

Answers (2)

Answers (2)

Avatar

Avatar

Ankur_Khare

MVP

Avatar

Ankur_Khare

MVP

Ankur_Khare
MVP

17-11-2020

I hope you created system user to get a resource resolver through a service user see Service Users in AEM.

And that system user have relevant access.

 

Check logs when you hit the target url.

Avatar

Avatar

Vijayalakshmi_S

MVP

Avatar

Vijayalakshmi_S

MVP

Vijayalakshmi_S
MVP

16-11-2020

Hi @nagarjunkool,

Can you confirm if the shared custom OSGI component is active and all the references are satisfied (ResourceResolverFactory and Externalizer)