Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Url Shortning

Avatar

Level 2

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, "");

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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/a... 

 

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



Arun Patidar

View solution in original post

6 Replies

Avatar

Level 3

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.

Avatar

Level 2

Thank you for your response, @KBWEB . 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.

Avatar

Level 3

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.

Avatar

Community Advisor

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

Avatar

Community Advisor

@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 

Avatar

Correct answer by
Community Advisor

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/a... 

 

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



Arun Patidar