how to read short Urls from long url /content/en in sling servlet. ? | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

September 20, 2022

hi,

thanks for the links. But I want to read the shortened url (cut url) available in the browser address bar in my sling servlet or sling models 

joerghoh
Adobe Employee
Adobe Employee
September 20, 2022

In your example code you are trying to read the "referer" header, which is obviously not what you want. Do you want to read the "long" (probably you mean "unshortened") path of the requested resource or the "long" path of the referer?

 

In any way, the links @saravanan_dharmaraj  provided are good ones, check them to understand the mapping.

If you want to reverse the shortening in Java code, you can use these API:

resourceresolver.map (longpath)

resourceresolver.resolver (request, shortpath) 

 

Both return resources, for which you can use "resource.getPath()" to get their actual repository path. See https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html

 

 

September 20, 2022

hi,

thanks for the reply. I want to read the shortened url which is visible to user in browser address bar (without /content/en ) in my sling servlet.

request.getRequestURL() and getRequestURI,request.getHeader('referer') are returning only long urls /content/en which I dont want. I want the one which is visible to user in my sling servlet or sling model

joerghoh
Adobe Employee
Adobe Employee
September 24, 2022

In that case you need the

resouceResolver.map()

API call.

arunpatidar
Community Advisor
Community Advisor
September 21, 2022

Hi,

Could you please explain the use case, I believe in servlet you can shorten the url by chopping off contextpath substring.

Arun Patidar
September 27, 2022

hi,
So my use case is something like, I have a page with path (say longURL) "http://localhost:4502/content/en/test/temp/apple.html", but the url which is visible to user is (shortURL) "www.apple.com/home". I want to read this shortURL in my servlet.If I use request.getPath or getReferer or getRequestURL are returning longurl, but I need shortURL 

arunpatidar
Community Advisor
Community Advisor
September 27, 2022

Where are the mappings from long to short? in AEM? How you are transforming links.

/content/en/test/temp/apple.html --> www.apple.com/home

 

you can use the same mapping here to get short url from long url.

Arun Patidar