Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Issue with teaser images with resource mapping

Avatar

Level 4

Hi All,

I am using resource mapping to shorten the website URL. It works fine for all the scenarios except that core images authored as part of teaser component are not showing up. When I tried to debug the issue, I found out that the issue is happening as image path is pointing to nodes under /content and because of resource mapping image path is also getting shortened and thus returning 404.

When I try to access image with full path then it loads up properly.

E.g.

I have teaser component authored on my home page of demo.com website. After adding the the resource mapping and trying to access domo.com, it server tries to load image from below url and thus throwing 404 error:

https://demo.com_jcr_content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_165…

If i try to access full URL for image then image is loading fine

https://demo.com/content/demo/us/en/_jcr_content/root/responsivegrid/responsivegrid_1471831795/respo...

Is there a way that shortening of these image paths can be ignored and rule only applies for webpages? Or else is there any other solution that can used here?

Below is sample resource mapping that I am using for demo.com.

{

    "jcr:primaryType": "sling:Folder",

    "demo.com": {

        "jcr:primaryType": "sling:Mapping",

        "sling:internalRedirect": [

            "/content/demo/us/en"

        ],

        "demo_com_content": {

            "jcr:primaryType": "sling:Mapping",

            "sling:match": "(.+)$",

            "sling:internalRedirect": [

                "/content/demo/us/en/$1",

                "/$1"

            ]

        },

        "reverse_mapping_content": {

            "jcr:primaryType": "sling:Mapping",

            "sling:match": "$1",

            "sling:internalRedirect": [

                "/content/demo/us/en/(.*).html"

            ]

        },

        "reverse_mapping_content_nohtml": {

            "jcr:primaryType": "sling:Mapping",

            "sling:match": "$1",

            "sling:internalRedirect": [

                "/content/demo/us/en/(.*)"

            ]

        },

        "reverse_mapping_root": {

            "jcr:primaryType": "sling:Mapping",

            "sling:match": "$",

            "sling:internalRedirect": [

                "/content/demo/us/en(.html)?"

            ]

        }

    },

    "demo_com_root": {

        "jcr:primaryType": "sling:Mapping",

        "sling:match": "demo.com$",

        "sling:internalRedirect": [

            "/content/demo/us/en.html"

        ]

    }

}

10 Replies

Avatar

Level 10

Could you explain the purpose of using "reverse_mapping_content", "reverse_mapping_content_nohtml"  and "reverse_mapping_root". You could work with absolute urls on the server itself.

The other rules should suffice the requirement. The issue you're facing is because of "reverse_mapping_content_nohtml". You should not create a generic rule to map anything with "/content/demo/us/en/(.*)"

Remove two rules - "reverse_mapping_content_nohtml"  and "reverse_mapping_root" and test.

Avatar

Level 4

Tried deleting those 2 entries but no luck. Still same behavior.

Avatar

Level 10

https://demo.com/content/demo/us/en/_jcr_content/root/responsivegrid/responsivegrid_147183 1795/responsivegrid_165…  to    https://demo.com/content/demo/us/en/_jcr_content/root/responsivegrid/responsivegrid_147183 1795/responsivegrid_165…

happens with "reverse_mapping_content_nohtml" per shared rules.

After removing the rules, navigate to /system/console/jcrresolver and test your url/path using the 'map' feature

Could you share the rules in a package if you still run into issues?

Avatar

Level 4

Hi Gaurav,

Removing those 2 configurations is not fixing the issue. I checked resource resolver and both resolves to same path. But when I verify the Servlet resolver for long and short path, i notice that long path is being handled by adaptiveimageservlet as system is able to resolve the path to a resource while for short path it is not able to resolve to any resource so it tries to handle with DefaultGetServlet.

//=========================Long Path===========================================///

0 TIMER_START{Request Processing}

      1 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>

      3 LOG Method=GET, PathInfo=null

      4 TIMER_START{handleSecurity}

    784 TIMER_END{777,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@363c58ed returns true

    991 TIMER_START{ResourceResolution}

   2076 TIMER_END{1077,ResourceResolution} URI=/content/demo/us/en/_jcr_content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png resolves to Resource=JcrNodeResource, type=demo/components/core/wcm/teaser, superType=null, path=/content/demo/us/en/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser

   2085 LOG Resource Path Info: SlingRequestPathInfo: path='/content/demo/us/en/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser', selectorString='coreimg', extension='png', suffix='/1549341207212.png'

   2086 TIMER_START{ServletResolution}

   2089 TIMER_START{resolveServlet(/content/demo/us/en/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser)}

   2104 TIMER_END{12,resolveServlet(/content/demo/us/en/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser)} Using servlet 59536

   2107 TIMER_END{20,ServletResolution} URI=/content/demo/us/en/_jcr_content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png handled by Servlet=59536

///==================Short Path =========================////

0 TIMER_START{Request Processing}

      1 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>

      5 LOG Method=GET, PathInfo=null

      6 TIMER_START{handleSecurity}

   1035 TIMER_END{1027,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@363c58ed returns true

   1189 TIMER_START{ResourceResolution}

   1987 TIMER_END{796,ResourceResolution} URI=/_jcr_content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png resolves to Resource=NonExistingResource, path=/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png

   1993 LOG Resource Path Info: SlingRequestPathInfo: path='/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png', selectorString='coreimg', extension='png', suffix='/1549341207212.png'

   1993 TIMER_START{ServletResolution}

   1996 TIMER_START{resolveServlet(/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png)}

   2716 LOG {0}: no servlet found

   2722 TIMER_END{723,resolveServlet(/jcr:content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet

   2724 TIMER_END{730,ServletResolution} URI=/_jcr_content/root/responsivegrid/responsivegrid_1471831795/responsivegrid_1654523246/teaser.coreimg.png/1549341207212.png handled by Servlet=org.apache.sling.servlets.get.DefaultGetServlet

Avatar

Level 10

Could you package your sling mappings and share with me? I'd like to test in my local.

Avatar

Level 4

Hi Gaurav,

I am unable to find an option to upload a file other than image and video. Could you please assist me on how the zip file can be uploaded in this editor.

Thanks,
Rajeev

Avatar

Level 10

I checked the mappings but couldn't find a solution where you can shorten the url using sling mappings, avoid modifying teaser component and avoid using apache redirects for this use case.

Let's hear from other folks if they're aware of a better solution.

Avatar

Level 4

Rajeev, did you get to closure on this scenario? If yes, please share the same with us.

Avatar

Level 4

Was able to get the redirects to work for both content URLs and teaser image URLs. Below are few rules from my local instance

 

{
  "jcr:primaryType": "sling:Folder",
  "jcr:createdBy": "admin",
  "hidden": "true",
  "jcr:created": "Tue Sep 17 2019 15:26:49 GMT-0700",
  "http": {
    "jcr:primaryType": "sling:Folder",
    "jcr:createdBy": "admin",
    "jcr:created": "Tue Sep 17 2019 15:26:49 GMT-0700",
    "localhost.4508": {
      "jcr:primaryType": "sling:Mapping",
      "jcr:createdBy": "admin",
      "jcr:created": "Thu Feb 13 2020 12:18:43 GMT-0800",
      "sling:internalRedirect": "/content/we-retail/us/en",
      "redirect": {
        "jcr:primaryType": "sling:Mapping",
        "jcr:createdBy": "admin",
        "jcr:created": "Thu Feb 13 2020 12:18:43 GMT-0800",
        "sling:match": "(.+)$",
        "sling:internalRedirect": [
          "/content/we-retail/us/en/$1",
          "/$1"
        ]
        }
      }
    }
  }