You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Konrad Windszus (JIRA)" <ji...@apache.org> on 2017/03/02 09:22:45 UTC

[jira] [Commented] (SLING-6587) Resource Merger does not work correctly with content

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

Konrad Windszus commented on SLING-6587:
----------------------------------------

The resource resolver always first tries to resolve the URL directly (without any splitting) against all registered resource providers. Since your resource picker actually returns a resource for a resource path including the extension the resource resolver just takes this resource. Only in case the first attempt does not return a resource the resolver will split up the URL. So in this case you should be able to fix in your {{ResourcePicker}} by just returning an empty collection for resource paths containing ".".

> Resource Merger does not work correctly with content
> ----------------------------------------------------
>
>                 Key: SLING-6587
>                 URL: https://issues.apache.org/jira/browse/SLING-6587
>             Project: Sling
>          Issue Type: Bug
>          Components: Extensions
>    Affects Versions: Resource Merger 1.3.0
>            Reporter: Georg Henzler
>
> I tried to create the following resource picker in the hope I could merge content resources and render them as html:
> {code}
> @Component(label = "Content Resource Picker", description = "", metatype = true)
> @Service(value = { MergedResourcePicker2.class })
> @Properties({
>         @Property(name = MergedResourcePicker2.MERGE_ROOT, value = WwwMergingResourcePicker.DEFAULT_ROOT, label = "Root", description = "The mount point of merged resources"),
>         @Property(name = MergedResourcePicker2.READ_ONLY, boolValue = false, label = "Read Only", description = "Specifies if the resources are read-only or can be modified.")
> })
> public class WwwMergingResourcePicker implements MergedResourcePicker2 {
>     private static final Logger LOG = LoggerFactory.getLogger(WwwMergingResourcePicker.class);
>     public static final String DEFAULT_ROOT = "/mnt/contentwww";
>     @Override
>     public List<Resource> pickResources(final ResourceResolver resolver, final String relativePath,
>             final Resource relatedResource) {
>         String resourcePath = StringUtils.substringBefore(relativePath, "."); // for some reason path/to/page.html including ".html" is passed in here
>         List<Resource> resources = new ArrayList<Resource>();
>         String overrideContentBasePath = "/content/www/override";
>         String masterBasePath = "/content/www/master";
>         String overrideContentPath = overrideContentBasePath + "/" + resourcePath;
>         Resource overrideContentResource = resolver.getResource(overrideContentPath);
>         resources.add(overrideContentResource);
>         String masterPath = masterBasePath + "/" + resourcePath;
>         Resource masterResource = resolver.getResource(masterPath);
>         resources.add(masterResource);
>         return resources;
>     }
> }
> {code}
> The request to `/mnt/contentwww/path/to/my/page.html` answers with a redirect to /mnt/contentwww/path/to/my/page.html/, trailing slash instead of returning an html rendering, the root cause seems to be that for some reason the request path is completely taken as resource path instead of splitting it in the sling way (extension should be html, .html should be cut off the resource path: 
> {code}
>  0 TIMER_END{0,ResourceResolution} URI=/mnt/contentwww/path/to/my/page.html resolves to Resource=MergedResource [path=/mnt/contentwww/path/to/my/page.html, resources=[Ljava.lang.String;@31d6983a]
>       0 LOG Resource Path Info: SlingRequestPathInfo: path='/mnt/contentwww/path/to/my/page.html', selectorString='null', extension='null', suffix='null'
> ...
>       4 TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0}
>       4 LOG Using org.apache.sling.servlets.get.impl.helpers.StreamRendererServlet to render for extension=null
> {code}
> Looking at the code of the resource merger module, it is just registering a resource provider and hence, conceptually it should work (the resource provider should never get to see a path with extension ".html" IMHO, to me it looks like the problem might be in some other module).



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)