Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!
SOLVED

ResourceResolver resolve method not working as expected (6.1)

Avatar

Level 5

I am using AEM 6.1 and am experiencing some weird behaviour with the 'resolve' method of the ResourceResolver.

I have a bunch of mappings that work correctly on the live site, when I use the '.../system/console/jcrresolver' to test my mappings I get the following result:

Screen Shot 2017-05-31 at 11.07.21.png

'https://acc-company.com/nl/size-guides' is correctly resolved into '/content/www-company-com/nl/size...

When I try to use the resolve method from ResourceResolver in code I do get a wrong result:

resourceResolver.resolve("https://acc-company.com/nl/size-guides").getPath();

Results in: '/https://acc-company.com/nl/size-guides', why am I not receiving '/content/www-company-com/nl/size-guides' ?

NOTE: mapping (the reverse of resolving) does work when triggered from code:

resourceResolver.map("/content/www-company-com/nl/size-guides");

Results in: 'https://acc-company.com/nl/size-guides'

Any idea what is causing the resolving to fail?

Thanks in advance

Jeroen

1 Accepted Solution

Avatar

Correct answer by
Level 8
3 Replies

Avatar

Level 8

Hi,

Not pretty sure, but just a thought.

After doing Resource resource = resolver.resolve(pagePath), You might want to use adaptTo() like resource.adaptTo(Page.class) and then do a getPath() on it and see if it helps.

Avatar

Level 5

Hey

The result of the resolve is a 'NonExistingResource' so it's pointless to call 'adaptTo' on this because it will result in 'null'

Screen Shot 2017-05-31 at 11.37.17.png

Avatar

Correct answer by
Level 8