Url Shortning | Community
Skip to main content
lavishvasuja
Level 3
May 13, 2023
Solved

Url Shortning

  • May 13, 2023
  • 4 replies
  • 7721 views

Hello All,

 

I am working on a project that has multiple websites(AEM Cloud). I am implementing URL shortening and have created a LinkTransformImpl file for this purpose.

 

In my implementation, I am iterating over the attributes of an href tag and checking for the presence of a linkTransform attribute. For one of the websites in my project (industrial-transformation), when I print the value of attributes.getValue(i) on our dev server, it prints /language-masters/en/home.html, but on my local environment, it prints the correct path starting from /content/industrial-transformation/language-master/. For other websites in the project, it prints the correct path on both the dev server and local environment.

 

Can anyone suggest a solution to this problem?

 

 

 

if (linkTransform && Optional.ofNullable(hrefTag).isPresent()) { for (int i = 0; i < attributes.getLength(); i++) { log.info("lavishtesting "+attributes.getValue(i)+ " testinglavish"); if (HREF.equalsIgnoreCase(attributes.getQName(i))) { String value = ""; if (attributes.getValue(i).contains(CONTENT) && attributes.getValue(i).contains(CONTENT_HTML)) { value = attributes.getValue(i).replaceAll(CONTENT_HTML, ""); value = value.replace(CONTENT, "");

 

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

You have a rewrite mapping e.g. org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.xml  in dev

Example https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/ui.apps/src/main/content/jcr_root/apps/JunitApp/config.publish/org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.xml 

 

You can do resource.resolve() before adding to transformation code or remove the above config for your site/path.

4 replies

Level 3
May 13, 2023

Check on the dev server if you already have another LinkCheckerTransformerFactory that already does the rewrite before it even hits your custom transformer. If that is the case, decide which one to use - the existing one or yours, if they do the same rewriting. If different, decide which one will rewrite what and put them in the proper order of execution via ranking.

lavishvasuja
Level 3
May 14, 2023

Thank you for your response, @krassimirbo . I have the same code on both my local machine and the project's dev environment. However, the code works on my local machine but not on the dev environment.

Level 3
May 15, 2023

Hi @lavishvasuja,

 

In your AEM local and dev environment, open the path /system/console/status-slingrewriter. That will show you all Sling Rewriter configurations on both environments. Most probably, the configuration for your LinkTransformImpl is missing on the dev server or if it is present it has a lower ranking. 

 

Let me know what you see there.

somen-sarkar
Community Advisor
Community Advisor
May 15, 2023

Hi,

Could you check if you have any rewrite rule mentioned for "industrial-transformation" site in dispatcher config or anything in Resource Resolver Factory config in OSGI ?  Some differences might be there which is causing the "/content/industrial-transformation" being removed for cloud dev instance . 

Another thing you can try. Change the node name of "industrial-transformation" to a different name and observe the link transformation behaviour.

 

Thanks,

Somen

Jagadeesh_Prakash
Community Advisor
Community Advisor
May 15, 2023

@lavishvasuja I recommand you to go through the step by step debuging issue 

 

As suggested by @somen-sarkar  "Another thing you can try. Change the node name of "industrial-transformation" to a different name and observe the link transformation behaviour." this is one good idea. I am pretty sure that it will show where exactly the issue is

 

If not try debug in below ways :

1. Try deploying the code on a new instance 

2. And also try to check any dispatcher rules are getting applied. 

3. Remove the LinkTransformImpl from your code and check once 

4. Once check in /etc/map as well 

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
May 15, 2023

You have a rewrite mapping e.g. org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.xml  in dev

Example https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/ui.apps/src/main/content/jcr_root/apps/JunitApp/config.publish/org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.xml 

 

You can do resource.resolve() before adding to transformation code or remove the above config for your site/path.

Arun Patidar