Scripting provides a great compromise between the raw power of writing an accessor in
the Java Language and using a declarative runtime such as DPML. You can combine complex
logic and algorithms with the ability to issue sub-requests into the NetKernel URI request
infrastructure. Scripting performance is very good since every script is dynamically compiled and
cached and so performs equivalently to Java byte-code.
This trailmap shows some scripts which demonstrate common usage patterns.
Brief Guide to the Scripting Context
The NetKernel Scripting Framework executes scripts in an accessor - each script has access
to the accessor's current request context, that is the active URI request which invoked the script.
A script receives a context object which is an implementation of
INKFConvenienceHelper from the NetKernel Foundation API - the context object is used to retrieve arguments passed to the script
in the request, interact with the kernel to make sub-requests for services and finally to issue a resource as the ultimate response of the script.
Through the context object a script can access the request which invoked it. The request may then be used to access any arguments which might have been
passed to the script.
Generally a script performs some processing which generates a resource. It may do this with internal code or equally it may
issue sub-requests for other services, so, as with DPML, a script can be used to schedule services and co-ordinate workflows.
A script returns its response by calling context.setResponse(...) - this is the equivalent of setting this:response
in DPML.
A detailed guide to the NetKernel Scripting Framework is provided here.
Invoking a Script
A script is invoked by using one of the following accessors beanshell, groovy, javascript
or python. These accessors may be used from within any XML runtime process or can be called directly with an active URI - for example,
to execute a script from DPML...
<instr>
<type>beanshell</type>
<operator>ffcpl:/myscript.bsh</operator>
<arg1>ffcpl:/argument1.xml</arg1>
<target>var:result</target>
</instr>
which is equivalent to the direct active URI invocation...
active:beanshell+operator@ffcpl:/myscript.bsh+arg1@ffcpl:/argument1.xml...
Examples
- XSLT Pipeline an example of sequencing a set of XML transforms using a loosely typed style.
- REST Service an example of creating a REST style service with a strongly typed style.
- Hilbert Curve an example of a complex logic combined with issuing sub-requests.