|
FAQ has been edited by Bertrand Delacretaz (Jul 09, 2008). Change summary: add more _javascript_/jsp engine info Frequently Asked QuestionsThis page lists a series of common questions and answers. It is of course work in progress ...
Scripts and ServletsHow to replace the default json renderer (for example) with my own?The JSON rendering is done by the DefaultGetServlet, which is hardwired to use the JsonRendererServlet for .json extensions. If a servlet or script is registered for the sling/servlet/default resource type, but with a specific sling.servlet.extensions property (set using the @scr.property annotation), it will take over and process GET requests which have a .json extension and no specific servlet or script. As scripts and servlets are equivalent in Sling, the simplest way to do this to create a script at apps/sling/servlet/default/json.esp, for example. The same logic applies to other extensions (html, txt, ...) handled by the DefaultGetServlet. How do I create a new script engine?As I write this, we don't have documentation on how to create more script engines, but that's not too hard to do if you take one of the simple existing engines as an example. The JRuby engine If creating a script engine, don't forget the META-INF/services/javax.script.ScriptEngineFactory file, which lets scripting subsystem know about the factory class, so that the engine is activated when the bundle that contains it is loaded. Once the script engine is created, loading its bundle into Sling should be enough to activate scripts having the extension defined by the engine. If several scripts are found with the same name but different script extensions, the priority in selecting them is currently unspecified. The _javascript_ and freemarker engines source code also shows how to add automated tests to a script engine, including making a JCR repository available to the tests. To go further, the _javascript_ and jsp script engines are the most interesting ones to study. The _javascript_ engine provides wrappers The jsp engine is actually a compiler, so it can be an interesting example if your language needs or can benefit from compiling. Working with bundlesIs there an easy way to update bundles in a running installation during development?The Sling Maven Plugin provides an install goal which is able to install or update a bundle in a running Sling application (if the Sling web console is deployed). If the plugin properties are configured accordingly you can just mvn clean package org.apache.sling:maven-sling-plugin:install and the bundle is uploaded. You can use the settings.xml to set the url to your Sling application. See the Sling Maven Plugin Classloading issuesAccessing Classes from the EnvironmentMostly when using the Sling Web Application, that is running Sling inside a web application deployed into some servlet container, you might want to share classes between the servlet container and Sling. Some examples of such sharing are:
For such cases the OSGi Core Specification provides a functionality to declare such class sharing. The functionality is defined in terms of two Framework properties org.osgi.framework.system.packages and org.osgi.framework.bootdelegation:
The problem with the org.osgi.framework.bootdelegation property is, that it completely bypasses any bundle import wirings and just asks the parent classloader. Such situations are not easily recognizable. Therefore the Sling Console will be enhanced to mark any package import which matchs an entry in the org.osgi.framework.bootdelegation appropriately (SLING-148 Also note, that any package listed as an import in a bundle must be resolveable for the bundle resolve. The import resolution process does not take the org.osgi.framework.bootdelegation configuration into account. This means, that regardless of whether a package is listed in the org.osgi.framework.bootdelegation property or not, if the package is listed as a required import in the Import-Package header, it must be exported by some other bundle. How are the sling.bootdelegation properties used ?Sling uses the sling.bootdelegation.class property name prefix to define lists of classes that must be added to the org.osgi.framework.bootdelegation property. In case you want to have a closer look, this is implemented in the org.apache.sling.launcher.app.Sling.resolve() method. If a Sling property name starts with the sling.bootdelegation.class. prefix, the list of packages defined as the property value is appended to the org.osgi.framework.bootdelegation property, but only if the fully qualified class taken from the rest of the property name exists in the parent class loader. Here's an example, from the jcr-client.properties file: sling.bootdelegation.class.javax.jcr.Repository = \ javax.jcr, \ javax.jcr.lock, \ javax.jcr.nodetype, \ javax.jcr.observation, \ javax.jcr.query, \ javax.jcr.util, \ javax.jcr.version
|
Unsubscribe or edit your notifications preferences
