Expand my Community achievements bar.

SOLVED

Links are not externalized while exporting experience fragment to Target

Avatar

Level 2

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;
    }

}

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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. 

View solution in original post

9 Replies

Avatar

Community Advisor

Hi @nagarjunkool,

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

 

Avatar

Level 2

Component is Active. There is no issue with both the references

Avatar

Community Advisor
Okie, You were not able to see any logs (Debug level that you have added) from rewriteLink method?

Avatar

Level 2

As per the document reference, this service should be invoked while exporting the experience fragment to Target but it doesn't work. I am unable to trace out any thing from logs

Avatar

Correct answer by
Community Advisor

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. 

Avatar

Level 4

@Vaibhavi_J, If you can provide more details or any references would be great, i'm not able to find the 'ExtendedtransformerFactory' in OOTB API to overlay.

Avatar

Community Advisor

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

Level 2
I have validated all the permissions. It is fine.