Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

How to programmatically find out the Resource given a URL?

Avatar

Level 1

According to ResourceResolver Interface:

http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/resource/ResourceResolver.html

There are ways to resolve either path or request to a Resource:

     Resource   resolve(HttpServletRequest request) Deprecated. as of 2.0.4, use resolve(HttpServletRequest, String) instead. Resource   resolve(HttpServletRequest request, String absPath) Resolves the resource from the given absPath optionally taking HttpServletRequest into account, such as the value of the Host request header. Resource   resolve(String absPath) Resolves the resource from the given absolute path.

But, if I have a random given URL string (e.g. 'http://www.mycompany.com/whatever.html'). How do I programmatically find out the corresponding Resource from a given URL string?

In other words, how is 

Adobe Experience Manager Web Console
Sling Resource Resolver

implemented?

 
1 Accepted Solution

Avatar

Correct answer by
Employee

Hi,

If you look at the code Joerg pointed to, you'll see how to do this - generate a synthetic HttpServletRequest object.

Regards,
Justin

View solution in original post

3 Replies

Avatar

Employee Advisor

Avatar

Level 1

Not really.

All the codes indicate given a request (e.g. HttpServletRequest) I can call ResourceResolve.resolve(request) to programmatically translate a Request to Resource. However, if I don't have a Request, but only a URL String, how do I figure out the Resource of a random given URL String?

Thanks,

Avatar

Correct answer by
Employee

Hi,

If you look at the code Joerg pointed to, you'll see how to do this - generate a synthetic HttpServletRequest object.

Regards,
Justin