request.getHeader('referer') returns only long url.
Views
Replies
Total Likes
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
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
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
In that case you need the
resouceResolver.map()
API call.
Views
Replies
Total Likes
Hi,
Could you please explain the use case, I believe in servlet you can shorten the url by chopping off contextpath substring.
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
If you want to write the short-path as URL within the page itself (or a different page), just write the "long" path there. If a mapping exists AEM will do that for you automatically. At least for pages, not for JSON payloads etc.
For these you need to use the ResourceResolver as indicated above.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies