public class GroovyScript2RestLoader extends Object implements org.picocontainer.Startable
| Modifier and Type | Class and Description |
|---|---|
protected static class |
GroovyScript2RestLoader.InnerGroovyJaxrsPublisher |
static class |
GroovyScript2RestLoader.ScriptList
Script list, used for pass script list as JSON.
|
static class |
GroovyScript2RestLoader.ScriptMetadata
Script meta-data, used for pass script meta-data as JSON.
|
| Modifier and Type | Field and Description |
|---|---|
protected List<GroovyScriptAddRepoPlugin> |
addRepoPlugins |
protected org.exoplatform.container.configuration.ConfigurationManager |
configurationManager
See
ConfigurationManager. |
protected org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher |
groovyPublisher |
protected org.exoplatform.container.xml.InitParams |
initParams
See
InitParams. |
protected List<GroovyScript2RestLoaderPlugin> |
loadPlugins |
protected RegistryService |
registryService
See
RegistryService. |
protected RepositoryService |
repositoryService
See
RepositoryService. |
protected SessionProviderService |
sessionProviderService
|
| Constructor and Description |
|---|
GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder,
org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator,
RepositoryService repositoryService,
SessionProviderService sessionProviderService,
org.exoplatform.container.configuration.ConfigurationManager configurationManager,
Handler jcrUrlHandler,
org.exoplatform.container.xml.InitParams params) |
GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder,
org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator,
RepositoryService repositoryService,
SessionProviderService sessionProviderService,
org.exoplatform.container.configuration.ConfigurationManager configurationManager,
RegistryService registryService,
org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher groovyPublisher,
Handler jcrUrlHandler,
org.exoplatform.container.xml.InitParams params) |
GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder,
org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator,
RepositoryService repositoryService,
SessionProviderService sessionProviderService,
org.exoplatform.container.configuration.ConfigurationManager configurationManager,
RegistryService registryService,
Handler jcrUrlHandler,
org.exoplatform.container.xml.InitParams params) |
| Modifier and Type | Method and Description |
|---|---|
void |
addPlugin(org.exoplatform.container.component.ComponentPlugin cp) |
javax.ws.rs.core.Response |
addScript(InputStream stream,
javax.ws.rs.core.UriInfo uriInfo,
String repository,
String workspace,
String path)
This method is useful for clients that can send script in request body
without form-data.
|
javax.ws.rs.core.Response |
addScript(Iterator<org.apache.commons.fileupload.FileItem> items,
javax.ws.rs.core.UriInfo uriInfo,
String repository,
String workspace,
String path)
This method is useful for clients that send scripts as file in
'multipart/*' request body.
|
protected void |
addScripts()
Add scripts that specified in configuration.
|
javax.ws.rs.core.Response |
autoload(String repository,
String workspace,
String path,
boolean state)
Change exo:autoload property.
|
protected javax.jcr.Node |
createScript(javax.jcr.Node parent,
String name,
boolean autoload,
InputStream stream)
Create JCR node.
|
javax.ws.rs.core.Response |
deleteScript(String repository,
String workspace,
String path)
Remove node that contains groovy script.
|
protected String |
getAttributeSmart(Element element,
String attr)
Get attribute value.
|
protected static String |
getName(String fullPath)
Extract node's name from full node path.
|
String |
getNodeType()
Get node type for store scripts, may throw
IllegalStateException
if nodeType not initialized yet. |
protected static String |
getPath(String fullPath)
Extract path to node's parent from full path.
|
javax.ws.rs.core.Response |
getScript(String repository,
String workspace,
String path)
Get source code of groovy script.
|
javax.ws.rs.core.Response |
getScriptMetadata(String repository,
String workspace,
String path)
Get groovy script's meta-information.
|
javax.ws.rs.core.Response |
list(String repository,
String workspace,
String name)
Returns the list of all groovy-scripts found in workspace.
|
javax.ws.rs.core.Response |
load(String repository,
String workspace,
String path,
boolean state,
List<String> sources,
List<String> files,
javax.ws.rs.core.MultivaluedMap<String,String> properties)
Deploy groovy script as REST service.
|
javax.ws.rs.core.Response |
load(String repository,
String workspace,
String path,
boolean state,
javax.ws.rs.core.MultivaluedMap<String,String> properties,
org.exoplatform.services.rest.ext.groovy.SourceFolder[] src,
org.exoplatform.services.rest.ext.groovy.SourceFile[] files)
Deploy groovy script as REST service.
|
protected void |
readParamsFromFile()
Read parameters from file.
|
protected void |
readParamsFromRegistryService(SessionProvider sessionProvider)
Read parameters from RegistryService.
|
protected void |
setAttributeSmart(Element element,
String attr,
String value)
Set attribute value.
|
void |
start() |
void |
stop() |
javax.ws.rs.core.Response |
updateScript(InputStream stream,
javax.ws.rs.core.UriInfo uriInfo,
String repository,
String workspace,
String path)
This method is useful for clients that can send script in request body
without form-data.
|
javax.ws.rs.core.Response |
updateScript(Iterator<org.apache.commons.fileupload.FileItem> items,
javax.ws.rs.core.UriInfo uriInfo,
String repository,
String workspace,
String path)
This method is useful for clients that send scripts as file in
'multipart/*' request body.
|
javax.ws.rs.core.Response |
validateScript(String name,
InputStream script,
List<String> sources,
List<String> files)
Check is specified source
script contains valid Groovy source
code. |
void |
validateScript(String name,
InputStream script,
org.exoplatform.services.rest.ext.groovy.SourceFolder[] src,
org.exoplatform.services.rest.ext.groovy.SourceFile[] files)
Check is specified source
script contains valid Groovy source
code. |
protected void |
writeParamsToRegistryService(SessionProvider sessionProvider)
Write parameters to RegistryService.
|
protected org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher groovyPublisher
protected org.exoplatform.container.xml.InitParams initParams
InitParams.protected RepositoryService repositoryService
RepositoryService.protected org.exoplatform.container.configuration.ConfigurationManager configurationManager
ConfigurationManager.protected RegistryService registryService
RegistryService.protected SessionProviderService sessionProviderService
protected List<GroovyScript2RestLoaderPlugin> loadPlugins
protected List<GroovyScriptAddRepoPlugin> addRepoPlugins
public GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder,
org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator,
RepositoryService repositoryService,
SessionProviderService sessionProviderService,
org.exoplatform.container.configuration.ConfigurationManager configurationManager,
Handler jcrUrlHandler,
org.exoplatform.container.xml.InitParams params)
binder - binder for RESTful servicesgroovyScriptInstantiator - instantiate groovy scriptsrepositoryService - See RepositoryServicesessionProviderService - See SessionProviderServiceconfigurationManager - for solve resource loading issue in common wayparams - initialized parameterspublic GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder,
org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator,
RepositoryService repositoryService,
SessionProviderService sessionProviderService,
org.exoplatform.container.configuration.ConfigurationManager configurationManager,
RegistryService registryService,
Handler jcrUrlHandler,
org.exoplatform.container.xml.InitParams params)
binder - binder for RESTful servicesgroovyScriptInstantiator - instantiates Groovy scriptsrepositoryService - See RepositoryServicesessionProviderService - See SessionProviderServiceconfigurationManager - for solve resource loading issue in common wayregistryService - See RegistryServiceparams - initialized parameterspublic GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder,
org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator,
RepositoryService repositoryService,
SessionProviderService sessionProviderService,
org.exoplatform.container.configuration.ConfigurationManager configurationManager,
RegistryService registryService,
org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher groovyPublisher,
Handler jcrUrlHandler,
org.exoplatform.container.xml.InitParams params)
public String getNodeType()
IllegalStateException
if nodeType not initialized yet.public void start()
start in interface org.picocontainer.StartableStartable.start()public void stop()
stop in interface org.picocontainer.StartableStartable.stop()public void addPlugin(org.exoplatform.container.component.ComponentPlugin cp)
protected void addScripts()
protected javax.jcr.Node createScript(javax.jcr.Node parent,
String name,
boolean autoload,
InputStream stream)
throws Exception
parent - parent nodename - name of node to be createdstream - data stream for property jcr:dataException - if any errors occursprotected void readParamsFromRegistryService(SessionProvider sessionProvider) throws javax.jcr.PathNotFoundException, javax.jcr.RepositoryException
sessionProvider - the SessionProviderjavax.jcr.RepositoryExceptionjavax.jcr.PathNotFoundExceptionprotected void writeParamsToRegistryService(SessionProvider sessionProvider) throws IOException, SAXException, ParserConfigurationException, javax.jcr.RepositoryException
sessionProvider - the SessionProviderParserConfigurationExceptionSAXExceptionIOExceptionjavax.jcr.RepositoryExceptionprotected String getAttributeSmart(Element element, String attr)
element - The element to get attribute valueattr - The attribute nameprotected void setAttributeSmart(Element element, String attr, String value)
element - The element to set attribute valueattr - The attribute namevalue - The value of attributeprotected void readParamsFromFile()
public javax.ws.rs.core.Response addScript(InputStream stream, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path)
stream - the stream that contains groovy source codeuriInfo - see javax.ws.rs.core.UriInforepository - repository nameworkspace - workspace namepath - path to resource to be createdpublic javax.ws.rs.core.Response addScript(Iterator<org.apache.commons.fileupload.FileItem> items, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path)
items - iterator org.apache.commons.fileupload.FileItemuriInfo - javax.ws.rs.core.UriInforepository - repository nameworkspace - workspace namepath - path to resource to be createdpublic javax.ws.rs.core.Response validateScript(String name, InputStream script, List<String> sources, List<String> files)
script contains valid Groovy source
code.name - script name. This name will be used by GroovyClassLoader to
identify script, e.g. specified name will be used in error
message in compilation of Groovy fails. If this parameter is
null then GroovyClassLoader will use automatically
generated namescript - Groovy source streamsources - locations (string representation of URL) of source folders
that should be add in class path when compile Groovy script.
NOTE : To be able load Groovy source files from specified
folders the following rules must be observed:
- Groovy source files must be located in folder with respect
to package structure
- Name of Groovy source files must be the same as name of
class located in file
- Groovy source file must have extension '.groovy'
Example: If source stream that we want validate contains the
following code:
package c.b.a
import a.b.c.A
class B extends A {
// Do something.
}
Assume we store dependencies in JCR then URL of folder with
Groovy sources may be like this:
jcr://repository/workspace#/groovy-library. Then
absolute path to JCR node that contains Groovy source must be as
following: /groovy-library/a/b/c/A.groovyfiles - locations (string representation of URL) of source files that
should be add in class path when compile Groovy script. Each
location must point directly to file that contains Groovy
source. Source file can have any name and extensionpublic void validateScript(String name, InputStream script, org.exoplatform.services.rest.ext.groovy.SourceFolder[] src, org.exoplatform.services.rest.ext.groovy.SourceFile[] files) throws org.exoplatform.services.rest.ext.groovy.MalformedScriptException
script contains valid Groovy source
code.name - script name. This name will be used by GroovyClassLoader to
identify script, e.g. specified name will be used in error
message in compilation of Groovy fails. If this parameter is
null then GroovyClassLoader will use automatically
generated namescript - Groovy source streamsrc - set of folders that contains Groovy source files that should be
add in class-path when validate script, see
ClassPathEntry.getPath(). NOTE To be able load
Groovy source files from specified folders the following rules
must be observed:
files - set of groovy source files that should be add in class-path
when validate script. Each item must point directly
to file that contains Groovy source, see
ClassPathEntry.getPath() . Source file can have any name and
extensionorg.exoplatform.services.rest.ext.groovy.MalformedScriptException - if script contains not valid
source codepublic javax.ws.rs.core.Response updateScript(InputStream stream, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path)
stream - the stream that contains groovy source codeuriInfo - see javax.ws.rs.core.UriInforepository - repository nameworkspace - workspace namepath - path to resource to be createdpublic javax.ws.rs.core.Response updateScript(Iterator<org.apache.commons.fileupload.FileItem> items, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path)
items - iterator org.apache.commons.fileupload.FileItemuriInfo - see javax.ws.rs.core.UriInforepository - repository nameworkspace - workspace namepath - path to resource to be created@RolesAllowed(value="administrators") public javax.ws.rs.core.Response load(String repository, String workspace, String path, boolean state, List<String> sources, List<String> files, javax.ws.rs.core.MultivaluedMap<String,String> properties)
repository - repository nameworkspace - workspace namepath - the path to JCR node that contains groovy script to be
deployedstate - true if resource should be loaded and
false otherwise. If this attribute is not present
in HTTP request then it will be considered as truesources - locations (string representation of URL) of source folders
that should be add in class path when compile Groovy script.
NOTE: To be able load Groovy source files from specified
folders the following rules must be observed:
- Groovy source files must be located in folder with respect
to package structure
- Name of Groovy source files must be the same as name of
class located in file
- Groovy source file must have extension '.groovy'
Example: If source stream that we want validate contains the
following code:
package c.b.a
import a.b.c.A
class B extends A {
// Do something.
}
Assume we store dependencies in JCR then URL of folder with
Groovy sources may be like this:
jcr://repository/workspace#/groovy-library. Then
absolute path to JCR node that contains Groovy source must be as
following: /groovy-library/a/b/c/A.groovyfiles - locations (string representation of URL) of source files that
should be add in class path when compile Groovy script. Each
location must point directly to file that contains Groovy
source. Source file can have any name and extensionproperties - optional properties to be applied to loaded resource.
Ignored if state parameter is falsepublic javax.ws.rs.core.Response load(String repository, String workspace, String path, boolean state, javax.ws.rs.core.MultivaluedMap<String,String> properties, org.exoplatform.services.rest.ext.groovy.SourceFolder[] src, org.exoplatform.services.rest.ext.groovy.SourceFile[] files)
repository - repository nameworkspace - workspace namepath - the path to JCR node that contains groovy script to be
deployedstate - true if resource should be loaded and
false otherwise. If this attribute is not present
in HTTP request then it will be considered as trueproperties - optional properties to be applied to loaded resource.
Ignored if state parameter is falsesrc - set of folders that contains Groovy source files that should be
add in class-path when compile file located at path
. NOTE To be able load Groovy source files from specified
folders the following rules must be observed:
files - set of groovy source files that should be add in class-path
when compile file located at path. Each item must
point directly to file that contains Groovy source, see
ClassPathEntry.getPath() . Source file can have any name and
extensionpublic javax.ws.rs.core.Response deleteScript(String repository, String workspace, String path)
repository - repository nameworkspace - workspace namepath - JCR path to node that contains scriptpublic javax.ws.rs.core.Response autoload(String repository, String workspace, String path, boolean state)
repository - repository nameworkspace - workspace namepath - JCR path to node that contains scriptstate - value for property exo:autoload, if it is not specified then
'true' will be used as default.
Example: .../scripts/groovy/test1.groovy/load is the same to
.../scripts/groovy/test1.groovy/load?state=truepublic javax.ws.rs.core.Response getScript(String repository, String workspace, String path)
repository - repository nameworkspace - workspace namepath - JCR path to node that contains scriptpublic javax.ws.rs.core.Response getScriptMetadata(String repository, String workspace, String path)
repository - repository nameworkspace - workspace namepath - JCR path to node that contains scriptpublic javax.ws.rs.core.Response list(String repository, String workspace, String name)
repository - repository nameworkspace - workspace namename - additional search parameter. If not empty method returns the
list of script names matching wildcard else returns all the
scripts found in workspace.protected static String getPath(String fullPath)
fullPath - full path to nodeCopyright © 2020 eXo Platform SAS. All Rights Reserved.