You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Buss, Simon" <si...@vwfs.com> on 2011/03/23 17:03:51 UTC

accessing script / resource without http request

Hi,
We'd like to call a script on a resource from an osgi service to
generate a respresention of the resource's content in shape of a "drl"
file (drools rules language) and access the output of the script. Goal
is to compile a set of configurable rules files (irrelvant for the
problem). Hence, the service runs at startup we don't have an http
request at hand.


Here is what we tried so far.


          Resource scriptResource =
resolver.resolve("/apps/xxx/components/pages/yyy/drl.jsp");
          SlingScript script =
scriptResource.adaptTo(SlingScript.class);

          String path = "/content/path/to/page/_jcr_content.drl.jsp";
          Resource ruleResource = resolver.resolve(path);

          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PrintWriter writer = new PrintWriter(baos);
          BufferedReader reader = new BufferedReader(new
StringReader(""));

          SlingBindings props = new SlingBindings();
          props.setReader(reader);
          props.setOut(writer);
          props.setFlush(true);
          props.setResource(ruleResource);
          props.setRequest(new DummyRequest(resolver, reader,
ruleResource));
          props.setResponse(new DummyResponse(writer));
          Object scriptResult = script.eval(props);
          String s = (String) scriptResult;


DummyRequest and DummyResponse are the most simple implementations of
SlingHttpServletRequest and HttpServletResponse.



Outcome is as follows:

23.03.2011 16:32:51.001 *WARN* [SCR Component Actor] xxx.OurServiceImpl
Error reading rule
org.apache.sling.api.scripting.ScriptEvaluationException:
java.lang.NullPointerException
	at
org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlin
gScript.java:251)
	at
org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlin
gScript.java:161)
	at xxx.OurServiceImpl.readRules(OurServiceImpl.java:188)
	at xxx.OurServiceImpl.activate(OurServiceImpl.java:97)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java
:215)
	at
org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:3
8)
	at
org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.j
ava:551)
	at
org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:443)
	at
org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.ja
va:138)
	at
org.apache.felix.scr.impl.manager.ImmediateComponentManager.createImplem
entationObject(ImmediateComponentManager.java:226)
	at
org.apache.felix.scr.impl.manager.ImmediateComponentManager.createCompon
ent(ImmediateComponentManager.java:118)
	at
org.apache.felix.scr.impl.manager.AbstractComponentManager$Unsatisfied.a
ctivate(AbstractComponentManager.java:1022)
	at
org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInter
nal(AbstractComponentManager.java:323)
	at
org.apache.felix.scr.impl.manager.AbstractComponentManager$1.doRun(Abstr
actComponentManager.java:139)
	at
org.apache.felix.scr.impl.ComponentActivatorTask.run(ComponentActivatorT
ask.java:67)
	at
org.apache.felix.scr.impl.ComponentActorThread.run(ComponentActorThread.
java:96)
	at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
	at
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.doEndTag(DefineOb
jectsTag.java:111)
	at
com.day.cq.wcm.tags.DefineObjectsTag.doEndTag(DefineObjectsTag.java:176)
	at
org.apache.jsp.apps.xxx.components.pages.yyy.drl_jsp._jspService(drl_jsp
.java:95)
	at
org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJs
pBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at
org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(
JspServletWrapper.java:394)
	at
org.apache.sling.scripting.jsp.JspServletWrapperAdapter.service(JspServl
etWrapperAdapter.java:59)
	at
org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptE
ngineFactory.java:142)
	at
org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScri
ptEngineFactory.java:73)
	at
org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.ev
al(JspScriptEngineFactory.java:344)
	at
org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlin
gScript.java:224)
	... 20 more


Any pointers on what needs to be set/implemented when "mocking" request
and response or alternative approaches are appreciated!

Thanks in advance and kind regards,
Simon



Volkswagen Financial Services AG
Sitz/Registered seat: Braunschweig
Registergericht/Registration court: Amtsgericht Braunschweig
HRB Nr./Commercial Register No.: 3790
Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Hans Dieter Potsch
Vorstand/Board of Management: Frank Witter (Vorsitzender/Chairman), Frank Fiedler, Christiane Hesse, Dr. Michael Reinhart, Lars-Henner Santelmann
Wichtiger Hinweis: Die vorgenannten Angaben werden jeder E-Mail automatisch hinzugefugt und lassen keine Ruckschlusse auf den Rechtscharakter der E-Mail zu.
Important note: The above information is automatically added to this e-mail. This addition does not constitute a representation that the content of this e-mail is legally relevant and/or is intended to be legally binding upon Volkswagen Financial Services AG.