Class GroovyJaxrsPublisher
- java.lang.Object
-
- org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher
-
public class GroovyJaxrsPublisher extends Object
Manage viaResourceBinderGroovy based RESTful services.- Version:
- $Id$
- Author:
- Andrey Parfonov
-
-
Field Summary
Fields Modifier and Type Field Description protected org.exoplatform.services.rest.impl.ResourceBinderbinderprotected GroovyClassLoaderProviderclassLoaderProviderprotected static CharsetDEFAULT_CHARSETDefault character set.protected static StringDEFAULT_CHARSET_NAMEDefault character set name.protected org.exoplatform.services.script.groovy.GroovyScriptInstantiatorinstantiatorprotected Map<ResourceId,String>resources
-
Constructor Summary
Constructors Constructor Description GroovyJaxrsPublisher(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator)Create GroovyJaxrsPublisher which is able publish per-request and singleton resources.GroovyJaxrsPublisher(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator, GroovyClassLoaderProvider classLoaderProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected groovy.lang.GroovyCodeSourcecreateCodeSource(URL url)CreateGroovyCodeSourcefrom given location (URL).protected ObjectcreateInstance(Class clazz)groovy.lang.GroovyClassLoadergetGroovyClassLoader()Deprecated.org.exoplatform.services.rest.ObjectFactory<org.exoplatform.services.rest.resource.AbstractResourceDescriptor>getResource(ResourceId resourceId)Get resource corresponded to specified idresourceId.booleanisPublished(ResourceId resourceId)Check is groovy resource with specified id is published or notvoidpublishPerRequest(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)Parse given stream and publish result as per-request RESTful service.voidpublishPerRequest(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)Parse given stream and publish result as per-request RESTful service.voidpublishPerRequest(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)Parse givensourceand publish result as per-request RESTful service.voidpublishPerRequest(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)Parse givensourceand publish result as per-request RESTful service.voidpublishPerRequest(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)Parse givensourceand publish result as per-request RESTful service.voidpublishPerRequest(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)Parse givensourceand publish result as per-request RESTful service.voidpublishSingleton(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)Parse given stream and publish result as singleton RESTful service.voidpublishSingleton(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)Parse given stream and publish result as singleton RESTful service.voidpublishSingleton(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)Parse givensourceand publish result as singleton RESTful service.voidpublishSingleton(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)Parse givensourceand publish result as singleton RESTful service.voidpublishSingleton(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)Parse givensourceand publish result as singleton RESTful service.voidpublishSingleton(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)Parse givensourceand publish result as singleton RESTful service.voidsetGroovyClassLoader(groovy.lang.GroovyClassLoader gcl)Deprecated.org.exoplatform.services.rest.ObjectFactory<org.exoplatform.services.rest.resource.AbstractResourceDescriptor>unpublishResource(ResourceId resourceId)Unpublish resource with specified id.voidvalidateResource(InputStream in, String name)Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.voidvalidateResource(InputStream in, String name, SourceFolder[] src, SourceFile[] files)Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.voidvalidateResource(String source, String name)Validate doessourcecontain Groovy source code which is conforms with requirement to JAX-RS resource.voidvalidateResource(String source, String charset, String name, SourceFolder[] src, SourceFile[] files)Validate doessourcecontain Groovy source code which is conforms with requirement to JAX-RS resource.voidvalidateResource(String source, String name, SourceFolder[] src, SourceFile[] files)Validate doessourcecontain Groovy source code which is conforms with requirement to JAX-RS resource.
-
-
-
Field Detail
-
DEFAULT_CHARSET_NAME
protected static final String DEFAULT_CHARSET_NAME
Default character set name.- See Also:
- Constant Field Values
-
DEFAULT_CHARSET
protected static final Charset DEFAULT_CHARSET
Default character set.
-
binder
protected final org.exoplatform.services.rest.impl.ResourceBinder binder
-
instantiator
protected final org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator
-
classLoaderProvider
protected final GroovyClassLoaderProvider classLoaderProvider
-
resources
protected final Map<ResourceId,String> resources
-
-
Constructor Detail
-
GroovyJaxrsPublisher
public GroovyJaxrsPublisher(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator, GroovyClassLoaderProvider classLoaderProvider)
-
GroovyJaxrsPublisher
public GroovyJaxrsPublisher(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator)Create GroovyJaxrsPublisher which is able publish per-request and singleton resources. Any required dependencies for per-request resource injected byPerRequestObjectFactory, instance of singleton resources will be created byGroovyScriptInstantiator.- Parameters:
binder- resource binderinstantiator- instantiate java object from given groovy source
-
-
Method Detail
-
getGroovyClassLoader
@Deprecated public groovy.lang.GroovyClassLoader getGroovyClassLoader()
Deprecated.- Returns:
- get underling groovy class loader
-
setGroovyClassLoader
@Deprecated public void setGroovyClassLoader(groovy.lang.GroovyClassLoader gcl)
Deprecated.Set groovy class loader.- Parameters:
gcl- groovy class loader- Throws:
NullPointerException- ifgcl == null
-
getResource
public org.exoplatform.services.rest.ObjectFactory<org.exoplatform.services.rest.resource.AbstractResourceDescriptor> getResource(ResourceId resourceId)
Get resource corresponded to specified idresourceId.- Parameters:
resourceId- resource id- Returns:
- resource or
null
-
isPublished
public boolean isPublished(ResourceId resourceId)
Check is groovy resource with specified id is published or not- Parameters:
resourceId- id of resource to be checked- Returns:
trueif resource is published andfalseotherwise
-
publishPerRequest
public void publishPerRequest(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given stream and publish result as per-request RESTful service.- Parameters:
in- stream which contains groovy source code of RESTful serviceresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benull- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Class, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishPerRequest
public void publishPerRequest(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
Parse given stream and publish result as per-request RESTful service.- Parameters:
in- stream which contains Groovy source code of RESTful serviceresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benullsrc- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Class, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishPerRequest
public final void publishPerRequest(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse givensourceand publish result as per-request RESTful service.- Parameters:
source- groovy source code of RESTful serviceresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benull- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Class, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishPerRequest
public final void publishPerRequest(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
Parse givensourceand publish result as per-request RESTful service.- Parameters:
source- groovy source code of RESTful serviceresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benullsrc- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Class, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishPerRequest
public final void publishPerRequest(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse givensourceand publish result as per-request RESTful service.- Parameters:
source- groovy source code of RESTful servicecharset- source string charset. May benullthan default charset will be in useresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benull.- Throws:
UnsupportedCharsetException- ifcharsetis unsupportedNullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Class, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishPerRequest
public final void publishPerRequest(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
Parse givensourceand publish result as per-request RESTful service.- Parameters:
source- groovy source code of RESTful servicecharset- source string charset. May benullthan default charset will be in useresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benull.src- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
UnsupportedCharsetException- ifcharsetis unsupportedNullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Class, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishSingleton
public void publishSingleton(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given stream and publish result as singleton RESTful service.- Parameters:
in- stream which contains groovy source code of RESTful serviceresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benull- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Object, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishSingleton
public void publishSingleton(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
Parse given stream and publish result as singleton RESTful service.- Parameters:
in- stream which contains groovy source code of RESTful serviceresourceId- id to be assigned to resourceproperties- optional resource properties. This parameter may benullsrc- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Object, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishSingleton
public final void publishSingleton(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse givensourceand publish result as singleton RESTful service.- Parameters:
source- groovy source code of RESTful serviceresourceId- name of resourceproperties- optional resource properties. This parameter may benull.- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Object, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishSingleton
public final void publishSingleton(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
Parse givensourceand publish result as singleton RESTful service.- Parameters:
source- groovy source code of RESTful serviceresourceId- name of resourceproperties- optional resource properties. This parameter may benull.src- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
NullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Object, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishSingleton
public final void publishSingleton(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse givensourceand publish result as singleton RESTful service.- Parameters:
source- groovy source code of RESTful servicecharset- source string charset. May benullthan default charset will be in useresourceId- name of resourceproperties- optional resource properties. This parameter may benull.- Throws:
UnsupportedCharsetException- ifcharsetis unsupportedNullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Object, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
publishSingleton
public final void publishSingleton(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
Parse givensourceand publish result as singleton RESTful service.- Parameters:
source- groovy source code of RESTful servicecharset- source string charset. May benullthan default charset will be in useresourceId- name of resourceproperties- optional resource properties. This parameter may benull.src- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
UnsupportedCharsetException- ifcharsetis unsupportedNullPointerException- ifresourceId == nullorg.exoplatform.services.rest.impl.ResourcePublicationException- seeResourceBinder.addResource(Object, MultivaluedMap)org.codehaus.groovy.control.CompilationFailedException- if compilation fails from source errors
-
unpublishResource
public org.exoplatform.services.rest.ObjectFactory<org.exoplatform.services.rest.resource.AbstractResourceDescriptor> unpublishResource(ResourceId resourceId)
Unpublish resource with specified id.- Parameters:
resourceId- id of resource to be unpublished- Returns:
trueif resource was published andfalseotherwise, e.g. because there is not resource corresponded to suppliedresourceId
-
validateResource
public void validateResource(InputStream in, String name, SourceFolder[] src, SourceFile[] files) throws MalformedScriptException
Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.- Parameters:
in- Groovy source streamname- 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 isnullthen GroovyClassLoader will use automatically generated namesrc- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
MalformedScriptException- if source has errors or there is no required JAX-RS annotation
-
validateResource
public void validateResource(InputStream in, String name) throws MalformedScriptException
Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.- Parameters:
in- Groovy source streamname- 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 isnullthen GroovyClassLoader will use automatically generated name- Throws:
MalformedScriptException- if source has errors or there is no required JAX-RS annotation
-
validateResource
public final void validateResource(String source, String charset, String name, SourceFolder[] src, SourceFile[] files) throws MalformedScriptException
Validate doessourcecontain Groovy source code which is conforms with requirement to JAX-RS resource.- Parameters:
source- Groovy source code as Stringcharset- source string charset. May benullthan default charset will be in usename- 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 isnullthen GroovyClassLoader will use automatically generated namesrc- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
MalformedScriptException- if source has errors or there is no required JAX-RS annotation
-
validateResource
public final void validateResource(String source, String name, SourceFolder[] src, SourceFile[] files) throws MalformedScriptException
Validate doessourcecontain Groovy source code which is conforms with requirement to JAX-RS resource.- Parameters:
source- Groovy source code as Stringname- 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 isnullthen GroovyClassLoader will use automatically generated namesrc- additional path to Groovy sourcesfiles- Groovy source files to be added in build path directly- Throws:
MalformedScriptException- if source has errors or there is no required JAX-RS annotation
-
validateResource
public final void validateResource(String source, String name) throws MalformedScriptException
Validate doessourcecontain Groovy source code which is conforms with requirement to JAX-RS resource.- Parameters:
source- Groovy source code as Stringname- 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 isnullthen GroovyClassLoader will use automatically generated name- Throws:
MalformedScriptException- if source has errors or there is no required JAX-RS annotation
-
createInstance
protected Object createInstance(Class clazz) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
-
createCodeSource
protected groovy.lang.GroovyCodeSource createCodeSource(URL url) throws IOException
CreateGroovyCodeSourcefrom given location (URL).- Parameters:
url- groovy source url- Returns:
- GroovyCodeSource
- Throws:
IOException
-
-