Hi All,
I followed the below link to externalize links while exporting experience fragments to Target
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;
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
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.
Hi @nagarjunkool,
Can you confirm if the shared custom OSGI component is active and all the references are satisfied (ResourceResolverFactory and Externalizer)
Component is Active. There is no issue with both the references
Views
Replies
Total Likes
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
@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.
Views
Replies
Total Likes
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Views
Likes
Replies