Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Request Resource resolver resolve is not working

Avatar

Level 6

We are using AEM 6.5.14. The map and reverse map is properly configured. From /system/console/jcrresolver the resolve and map is working fine.

But from code we can not get the full path from domain. In short request.getResourceResolver().resolve("http://local.---world.com").getPath() is not returning the full path. 

THE MAP

kaikubad_0-1674712528592.png

 

FROM  /system/console/jcrresolver

jcr-resolve.png

 

FROM code map is working

kaikubad_0-1674712308051.png

BUT from code resolve is not working

resolve.png

 

What could be the possible solution?????

1 Accepted Solution

Avatar

Correct answer by
Level 6

Tried too many things, but the resurceReolver.resolve() is not working.
Finally moved to manual solution.

  1. Created the reverse map node on /etc/map
  2. Searching manually under /etc/map when needed with the domaain
  3. Then concatinating with path.

View solution in original post

13 Replies

Avatar

Employee Advisor

Hi @kaikubad ,

 

The "resolve" method expects the path of the resource, you have to write something like this:-

 

resourceResolver.resolve("/content/something")

Also, take a look at the API documentation for more details about these methods.

https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html 

 

Hope this helps!

 

Regards,

Nitesh

Avatar

Level 6

I was actually looking for the full path from domain. In this case i dont know the /content/something.
I only have http://local.---world.com/. From this I have to find the actual path mapped with it.

I need this from http://local.---world.com  -to>  content/---world/global/en.

Avatar

Employee Advisor

If you have access to the slingRequest object, then you could use it to get the resource path, something like this:-

 

request.getRequestPathInfo().getResourcePath()

 

Avatar

Level 6

In this case it will return the servlet path not the content path, because the request is coming on a servlet. And the code snippet you gave returns the current request path info. In my case its a servlet.

kaikubad_0-1674717297320.png

 

Avatar

Employee Advisor

I see it's path based servlet, You could try to register your servlet using resourceType

 

 

"sling.servlet.resourceTypes="+ "sling/servlet/default",
"sling.servlet.selectors=" + "demo"

 

 

So, this way if you call your servlet from a specific page like "<domain>/<something>.demo.html", and then from the servlet, you can invoke 

 

request.getRequestPathInfo().getResourcePath()

 

 

You will get the full resource path.

 

Apart from this AFAIK, there is no other way to internally resolve it from the domain, you could write some logic in your code if you have the mapping details, and append it to resolve to the actual path.

 

May be you can share your full use case to provide more alternative solutions.

 

Hope this helps!

 

Regards,

Nitesh

 

 

Avatar

Community Advisor

@kaikubad 

Can you try resourceResolver.map(...) instead of resolve. 

Anudeep_Garnepudi_0-1674720413069.png

 

Avatar

Level 6

map is to convert long path to short path.
i.e : contentPath=/content/---world/global/en.

now if i use resourceResolver.map(contentPath) then it will retuen http://local.---world.com/en.

I need the reverse one. I need  this from http://local.---world.com  -to>  content/---world/global.

Avatar

Community Advisor

Can u try this 

${request.requestURL.toString}

Avatar

Level 6

Thanks,The documentation is very good.

But unfortunately this doesn't work.

Avatar

Correct answer by
Level 6

Tried too many things, but the resurceReolver.resolve() is not working.
Finally moved to manual solution.

  1. Created the reverse map node on /etc/map
  2. Searching manually under /etc/map when needed with the domaain
  3. Then concatinating with path.