Links are not externalized while exporting experience fragment to Target

Avatar

Avatar
Give Back
Level 1
nagarjunkool
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Give Back
Boost 1
View profile

Avatar
Give Back
Level 1
nagarjunkool
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Give Back
Boost 1
View profile
nagarjunkool
Level 1

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
Affirm 50
MVP
Vaibhavi
MVP

Likes

216 likes

Total Posts

181 posts

Correct reply

61 solutions
Top badges earned
Affirm 50
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Affirm 50
MVP
Vaibhavi
MVP

Likes

216 likes

Total Posts

181 posts

Correct reply

61 solutions
Top badges earned
Affirm 50
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile
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
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile
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
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

572 likes

Total Posts

726 posts

Correct reply

239 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

572 likes

Total Posts

726 posts

Correct reply

239 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
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)