[jira] [Commented] (SLING-8562) Unable to resolve ESP scripts loaded from Filesystem Resource Provider

2019-07-08 Thread Ben Fortuna (JIRA)


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

Ben Fortuna commented on SLING-8562:


Can reproduce issue with both Java 8 and Java 11.

It appears that the jsFunctions are not being registered with the Rhino script 
engine, so it falls back on calling
{code:java}
javax.jcr.Node.getNodes(String){code}
This is possibly also happening with regular bundles, but in such cases the 
Node implementation is an actual JCR node rather than the FsNode partial 
implementation.

I'd be interested to know what the roadmap for Javascript support in Sling 
involves, as Nashorn is being deprecated in favour of GraalVM, so is Rhino the 
preferred script engine?

 

> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> --
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
>  Issue Type: Bug
>Affects Versions: Scripting Core 2.0.46, File System Resource Provider 
> 2.1.16
>Reporter: Ben Fortuna
>Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem 
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
>   "sling:resourceType": "sample/page/index",
>   "jcr:primaryType": "nt:unstructured",
>   "title": "Sample App"
> }{code}
>  
> /apps/sample/page/index/html.esp:
> {code:java}
> 
> ${currentNode.title}
> 
> {code}
>  
> When both content and app are mounted via Filesystem Resource Provider config 
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
>   at 
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
>   at 
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>  
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to 
> resolve the property `currentNode.title` but Filesystem Resource Provider 
> doesnt support this method.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (SLING-8562) Unable to resolve ESP scripts loaded from Filesystem Resource Provider

2019-07-10 Thread Robert Munteanu (JIRA)


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

Robert Munteanu commented on SLING-8562:


[~fortuna] - I am well outside my area of competence with this - but is this 
problem specific to ESP or does it manifest also on JSP/HTL scripts? I would 
guess that the problem is with the FS Resource Provider and script bindings 
that are specific to JCR.

> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> --
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
>  Issue Type: Bug
>Affects Versions: Scripting Core 2.0.46, File System Resource Provider 
> 2.1.16
>Reporter: Ben Fortuna
>Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem 
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
>   "sling:resourceType": "sample/page/index",
>   "jcr:primaryType": "nt:unstructured",
>   "title": "Sample App"
> }{code}
>  
> /apps/sample/page/index/html.esp:
> {code:java}
> 
> ${currentNode.title}
> 
> {code}
>  
> When both content and app are mounted via Filesystem Resource Provider config 
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
>   at 
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
>   at 
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>  
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to 
> resolve the property `currentNode.title` but Filesystem Resource Provider 
> doesnt support this method.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (SLING-8562) Unable to resolve ESP scripts loaded from Filesystem Resource Provider

2019-07-10 Thread Ben Fortuna (JIRA)


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

Ben Fortuna commented on SLING-8562:


Hi Robert, I've confirmed that HTL (and thymeleaf, groovy) script processing 
aren't affected by this issue, haven't tried JSP yet.

Definitely appears to be a rhino script binding issue, but unclear if the 
problem is with fs resource or with scripting core.

> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> --
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
>  Issue Type: Bug
>Affects Versions: Scripting Core 2.0.46, File System Resource Provider 
> 2.1.16
>Reporter: Ben Fortuna
>Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem 
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
>   "sling:resourceType": "sample/page/index",
>   "jcr:primaryType": "nt:unstructured",
>   "title": "Sample App"
> }{code}
>  
> /apps/sample/page/index/html.esp:
> {code:java}
> 
> ${currentNode.title}
> 
> {code}
>  
> When both content and app are mounted via Filesystem Resource Provider config 
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
>   at 
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
>   at 
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>  
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to 
> resolve the property `currentNode.title` but Filesystem Resource Provider 
> doesnt support this method.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (SLING-8562) Unable to resolve ESP scripts loaded from Filesystem Resource Provider

2019-07-11 Thread Julian Sedding (JIRA)


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

Julian Sedding commented on SLING-8562:
---

[~fortuna] your script does get resolved, otherwise you would not see the error 
you are seeing. It happens during script execution.

You are calling {{$\{currentNode.title\}}}, but there is no 
{{javax.jcr.Node#getTitle()}} method. Try {{$\{currentNode.name\}}} 
or{{$\{currentNode.path\}}}, which should both yield proper renderings, because 
{{javax.jcr.Node#getName()}} and {{javax.jcr.Node#getPath()}} do exist.

Seemingly, there is some "intelligence" somewhere in the code (and possibly the 
ESP implementation), that tries to make sense of the {{.title}} fragment and 
attempts to find a child-node with a matching name. The FS Resource Provider is 
primarily about providing resources, and on top of that it provides an 
incomplete JCR emulation layer. You hit one of the parts that are incomplete; 
to my knowledge there are no plans to provide a complete JCR emulation 
implementation (I doubt that would even be possible).

I would recommend that you try writing your rendering scripts using the 
{{Resource}} API instead. To get the title property of the current resource you 
would write {{$\{resource.valueMap['title']\}}} or possibly even 
{{$\{properties['title']\}}}. Note: I am not familiar with the ESP specifics, 
but I would expect bindings for both {{resource}} and {{properties}} to be 
present.

> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> --
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
>  Issue Type: Bug
>Affects Versions: Scripting Core 2.0.46, File System Resource Provider 
> 2.1.16
>Reporter: Ben Fortuna
>Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem 
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
>   "sling:resourceType": "sample/page/index",
>   "jcr:primaryType": "nt:unstructured",
>   "title": "Sample App"
> }{code}
>  
> /apps/sample/page/index/html.esp:
> {code:java}
> 
> ${currentNode.title}
> 
> {code}
>  
> When both content and app are mounted via Filesystem Resource Provider config 
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
>   at 
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
>   at 
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>  
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to 
> resolve the property `currentNode.title` but Filesystem Resource Provider 
> doesnt support this method.
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)


[jira] [Commented] (SLING-8562) Unable to resolve ESP scripts loaded from Filesystem Resource Provider

2019-07-11 Thread Ben Fortuna (JIRA)


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

Ben Fortuna commented on SLING-8562:


[~jsedding] apologies, I should have said script not "successfully" resolved. 
:) I've just written a quick test to demonstrate each of the above suggestions:
{code:java}
Testing sling scripting (ESP) with FS resource:
{properties} = [org.mozilla.javascript.EcmaError: ReferenceError: "properties" 
is not defined.]
{resource} = [/content/innersource/index]
{resource.valueMap} = [undefined]
{currentNode} = [/content/innersource/index]
{currentNode.name} = [java.lang.UnsupportedOperationException at 
org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)]
{currentNode.path} = [java.lang.UnsupportedOperationException at 
org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)]{code}
It appears that "properties" is not defined, and "resource" is defined but 
doesn't have a "valueMap" property.

For "currentNode" it is also defined, but any property access seems to resolve 
to the same FsNode.getNodes(String) method, which is not implemented.

I did have a look at the code and it appears that for currentNode.name or 
currentNode.path it SHOULD be calling a different method that is registered 
with Rhino via the "jsFunction_" method prefix, but I suspect this isn't 
working anymore so it falls back on the getNodes(String) method.

 

> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> --
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
>  Issue Type: Bug
>Affects Versions: Scripting Core 2.0.46, File System Resource Provider 
> 2.1.16
>Reporter: Ben Fortuna
>Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem 
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
>   "sling:resourceType": "sample/page/index",
>   "jcr:primaryType": "nt:unstructured",
>   "title": "Sample App"
> }{code}
>  
> /apps/sample/page/index/html.esp:
> {code:java}
> 
> ${currentNode.title}
> 
> {code}
>  
> When both content and app are mounted via Filesystem Resource Provider config 
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
>   at 
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
>   at 
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>  
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to 
> resolve the property `currentNode.title` but Filesystem Resource Provider 
> doesnt support this method.
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)


[jira] [Commented] (SLING-8562) Unable to resolve ESP scripts loaded from Filesystem Resource Provider

2019-07-12 Thread Julian Sedding (JIRA)


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

Julian Sedding commented on SLING-8562:
---

[~fortuna] as I said, I am not familiar with the ESP implementation. I took a 
look and you are right that my suggestions were incorrect. That's because there 
seems to be an explicit mapping between Java and javascript objects rather than 
an implicit mapping, which I had expected.

My reading of the source code is that you should be able to call properties 
explicitly like so {{currentNode.properties.title}} (or similarly 
{{resource.properties.title}}). I assume that calling {{currentNode.title}} 
tries various methods that take a String argument (i.e. "title"), among them 
{{Node#getNodes(String)}}. And as you noticed this method is not supported by 
the FS resource provider's JCR emulation layer.

Now I see multiple options:
# you provide a pull request to enhance the FS resource provider implementation
# you write ESP scripts using the more verbose {{currentNode.properties.*}} 
syntax (or better {{resource.properties.*}}
# you use JCR backed resources rather than FS resources
# you use a modern templating language like Thymeleaf or HTL, possibly with 
Sling Models
# you use JSP, also possibly with Sling Models

I would recommend option 4, as that's the most state-of-the-art way of 
implementing rendering scripts. Option 5 can be faster to hack, but it tends to 
be less maintainable.


> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> --
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
>  Issue Type: Bug
>Affects Versions: Scripting Core 2.0.46, File System Resource Provider 
> 2.1.16
>Reporter: Ben Fortuna
>Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem 
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
>   "sling:resourceType": "sample/page/index",
>   "jcr:primaryType": "nt:unstructured",
>   "title": "Sample App"
> }{code}
>  
> /apps/sample/page/index/html.esp:
> {code:java}
> 
> ${currentNode.title}
> 
> {code}
>  
> When both content and app are mounted via Filesystem Resource Provider config 
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
>   at 
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
>   at 
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>  
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to 
> resolve the property `currentNode.title` but Filesystem Resource Provider 
> doesnt support this method.
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)


[jira] [Commented] (SLING-8562) Unable to resolve ESP scripts loaded from Filesystem Resource Provider

2019-07-12 Thread Ben Fortuna (JIRA)


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

Ben Fortuna commented on SLING-8562:


Thanks [~jsedding] , I am exploring option 4 with positive results. In fact I 
am looking to support multiple template engines simultaneously - which sling 
does out of the box - so interested to see all possible options available.

My goal with sling is to provide an opinionated base platform that can be 
containerised (ie. Docker) but will load content/apps from external sources 
(eg. Filesystems). This should allow a single docker cluster to serve multiple 
tenants (sites) and be horizontally scalable (ie. Stateless).

Quite happy with results so far, and will try to contribute back where 
applicable.

> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> --
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
>  Issue Type: Bug
>Affects Versions: Scripting Core 2.0.46, File System Resource Provider 
> 2.1.16
>Reporter: Ben Fortuna
>Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem 
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
>   "sling:resourceType": "sample/page/index",
>   "jcr:primaryType": "nt:unstructured",
>   "title": "Sample App"
> }{code}
>  
> /apps/sample/page/index/html.esp:
> {code:java}
> 
> ${currentNode.title}
> 
> {code}
>  
> When both content and app are mounted via Filesystem Resource Provider config 
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
>   at 
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
>   at 
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>  
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to 
> resolve the property `currentNode.title` but Filesystem Resource Provider 
> doesnt support this method.
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)