There are two ways to save a script in JCR. The first way is to save
it at server startup time by using configuration.xml
and the second way is
to upload the script via HTTP.
Loading script at startup time
This way can be used for loading prepared scripts. To use this way, you need to configure org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoaderPlugin. See the simple configuration example below.
<external-component-plugins>
<target-component>org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoader</target-component>
<component-plugin>
<name>test</name>
<set-method>addPlugin</set-method>
<type>org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoaderPlugin</type>
<init-params>
<value-param>
<name>repository</name>
<value>repository</value>
</value-param>
<value-param>
<name>workspace</name>
<value>production</value>
</value-param>
<value-param>
<name>node</name>
<value>/script/groovy</value>
</value-param>
<properties-param>
<name>JcrGroovyTest.groovy</name>
<property name="autoload" value="true" />
<property name="path" value="file:/home/andrew/JcrGroovyTest.groovy" />
</properties-param>
</init-params>
</component-plugin>
</external-component-plugins>
The first value-param sets JCR repository.
The second value-param sets workspace.
The third one sets JCR node where scripts from plugin will be stored.
If the specified node does not exist, it will be created.
The list of scripts is set by properties-params.
Name of each properties-param will be used as node name for stored script.
The autoload property deploys this script at startup time,
and the path property sets the source of script to be loaded.
In this example, the single script is loaded from the local file: /home/andrew/JcrGroovyTest.groovy
.
This is sample of HTTP requests. In this example, the script is loaded from the test.groovy
file.
andrew@ossl:~> curl -u root:exo \ -X POST \ -H 'Content-type:script/groovy' \ --data-binary @test.groovy \ http://localhost:8080/rest/script/groovy/add/repository/production/script/groovy/test.groovy
This example imitates sending data with the HTML form ('multipart/form-data'). The autoload parameter is optional. If the autoload parameter is set to "true" (autoload=true), the script will be instantiated and deployed immediately.
andrew@ossl:~> curl -u root:exo \ -X POST \ -F "file=@test.groovy;name=test" \ -F "autoload=true" \ http://localhost:8080/rest/script/groovy/add/repository/production/script/groovy/test1.groovy