You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:12:07 UTC

[sling-org-apache-sling-scripting-sightly-js-provider] 02/06: SLING-6166 - Update the HTL bundles to use the SLING-6165 request-scoped resource resolver

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.scripting.sightly.js.provider-1.0.18
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-js-provider.git

commit 0b61ed64dcda78f76482e93ca4ee19d481f74c5e
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Nov 28 18:11:54 2016 +0000

    SLING-6166 - Update the HTL bundles to use the SLING-6165 request-scoped resource resolver
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/js-use-provider@1771784 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                              |  2 +-
 .../scripting/sightly/js/impl/JsUseProvider.java     | 20 +++-----------------
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0e9e765..42f30bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -112,7 +112,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.api</artifactId>
-            <version>2.1.8</version>
+            <version>2.1.11-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
index f80471c..6a087ee 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
@@ -18,17 +18,14 @@
  ******************************************************************************/
 package org.apache.sling.scripting.sightly.js.impl;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.script.Bindings;
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 
-import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider;
 import org.apache.sling.scripting.sightly.SightlyException;
 import org.apache.sling.scripting.sightly.js.impl.async.AsyncContainer;
 import org.apache.sling.scripting.sightly.js.impl.async.AsyncExtractor;
@@ -79,7 +76,6 @@ public class JsUseProvider implements UseProvider {
     private static final Logger LOGGER = LoggerFactory.getLogger(JsUseProvider.class);
     private static final String JS_ENGINE_NAME = "javascript";
     private static final JsValueAdapter jsValueAdapter = new JsValueAdapter(new AsyncExtractor());
-    private static final String SLING_SCRIPTING_USER = "sling-scripting";
 
     @Reference
     private ScriptEngineManager scriptEngineManager = null;
@@ -88,7 +84,7 @@ public class JsUseProvider implements UseProvider {
     private ProxyAsyncScriptableFactory proxyAsyncScriptableFactory = null;
 
     @Reference
-    private ResourceResolverFactory rrf = null;
+    private ScriptingResourceResolverProvider scriptingResourceResolverProvider = null;
 
     @Override
     public ProviderOutcome provide(String identifier, RenderContext renderContext, Bindings arguments) {
@@ -102,30 +98,20 @@ public class JsUseProvider implements UseProvider {
         }
         SlingScriptHelper scriptHelper = Utils.getHelper(globalBindings);
         JsEnvironment environment = null;
-        ResourceResolver slingScriptingResolver = null;
         try {
             environment = new JsEnvironment(jsEngine);
             environment.initialize();
-            Map<String, Object> authenticationInfo = new HashMap<String, Object>() {{
-                put(ResourceResolverFactory.SUBSERVICE, SLING_SCRIPTING_USER);
-            }};
-            slingScriptingResolver = rrf.getServiceResourceResolver(authenticationInfo);
+            ResourceResolver slingScriptingResolver = scriptingResourceResolverProvider.getRequestScopedResourceResolver();
             Resource callerScript = slingScriptingResolver.getResource(scriptHelper.getScript().getScriptResource().getPath());
             Resource scriptResource = Utils.getScriptResource(callerScript, identifier, globalBindings);
             globalBindings.put(ScriptEngine.FILENAME, scriptResource.getPath());
             proxyAsyncScriptableFactory.registerProxies(globalBindings);
             AsyncContainer asyncContainer = environment.runResource(scriptResource, globalBindings, arguments);
             return ProviderOutcome.success(jsValueAdapter.adapt(asyncContainer));
-        } catch (LoginException e) {
-            LOGGER.error("Cannot obtain a resource resolver backed by the " + SLING_SCRIPTING_USER + " service user.", e);
-            return ProviderOutcome.failure(e);
         } finally {
             if (environment != null) {
                 environment.cleanup();
             }
-            if (slingScriptingResolver != null) {
-                slingScriptingResolver.close();
-            }
         }
     }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.