[ 
https://issues.apache.org/jira/browse/SLING-1629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12895816#action_12895816
 ] 

Alexander Klimetschek commented on SLING-1629:
----------------------------------------------

Hmm, might not be enough. I also noted that quite often you
a) don't have the request object available in your API, as you adapted 
something from resource, and have only the ResourceResolver.map(string) method 
available
b) for background-processes, you might have the need to create feeds etc. with 
absolute URLs

So for b) without any request object at all, you need to solve
- how to get the context path
- what to use as default host/port name if nothing is configured in /etc/map

Regardless how it is solved, a method for that could not reside in 
SlingHttpServletRequest of course...

> Add methods for externalizing links to SlingHttpServletRequest
> --------------------------------------------------------------
>
>                 Key: SLING-1629
>                 URL: https://issues.apache.org/jira/browse/SLING-1629
>             Project: Sling
>          Issue Type: New Feature
>          Components: API, Engine
>            Reporter: Alexander Klimetschek
>            Priority: Minor
>         Attachments: SLING-1629.patch
>
>
> When creating links in responses there are two cases:
> 1) create it for use by the browser: URLs relative to the current request
> 2) link used by external apps: absolute URL including hostname etc.
> For 1), you can already use ResourceResolver.map(request, path) (important to 
> use the request-based here).
> For 2), when you explicitly want absolute URLs (eg. for rss feeds, links in 
> emails, etc.), the ResourceResolver map methods will only add a host/port if 
> such a configuration is part of /etc/map. There is no default to use the 
> host/port from the current request.
> Also, if a hostname is configured and you use map(request, path), because 
> that is required for adding the context path, it will _strip_ it from the map 
> call if the current request goes to that hostname, which is probably the 
> normal case. The map(request, path) call is clearly aimed at relative URLs, 
> case 1).
> In order to provide convenient short access to those features, an externalize 
> method on the sling request object is better for both cases:
> case 1) relative url
>     slingRequest.externalize("/my/path")
> same as slingRequest.getResourceResolver().map(slingRequest, "/my/path"))
> case 2) absolute url
>     slingRequest.externalize("http", "/my/path")
> produces e.g. http://localhost:8080/my/path

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to