exo-jcr SVN: r3710 - in kernel/trunk: exo.kernel.commons/src/main/java/org/exoplatform/commons/utils and 12 other directories.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-22 07:47:06 -0500 (Wed, 22 Dec 2010)
New Revision: 3710
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/reflect/AnnotationIntrospector.java
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/SLF4JExoLogFactory.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/mail/impl/MailServiceImpl.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/net/impl/NetServiceImpl.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/jotm/TransactionServiceJotmImpl.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/UnifiedClassLoader.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/EntityResolverImpl.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/JVMRuntimeInfoImpl.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
Log:
EXOJCR-1117: code refactoring - misspelling corrected
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/reflect/AnnotationIntrospector.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/reflect/AnnotationIntrospector.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/reflect/AnnotationIntrospector.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -111,7 +111,7 @@
}
};
- for (Method method : SecurityHelper.doPriviledgedAction(action))
+ for (Method method : SecurityHelper.doPrivilegedAction(action))
{
A annotation = method.getAnnotation(methodAnnotation);
if (annotation != null)
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -34,7 +34,7 @@
{
try
{
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Void>()
+ SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
{
public Void run() throws Exception
{
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -48,7 +48,7 @@
* @return
* @throws IOException
*/
- public static <E> E doPriviledgedIOExceptionAction(PrivilegedExceptionAction<E> action) throws IOException
+ public static <E> E doPrivilegedIOExceptionAction(PrivilegedExceptionAction<E> action) throws IOException
{
try
{
@@ -80,7 +80,7 @@
* @return
* @throws IOException
*/
- public static <E> E doPriviledgedSQLExceptionAction(PrivilegedExceptionAction<E> action) throws SQLException
+ public static <E> E doPrivilegedSQLExceptionAction(PrivilegedExceptionAction<E> action) throws SQLException
{
try
{
@@ -112,7 +112,7 @@
* @return
* @throws IOException
*/
- public static <E> E doPriviledgedParserConfigurationOrSAXExceptionAction(PrivilegedExceptionAction<E> action)
+ public static <E> E doPrivilegedParserConfigurationOrSAXExceptionAction(PrivilegedExceptionAction<E> action)
throws ParserConfigurationException, SAXException
{
try
@@ -149,7 +149,7 @@
* @return
* @throws IOException
*/
- public static <E> E doPriviledgedParserConfigurationAction(PrivilegedExceptionAction<E> action)
+ public static <E> E doPrivilegedParserConfigurationAction(PrivilegedExceptionAction<E> action)
throws ParserConfigurationException
{
try
@@ -182,7 +182,7 @@
* @return
* @throws IOException
*/
- public static <E> E doPriviledgedSAXExceptionAction(PrivilegedExceptionAction<E> action) throws SAXException
+ public static <E> E doPrivilegedSAXExceptionAction(PrivilegedExceptionAction<E> action) throws SAXException
{
try
{
@@ -214,7 +214,7 @@
* @return
* @throws IOException
*/
- public static <E> E doPriviledgedMalformedURLExceptionAction(PrivilegedExceptionAction<E> action)
+ public static <E> E doPrivilegedMalformedURLExceptionAction(PrivilegedExceptionAction<E> action)
throws MalformedURLException
{
try
@@ -246,7 +246,7 @@
* @param action
* @return
*/
- public static <E> E doPriviledgedAction(PrivilegedAction<E> action)
+ public static <E> E doPrivilegedAction(PrivilegedAction<E> action)
{
return AccessController.doPrivileged(action);
}
@@ -258,7 +258,7 @@
* @param action
* @return
*/
- public static <E> E doPriviledgedExceptionAction(PrivilegedExceptionAction<E> action)
+ public static <E> E doPrivilegedExceptionAction(PrivilegedExceptionAction<E> action)
throws PrivilegedActionException
{
return AccessController.doPrivileged(action);
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -37,7 +37,7 @@
{
public void configure(final Properties properties)
{
- SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Object>()
{
public Object run()
{
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/SLF4JExoLogFactory.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/SLF4JExoLogFactory.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/SLF4JExoLogFactory.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -43,7 +43,7 @@
@Override
protected Log getLogger(final String name)
{
- Logger slf4jlogger = SecurityHelper.doPriviledgedAction(new PrivilegedAction<Logger>()
+ Logger slf4jlogger = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Logger>()
{
public Logger run()
{
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/mail/impl/MailServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/mail/impl/MailServiceImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/mail/impl/MailServiceImpl.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -62,7 +62,7 @@
String username = props_.getProperty("mail.smtp.auth.username");
String password = props_.getProperty("mail.smtp.auth.password");
final ExoAuthenticator auth = new ExoAuthenticator(username, password);
- mailSession_ = SecurityHelper.doPriviledgedAction(new PrivilegedAction<Session>()
+ mailSession_ = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Session>()
{
public Session run()
{
@@ -72,7 +72,7 @@
}
else
{
- mailSession_ = SecurityHelper.doPriviledgedAction(new PrivilegedAction<Session>()
+ mailSession_ = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Session>()
{
public Session run()
{
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/net/impl/NetServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/net/impl/NetServiceImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/net/impl/NetServiceImpl.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -38,7 +38,7 @@
try
{
startTime = System.currentTimeMillis();
- Socket socket = SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Socket>()
+ Socket socket = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Socket>()
{
public Socket run() throws Exception
{
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -755,7 +755,7 @@
}
});
- SecurityHelper.doPriviledgedAction(new PrivilegedAction<Void>()
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
public Void run()
{
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/jotm/TransactionServiceJotmImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/jotm/TransactionServiceJotmImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/jotm/TransactionServiceJotmImpl.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -69,7 +69,7 @@
{
try
{
- SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Void>()
+ SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
{
public Void run() throws Exception
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -163,7 +163,7 @@
this.webAppContexts = Collections.singleton(new WebAppInitContext(portalContext));
this.portalContext = portalContext;
this.portalMergedContext = new PortalContainerContext(this);
- this.portalMergedClassLoader = SecurityHelper.doPriviledgedAction(new PrivilegedAction<ClassLoader>()
+ this.portalMergedClassLoader = SecurityHelper.doPrivilegedAction(new PrivilegedAction<ClassLoader>()
{
public ClassLoader run()
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -114,7 +114,7 @@
log.info("Active profiles " + profiles);
//
- SecurityHelper.doPriviledgedAction(new PrivilegedAction<Void>()
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
public Void run()
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -206,7 +206,7 @@
if ((path == null) || (path.length() == 0))
return;
- URL confURL = SecurityHelper.doPriviledgedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
+ URL confURL = SecurityHelper.doPrivilegedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
{
public URL run() throws Exception
{
@@ -319,7 +319,7 @@
{
try
{
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Void>()
+ SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
{
public Void run() throws Exception
{
@@ -352,7 +352,7 @@
// (2) exo-configuration.xml in AS (standalone) home directory
configurationURL =
- SecurityHelper.doPriviledgedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
+ SecurityHelper.doPrivilegedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
{
public URL run() throws Exception
{
@@ -364,7 +364,7 @@
if (!fileExists(configurationURL))
{
configurationURL =
- SecurityHelper.doPriviledgedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
+ SecurityHelper.doPrivilegedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
{
public URL run() throws Exception
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/UnifiedClassLoader.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/UnifiedClassLoader.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/UnifiedClassLoader.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -116,7 +116,7 @@
static protected UnifiedClassLoader createUnifiedClassLoaderInPrivilegedMode(final ClassLoader... cls)
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<UnifiedClassLoader>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<UnifiedClassLoader>()
{
public UnifiedClassLoader run()
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -304,7 +304,7 @@
+ ") could not be found or the invoker doesn't have adequate privileges to get the resource");
}
- return SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<InputStream>()
+ return SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<InputStream>()
{
public InputStream run() throws Exception
{
@@ -328,7 +328,7 @@
{
final String path = removePrefix("jar:/", url);
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<URL>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<URL>()
{
public URL run()
{
@@ -340,7 +340,7 @@
{
final String path = removePrefix("classpath:/", url);
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<URL>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<URL>()
{
public URL run()
{
@@ -354,7 +354,7 @@
if (context != null)
{
final String fPath = path;
- return SecurityHelper.doPriviledgedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
+ return SecurityHelper.doPrivilegedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>()
{
public URL run() throws Exception
{
@@ -370,7 +370,7 @@
path = path.substring(1);
}
final String fPath = path;
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<URL>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<URL>()
{
public URL run()
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -187,7 +187,7 @@
Reporter reporter = new Reporter(url);
builder.setErrorHandler(reporter);
builder.setEntityResolver(Namespaces.resolver);
- builder.parse(SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<InputStream>()
+ builder.parse(SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<InputStream>()
{
public InputStream run() throws Exception
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/EntityResolverImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/EntityResolverImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/EntityResolverImpl.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -69,7 +69,7 @@
final String path = systemIdToResourcePath.get(systemId);
if (path != null)
{
- InputStream in = SecurityHelper.doPriviledgedAction(new PrivilegedAction<InputStream>()
+ InputStream in = SecurityHelper.doPrivilegedAction(new PrivilegedAction<InputStream>()
{
public InputStream run()
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -161,7 +161,7 @@
}
final Object[] params = {cplugin};
- SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Void>()
+ SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
{
public Void run() throws Exception
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -113,7 +113,7 @@
//
try
{
- Class clazz = SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Class>()
+ Class clazz = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Class>()
{
public Class run() throws Exception
{
@@ -170,7 +170,7 @@
}
if (mbeanServer == null)
{
- mbeanServer = SecurityHelper.doPriviledgedAction(new PrivilegedAction<MBeanServer>()
+ mbeanServer = SecurityHelper.doPrivilegedAction(new PrivilegedAction<MBeanServer>()
{
public MBeanServer run()
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/JVMRuntimeInfoImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/JVMRuntimeInfoImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/JVMRuntimeInfoImpl.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -61,7 +61,7 @@
public String getName()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -72,7 +72,7 @@
public String getSpecName()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -83,7 +83,7 @@
public String getSpecVendor()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -94,7 +94,7 @@
public String getSpecVersion()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -105,7 +105,7 @@
public String getManagementSpecVersion()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -116,7 +116,7 @@
public String getVmName()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -127,7 +127,7 @@
public String getVmVendor()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -138,7 +138,7 @@
public String getVmVersion()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -149,7 +149,7 @@
public List getInputArguments()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<List>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<List>()
{
public List run()
{
@@ -160,7 +160,7 @@
public Map getSystemProperties()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<Map>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<Map>()
{
public Map run()
{
@@ -171,7 +171,7 @@
public boolean getBootClassPathSupported()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<Boolean>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<Boolean>()
{
public Boolean run()
{
@@ -182,7 +182,7 @@
public String getBootClassPath()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -193,7 +193,7 @@
public String getClassPath()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -204,7 +204,7 @@
public String getLibraryPath()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
@@ -215,7 +215,7 @@
public long getStartTime()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<Long>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<Long>()
{
public Long run()
{
@@ -226,7 +226,7 @@
public long getUptime()
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<Long>()
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<Long>()
{
public Long run()
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -76,7 +76,7 @@
{
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Collection c = SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Collection>()
+ Collection c = SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Collection>()
{
public Collection run() throws IOException
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -155,7 +155,7 @@
}
try
{
- SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Void>()
+ SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
{
public Void run() throws Exception
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java 2010-12-22 11:56:25 UTC (rev 3709)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java 2010-12-22 12:47:06 UTC (rev 3710)
@@ -253,7 +253,7 @@
final Field fld = field[i];
- SecurityHelper.doPriviledgedAction(new PrivilegedAction<Void>()
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
public Void run()
{
15 years, 5 months
exo-jcr SVN: r3709 - in jcr/trunk: exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-22 06:56:25 -0500 (Wed, 22 Dec 2010)
New Revision: 3709
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
Log:
EXOJCR-747: revert: restore single workspace into existed one in case of multi-db is not supported
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-12-22 11:55:56 UTC (rev 3708)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-12-22 11:56:25 UTC (rev 3709)
@@ -64,7 +64,6 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
@@ -757,41 +756,6 @@
PrivilegedFileHelper.mkdirs(dir);
config.setBackupDir(dir);
- try
- {
- // check if it is RDBMS backup of single workspace in case of multi-db configuration
- if ((Class.forName(fullBackupType)
- .equals(org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob.class)))
- {
- WorkspaceEntry wEntry = null;
- for (WorkspaceEntry entry : repoService.getRepository(config.getRepository()).getConfiguration()
- .getWorkspaceEntries())
- {
- if (entry.getName().equals(config.getWorkspace()))
- {
- wEntry = entry;
- break;
- }
- }
-
- if (wEntry == null)
- {
- throw new WorkspaceRestoreException("Workspace " + config.getWorkspace()
- + " did not found in current repository " + config.getRepository() + " configuration");
- }
-
- if (Boolean.parseBoolean(wEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB)))
- {
- throw new BackupOperationException(
- "Backup of single workspace in case of multi-db configuration is not supported");
- }
- }
- }
- catch (ClassNotFoundException e)
- {
- throw new BackupOperationException("Class " + fullBackupType + " is not found.", e);
- }
-
BackupChain bchain =
new BackupChainImpl(config, logsDirectory, repoService,
fullBackupType, incrementalBackupType, IdGenerator.generate(), logsDirectory, startTime);
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-12-22 11:55:56 UTC (rev 3708)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-12-22 11:56:25 UTC (rev 3709)
@@ -25,7 +25,6 @@
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.WorkspaceRestoreException;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -101,29 +100,6 @@
+ " did not found in current repository " + repositoryName + " configuration");
}
- boolean isMultiDb;
- try
- {
- String multiDb = wEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
- if (multiDb == null)
- {
- throw new RepositoryConfigurationException("Parameter " + JDBCWorkspaceDataContainer.MULTIDB
- + " not found in workspace configuration " + wEntry.getName());
- }
-
- isMultiDb = Boolean.parseBoolean(multiDb);
- }
- catch (RepositoryConfigurationException e)
- {
- throw new WorkspaceRestoreException("Can't define " + JDBCWorkspaceDataContainer.MULTIDB + " parameter", e);
- }
-
- if (isMultiDb)
- {
- throw new WorkspaceRestoreException(
- "Restore of single workspace into existed one for multi-db is not supported");
- }
-
boolean isSystem =
repositoryService.getRepository(repositoryName).getConfiguration().getSystemWorkspaceName()
.equals(wEntry.getName());
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-22 11:55:56 UTC (rev 3708)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-22 11:56:25 UTC (rev 3709)
@@ -1275,7 +1275,12 @@
public void testExistedWorkspaceRestoreMultiDB() throws Exception
{
String repositoryNameToBackup = "db8";
+ SessionImpl ws1Session =
+ (SessionImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials, "ws1");
+ ws1Session.getRootNode().addNode("TESTNODE");
+ ws1Session.save();
+
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -1326,15 +1331,26 @@
assertNotNull(bchLog.getStartedTime());
assertNotNull(bchLog.getFinishedTime());
+ backup.restoreExistingWorkspace(bchLog, repositoryNameToBackup, ws1, false);
+
+ // check
+ SessionImpl back1 = null;
try
{
- backup.restoreExistingWorkspace(bchLog, repositoryNameToBackup, ws1, false);
- fail("Exception should be thrown");
+ back1 = (SessionImpl)repositoryService.getRepository("db8").login(credentials, "ws1");
+ Node ws1backTestRoot = back1.getRootNode().getNode("TESTNODE");
}
- catch (WorkspaceRestoreException e)
+ catch (Exception e)
{
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
- }
}
else
fail("There are no backup files in " + backDir.getAbsolutePath());
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java 2010-12-22 11:55:56 UTC (rev 3708)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java 2010-12-22 11:56:25 UTC (rev 3709)
@@ -20,8 +20,6 @@
import org.exoplatform.container.xml.PropertiesParam;
import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
-import java.io.File;
-
/**
* Created by The eXo Platform SAS.
*
@@ -54,29 +52,4 @@
return backupManagerImpl;
}
- // @Override
- public void testExistedWorkspaceRestoreMultiDB() throws Exception
- {
- String repositoryNameToBackup = "db8";
-
- // backup
- File backDir = new File("target/backup/" + System.currentTimeMillis());
- backDir.mkdirs();
-
- BackupConfig config = new BackupConfig();
- config.setRepository(repositoryNameToBackup);
- config.setWorkspace(workspaceNameToBackup);
- config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
-
- config.setBackupDir(backDir);
-
- try
- {
- backup.startBackup(config);
- fail("Exception should be thrown");
- }
- catch (BackupOperationException e)
- {
- }
- }
}
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-12-22 11:55:56 UTC (rev 3708)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-12-22 11:56:25 UTC (rev 3709)
@@ -483,11 +483,6 @@
<section>
<title>Restore existing workspace or repository</title>
- <note>
- <para>Restoring single workspace into existed one in case of multi-db is
- not supported.</para>
- </note>
-
<para>The resore of existing workspace or repositry is available.</para>
<para>For restore will be used spacial methods:</para>
15 years, 5 months
exo-jcr SVN: r3708 - in jcr/trunk: exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-22 06:55:56 -0500 (Wed, 22 Dec 2010)
New Revision: 3708
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml
Log:
EXOJCR-939: revert: clean data for single workspace in case of multi-db is not supported
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2010-12-22 11:34:50 UTC (rev 3707)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2010-12-22 11:55:56 UTC (rev 3708)
@@ -65,28 +65,6 @@
security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
}
- boolean isMultiDb;
- try
- {
- String multiDb = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
- if (multiDb == null)
- {
- throw new RepositoryConfigurationException("Parameter " + JDBCWorkspaceDataContainer.MULTIDB
- + " not found in workspace configuration " + wsEntry.getName());
- }
-
- isMultiDb = Boolean.parseBoolean(multiDb);
- }
- catch (RepositoryConfigurationException e)
- {
- throw new DBCleanerException("Can't define " + JDBCWorkspaceDataContainer.MULTIDB + " parameter", e);
- }
-
- if (isMultiDb)
- {
- throw new DBCleanerException("Clean of single workspace for multi-db is not supported");
- }
-
getDBCleaner(wsEntry).clean();
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java 2010-12-22 11:34:50 UTC (rev 3707)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java 2010-12-22 11:55:56 UTC (rev 3708)
@@ -23,7 +23,6 @@
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
-import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerException;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
@@ -250,18 +249,21 @@
Statement statement = conn.createStatement();
ResultSet res = statement.executeQuery("select * from JCR_MITEM where ID='" + id + "'");
assertTrue(res.next());
- statement.close();
// remove workspace data from database
+ new DBCleanerService().cleanWorkspaceData(repositoryEntry.getWorkspaceEntries().get(0));
+
+ // check - does JCR_SITEM become empty
try
{
- new DBCleanerService().cleanWorkspaceData(repositoryEntry.getWorkspaceEntries().get(0));
- fail("Exception should be thrown");
+ res = statement.executeQuery("select * from JCR_MITEM where ID='" + id + "'");
+ fail();
}
- catch (DBCleanerException e)
+ catch (SQLException e)
{
-
+ //ok
}
+ statement.close();
service.removeRepository(repositoryName);
}
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml 2010-12-22 11:34:50 UTC (rev 3707)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml 2010-12-22 11:55:56 UTC (rev 3708)
@@ -62,10 +62,4 @@
</listitem>
</itemizedlist></para>
</section>
-
- <section>
- <title>Limitation</title>
-
- <para>Clean of single workspace for multi-db is not supported.</para>
- </section>
</chapter>
15 years, 5 months
exo-jcr SVN: r3707 - jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-22 06:34:50 -0500 (Wed, 22 Dec 2010)
New Revision: 3707
Modified:
jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java
Log:
JCR-1502 : Bug in BackupClientImpl was fixed.
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java 2010-12-22 11:33:16 UTC (rev 3706)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java 2010-12-22 11:34:50 UTC (rev 3707)
@@ -466,10 +466,11 @@
String backupSetPath, boolean removeExists)
throws IOException, BackupExecuteException
{
+ BackupAgentResponse response = null;
+ String sURL = null;
+
if (workspaceName != null)
{
- String sURL = null;
- BackupAgentResponse response = null;
if (config != null)
{
if (backupId != null )
@@ -511,38 +512,9 @@
response = transport.executePOST(sURL, json.toString());
}
- else
- {
- if (backupId != null)
- {
- sURL =
- path + HTTPBackupAgent.Constants.BASE_URL + HTTPBackupAgent.Constants.OperationType.RESTORE
- + "/" + backupId + "/" + removeExists;
- }
- else if (backupSetPath != null)
- {
- sURL =
- path + HTTPBackupAgent.Constants.BASE_URL
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + repositoryName
- + "/" + backupSetPath + "/" + removeExists;
- }
-
- response = transport.executeGET(sURL);
- }
-
- if (response.getStatus() == Response.Status.OK.getStatusCode())
- {
- return "\nSuccessful : \n" + "\tstatus code = " + response.getStatus() + "\n";
- }
- else
- {
- return failureProcessing(response);
- }
}
- else
+ else if (repositoryName != null)
{
- String sURL = null;
- BackupAgentResponse response = null;
if (config != null)
{
if (backupId != null)
@@ -586,35 +558,76 @@
response = transport.executePOST(sURL, json.toString());
}
- else
+ }
+ else
+ {
+ if (backupId != null)
{
- if (backupId != null)
+
+ //check is repository or workspace backup
+ boolean isRepository = true;
+
+ String lsURL =
+ path + HTTPBackupAgent.Constants.BASE_URL
+ + HTTPBackupAgent.Constants.OperationType.CURRENT_OR_COMPLETED_BACKUP_REPOSITORY_INFO
+ + "/" + backupId;
+
+ BackupAgentResponse lResponse = transport.executeGET(lsURL);
+
+ if (lResponse.getStatus() != Response.Status.OK.getStatusCode())
{
+
sURL =
path + HTTPBackupAgent.Constants.BASE_URL
+ + HTTPBackupAgent.Constants.OperationType.CURRENT_OR_COMPLETED_BACKUP_INFO + "/"
+ + backupId;
+
+ lResponse = transport.executeGET(sURL);
+
+ if (lResponse.getStatus() == Response.Status.OK.getStatusCode())
+ {
+ isRepository = false;
+ }
+ else
+ {
+ return failureProcessing(lResponse);
+ }
+ }
+
+ if (isRepository)
+ {
+ sURL =
+ path + HTTPBackupAgent.Constants.BASE_URL
+ HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY + "/" + backupId + "/"
+ removeExists;
}
- else if (backupSetPath != null)
+ else
{
sURL =
- path + HTTPBackupAgent.Constants.BASE_URL
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET
- + "/" + backupSetPath + "/" + removeExists;
+ path + HTTPBackupAgent.Constants.BASE_URL + HTTPBackupAgent.Constants.OperationType.RESTORE
+ + "/" + backupId + "/" + removeExists;
}
- response = transport.executeGET(sURL);
}
-
- if (response.getStatus() == Response.Status.OK.getStatusCode())
+ else if (backupSetPath != null)
{
- return "\nSuccessful : \n" + "\tstatus code = " + response.getStatus() + "\n";
+ sURL =
+ path + HTTPBackupAgent.Constants.BASE_URL
+ + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + backupSetPath + "/"
+ + removeExists;
}
- else
- {
- return failureProcessing(response);
- }
+
+ response = transport.executeGET(sURL);
}
+
+ if (response.getStatus() == Response.Status.OK.getStatusCode())
+ {
+ return "\nSuccessful : \n" + "\tstatus code = " + response.getStatus() + "\n";
+ }
+ else
+ {
+ return failureProcessing(response);
+ }
}
/**
15 years, 5 months
exo-jcr SVN: r3706 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-22 06:33:16 -0500 (Wed, 22 Dec 2010)
New Revision: 3706
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
Log:
JCR-1502 : Remove commented code in HTTPBackupAgent.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-12-22 10:57:44 UTC (rev 3705)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-12-22 11:33:16 UTC (rev 3706)
@@ -1808,129 +1808,6 @@
}
/**
- * Restore the repository.
- *
- * @param rEntry
- * RepositoryEntry, the configuration to restored repository
- * @param repository
- * String, the repository name
- * @param backupId
- * String, the identifier of backup
- * @param removeExisting
- * Boolean, if 'true' will be removed fully (db, value storage, index) existed repository.
- * @return Response return the response
- */
- /*
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- @RolesAllowed("administrators")
- @Path("/restore-repository-from-backup-set/{backup-set-path:.*}/{remove-Existing}")
- public Response restoreRepositoryFromBackupSet(@PathParam("backup-set-path") String backupSetPath,
- @PathParam("remove-Existing") Boolean removeExisting)
- {
- String failMessage;
- Response.Status status;
- Throwable exception;
-
- String repository = null;
-
- try
- {
- File backupSetDir = (new File(backupSetPath));
-
- if (!backupSetDir.exists())
- {
- throw new WorkspaceRestoreException("Backup set directory is not exists :" + backupSetPath);
- }
-
- if (!backupSetDir.isDirectory())
- {
- throw new WorkspaceRestoreException("Backup set directory is not directory :" + backupSetPath);
- }
-
- File[] cfs = PrivilegedFileHelper.listFiles(backupSetDir, new RepositoryBackupLogsFilter());
-
- if (cfs.length == 0)
- {
- throw new BackupConfigurationException("Can not found repository backup log in directory : "
- + backupSetPath);
- }
-
- if (cfs.length > 1)
- {
- throw new BackupConfigurationException(
- "Backup set directory should contains only one repository backup log : " + backupSetPath);
- }
-
- RepositoryBackupChainLog backupChainLog = new RepositoryBackupChainLog(cfs[0]);
- repository = backupChainLog.getBackupConfig().getRepository();
-
- validateOneRepositoryRestoreInstants(repository);
-
- if (removeExisting)
- {
- if (!isRepositoryExist(repository))
- {
- throw new RepositoryRestoreExeption("Repository " + repository + " is not exists!");
- }
-
- backupManager.restoreExistingRepository(backupSetDir, true);
- }
- else
- {
- if (isRepositoryExist(repository))
- {
- throw new RepositoryRestoreExeption("Repository " + repository + " already exists!");
- }
-
- backupManager.restoreRepository(backupSetDir, true);
- }
-
- // Sleeping. Restore should be initialized by job thread
- Thread.sleep(100);
-
- // search necessary restore
- JobRepositoryRestore restore = backupManager.getLastRepositoryRestore(repository);
- ShortInfo info =
- new ShortInfo(ShortInfo.RESTORE, restore.getRepositoryBackupChainLog(), restore.getStartTime(),
- restore.getEndTime(), restore.getStateRestore(), restore.getRepositoryName());
-
- return Response.ok(info).cacheControl(noCache).build();
- }
- catch (RepositoryRestoreExeption e)
- {
- exception = e;
- status = Response.Status.FORBIDDEN;
- failMessage = e.getMessage();
- }
- catch (RepositoryException e)
- {
- exception = e;
- status = Response.Status.NOT_FOUND;
- failMessage = e.getMessage();
- }
- catch (RepositoryConfigurationException e)
- {
- exception = e;
- status = Response.Status.NOT_FOUND;
- failMessage = e.getMessage();
- }
- catch (Throwable e)
- {
- exception = e;
- status = Response.Status.INTERNAL_SERVER_ERROR;
- failMessage = e.getMessage();
- }
-
- log.error("Can not start restore the repository '" + "/" + repository + "' from backup set '" + backupSetPath
- + "'", exception);
-
- return Response.status(status).entity(
- "Can not start restore the repository '" + "/" + repository + "' from backup set '" + backupSetPath
- + "' : " + failMessage).type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
- }*/
-
- /**
* The backup stop by 'id'.
*
* @param backupId
15 years, 5 months
exo-jcr SVN: r3705 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/backup and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-22 05:57:44 -0500 (Wed, 22 Dec 2010)
New Revision: 3705
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
Log:
EXOJCR-1078: small fixes
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java 2010-12-22 10:54:30 UTC (rev 3704)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java 2010-12-22 10:57:44 UTC (rev 3705)
@@ -94,15 +94,15 @@
}
catch (RepositoryConfigurationException e1)
{
- throw new RepositoryException("Can't rollback changes", e);
+ log.error("Can't rollback changes", e1);
}
catch (DBCleanerException e1)
{
- throw new RepositoryException("Can't rollback changes", e);
+ log.error("Can't rollback changes", e1);
}
catch (IOException e1)
{
- throw new RepositoryException("Can't rollback changes", e);
+ log.error("Can't rollback changes", e1);
}
throw new RepositoryException(e);
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-22 10:54:30 UTC (rev 3704)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-22 10:57:44 UTC (rev 3705)
@@ -141,15 +141,15 @@
}
catch (RepositoryConfigurationException e1)
{
- throw new RepositoryException("Can't rollback changes", e);
+ log.error("Can't rollback changes", e1);
}
catch (DBCleanerException e1)
{
- throw new RepositoryException("Can't rollback changes", e);
+ log.error("Can't rollback changes", e1);
}
catch (IOException e1)
{
- throw new RepositoryException("Can't rollback changes", e);
+ log.error("Can't rollback changes", e1);
}
throw new RepositoryException(e);
}
@@ -806,6 +806,7 @@
}
}
insertNode.addBatch();
+
}
insertNode.executeBatch();
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-12-22 10:54:30 UTC (rev 3704)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-12-22 10:57:44 UTC (rev 3705)
@@ -237,7 +237,7 @@
ArrayList qParams = new ArrayList();
// qParams.add(new SimpleParameterEntry("indexDir", "target" + File.separator+ "temp" +
// File.separator +"index" + name));
- qParams.add(new SimpleParameterEntry(QueryHandlerParams.PARAM_INDEX_DIR, "target" + File.separator + name
+ qParams.add(new SimpleParameterEntry(QueryHandlerParams.PARAM_INDEX_DIR, "target/temp/index/" + name
+ System.currentTimeMillis()));
QueryHandlerEntry qEntry =
new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
@@ -272,7 +272,7 @@
ValueStorageEntry valueStorageEntry =
new ValueStorageEntry("org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage", vsparams);
ArrayList<SimpleParameterEntry> spe = new ArrayList<SimpleParameterEntry>();
- spe.add(new SimpleParameterEntry("path", "target/temp/swap/" + name + "_" + System.currentTimeMillis()));
+ spe.add(new SimpleParameterEntry("path", "target/temp/values/" + name + "_" + System.currentTimeMillis()));
valueStorageEntry.setId("draft");
valueStorageEntry.setParameters(spe);
valueStorageEntry.setFilters(vsparams);
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-22 10:54:30 UTC (rev 3704)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-22 10:57:44 UTC (rev 3705)
@@ -190,7 +190,7 @@
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
- <property name="swap-directory" value="target/temp2/swap/ws" />
+ <property name="swap-directory" value="target/temp/swap/db2_ws" />
</properties>
</container>
<cache enabled="true">
@@ -201,7 +201,7 @@
</cache>
<query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
- <property name="index-dir" value="target/temp2/index/ws" />
+ <property name="index-dir" value="target/temp/index/db2_ws" />
</properties>
</query-handler>
</workspace>
15 years, 5 months
exo-jcr SVN: r3704 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-22 05:54:30 -0500 (Wed, 22 Dec 2010)
New Revision: 3704
Added:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
Log:
EXOJCR-1102: add load test
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2010-12-22 10:54:30 UTC (rev 3704)
@@ -0,0 +1,323 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.load;
+
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.AbstractBackupTestCase;
+import org.exoplatform.services.jcr.ext.backup.BackupChain;
+import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.BackupConfig;
+import org.exoplatform.services.jcr.ext.backup.BackupJob;
+import org.exoplatform.services.jcr.ext.backup.BackupManager;
+import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
+import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.core.PropertyImpl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestLoadBackup.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestLoadBackup extends AbstractBackupTestCase
+{
+ protected final String REPOSITORY_NAME = "db7";
+
+ protected final String WORKSPACE_NAME = "ws1";
+
+ protected final int WRITER_COUNT = 100;
+
+ protected final String FULL_BACKUP_TYPE = "org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob";
+
+ protected final int BACKUP_TYPE = BackupManager.FULL_BACKUP_ONLY;
+
+ protected final boolean RESTORE_INTO_EXISTED = false;
+
+ protected ManageableRepository repository;
+
+ /**
+ * Writer.
+ */
+ class TreeWriterThread extends Thread
+ {
+ private Session session;
+
+ private final String nodeName;
+
+ public TreeWriterThread(Session session, String nodeName) throws RepositoryException
+ {
+ this.session = session;
+ this.nodeName = nodeName;
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ while (true)
+ {
+ Node rootChild = session.getRootNode().addNode(nodeName + System.currentTimeMillis());
+ session.save();
+
+ addChilds(session, rootChild, 0);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Test Backup/Restore.
+ *
+ * @throws Exception
+ */
+ public void testBackupRestore() throws Exception
+ {
+ BackupManagerImpl backupManagerImpl = null;
+
+ List<TreeWriterThread> threads = new ArrayList<TreeWriterThread>();
+ List<Session> sessions = new ArrayList<Session>();
+
+ //writers
+ for (int i = 0; i < WRITER_COUNT; i++)
+ {
+ Session writerSession = repository.login(credentials, WORKSPACE_NAME);
+ TreeWriterThread writer = new TreeWriterThread(writerSession, "subnode" + i);
+ writer.start();
+ threads.add(writer);
+ sessions.add(writerSession);
+ }
+
+ Thread.sleep(5 * 1000);
+
+ System.out.println(" ============ BACKUP START ============");
+
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+ BackupChain bch = null;
+
+ backupManagerImpl = (BackupManagerImpl)getBackupManager();
+ backupManagerImpl.start();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(REPOSITORY_NAME);
+ config.setWorkspace(WORKSPACE_NAME);
+ config.setBackupType(BACKUP_TYPE);
+ config.setBackupDir(backDir);
+
+ backupManagerImpl.startBackup(config);
+
+ bch = backupManagerImpl.findBackup(REPOSITORY_NAME, WORKSPACE_NAME);
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(30);
+ }
+
+ System.out.println(" ============ FULL BACKUP FINISHED ============");
+
+ if (BACKUP_TYPE == BackupManager.FULL_AND_INCREMENTAL)
+ {
+ Thread.sleep(30 * 1000);
+ }
+
+ // stop backup
+ if (bch != null)
+ {
+ backupManagerImpl.stopBackup(bch);
+ }
+ else
+ {
+ fail("Can't get fullBackup chain");
+ }
+ Thread.sleep(5 * 1000);
+
+ System.out.println(" ============ BACKUP FINISHED ============");
+
+ // for (Thread thread : threads)
+ // {
+ // thread.interrupt();
+ // }
+
+ // restore
+ WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back", "jdbcjcr3");
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ System.out.println(" ============ RESTORE START ============");
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restore(bchLog, repositoryNameToBackup, ws1back, false);
+ }
+ else
+ {
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ System.out.println(" ============ CHECKING INTEGRITY ============");
+
+ checkIntegrity((NodeImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials, "ws1back")
+ .getRootNode());
+ }
+
+ protected void addChilds(Session session, Node root, int layer) throws Exception
+ {
+ if (layer == 4)
+ {
+ return;
+ }
+
+ for (int i = 0; i < 10; i++)
+ {
+ Node n = root.addNode("testNode" + i);
+ n.addMixin("mix:referenceable");
+ n.addMixin("mix:versionable");
+ n.setProperty("long", i);
+ n.setProperty("ref", n);
+ n.setProperty("string", new String[]{"test" + System.currentTimeMillis()});
+ n.setProperty("stream", new FileInputStream(createBLOBTempFile(1 * 1024)));
+
+ session.save();
+
+ n.checkin();
+ n.checkout();
+
+ Thread.sleep(50);
+
+ addChilds(session, n, layer + 1);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ExtendedBackupManager getBackupManager()
+ {
+ InitParams initParams = new InitParams();
+ PropertiesParam pps = new PropertiesParam();
+ pps.setProperty(BackupManagerImpl.FULL_BACKUP_TYPE, FULL_BACKUP_TYPE);
+ pps.setProperty(BackupManagerImpl.INCREMENTAL_BACKUP_TYPE,
+ "org.exoplatform.services.jcr.ext.backup.impl.fs.IncrementalBackupJob");
+ pps.setProperty(BackupManagerImpl.BACKUP_DIR, "target/backup");
+ pps.setProperty(BackupManagerImpl.DEFAULT_INCREMENTAL_JOB_PERIOD, "3600");
+
+ initParams.put(BackupManagerImpl.BACKUP_PROPERTIES, pps);
+
+ return new BackupManagerImpl(initParams, repositoryService);
+ }
+
+ /**
+ * Check integrity. Get all values from all properties.
+ *
+ * @param node
+ * @throws RepositoryException
+ */
+ protected void checkIntegrity(NodeImpl node) throws RepositoryException
+ {
+ Iterator<NodeImpl> iterator = node.getNodes();
+ while (iterator.hasNext())
+ {
+ NodeImpl newNode = iterator.next();
+ if (newNode.isNodeType(Constants.MIX_VERSIONABLE)
+ && !newNode.getData().getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
+ {
+ VersionHistory verHist = newNode.getVersionHistory();
+
+ NodeImpl verNode = null;
+ try
+ {
+ verNode = (NodeImpl)verHist.getVersion("1");
+ checkIntegrity(verNode);
+ }
+ catch (VersionException e)
+ {
+ }
+ }
+
+ checkIntegrity(newNode);
+
+ Iterator<PropertyImpl> propIt = newNode.getProperties();
+ while (propIt.hasNext())
+ {
+ PropertyImpl prop = propIt.next();
+ if (prop.isMultiValued())
+ {
+ for (Value value : prop.getValues())
+ {
+ value.toString();
+ }
+ }
+ else
+ {
+ prop.getValue().toString();
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ repository = repositoryService.getRepository(REPOSITORY_NAME);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void tearDown() throws Exception
+ {
+ }
+}
15 years, 5 months
exo-jcr SVN: r3702 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/script/groovy and 1 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-22 05:24:13 -0500 (Wed, 22 Dec 2010)
New Revision: 3702
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyTest.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-1105
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-12-22 10:15:37 UTC (rev 3701)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -35,6 +35,7 @@
import org.exoplatform.services.jcr.ext.registry.RegistryService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
import org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher;
import org.exoplatform.services.rest.ext.groovy.ResourceId;
import org.exoplatform.services.rest.impl.ResourceBinder;
@@ -95,6 +96,14 @@
@Path("script/groovy")
public class GroovyScript2RestLoader implements Startable
{
+ protected static class InnerGroovyJaxrsPublisher extends GroovyJaxrsPublisher
+ {
+ public InnerGroovyJaxrsPublisher(ResourceBinder binder, GroovyScriptInstantiator instantiator,
+ GroovyClassLoaderProvider classLoaderProvider)
+ {
+ super(binder, instantiator, classLoaderProvider);
+ }
+ }
/** Logger. */
static final Log LOG = ExoLogger.getLogger("exo.jcr.component.ext.GroovyScript2RestLoader");
@@ -149,7 +158,8 @@
InitParams params)
{
this(binder, groovyScriptInstantiator, repositoryService, sessionProviderService, configurationManager, null,
- new GroovyJaxrsPublisher(binder, groovyScriptInstantiator), jcrUrlHandler, params);
+ new InnerGroovyJaxrsPublisher(binder, groovyScriptInstantiator, new JcrGroovyClassLoaderProvider()),
+ jcrUrlHandler, params);
}
/**
@@ -167,7 +177,8 @@
org.exoplatform.services.jcr.ext.resource.jcr.Handler jcrUrlHandler, InitParams params)
{
this(binder, groovyScriptInstantiator, repositoryService, sessionProviderService, configurationManager,
- registryService, new GroovyJaxrsPublisher(binder, groovyScriptInstantiator), jcrUrlHandler, params);
+ registryService, new InnerGroovyJaxrsPublisher(binder, groovyScriptInstantiator,
+ new JcrGroovyClassLoaderProvider()), jcrUrlHandler, params);
}
public GroovyScript2RestLoader(ResourceBinder binder, GroovyScriptInstantiator groovyScriptInstantiator,
@@ -186,9 +197,9 @@
/**
* Remove script with specified URL from ResourceBinder.
- *
+ *
* @param url the URL. The <code>url.toString()</code> must be corresponded
- * to script class.
+ * to script class.
* @see GroovyScriptRestLoader#loadScript(URL).
* @deprecated
*/
@@ -199,7 +210,7 @@
/**
* Remove script by specified key from ResourceBinder.
- *
+ *
* @param key the key with which script was created.
* @see GroovyScript2RestLoader#loadScript(String, InputStream)
* @see GroovyScript2RestLoader#loadScript(String, String, InputStream)
@@ -253,7 +264,7 @@
/**
* Get node type for store scripts, may throw {@link IllegalStateException}
* if <tt>nodeType</tt> not initialized yet.
- *
+ *
* @return return node type
*/
public String getNodeType()
@@ -286,7 +297,7 @@
/**
* Load script from given stream.
- *
+ *
* @param key the key which must be corresponded to object class name.
* @param stream the stream which represents groovy script.
* @return if script loaded false otherwise
@@ -301,10 +312,10 @@
/**
* Load script from given stream.
- *
+ *
* @param key the key which must be corresponded to object class name.
* @param name this name will be passed to compiler to get understandable if
- * compilation failed
+ * compilation failed
* @param stream the stream which represents groovy script.
* @return if script loaded false otherwise
* @throws IOException if script can't be loaded or parsed.
@@ -424,10 +435,12 @@
repositoryName, workspaceName, node), null);
}
- session.getWorkspace().getObservationManager().addEventListener(
- new GroovyScript2RestUpdateListener(repositoryName, workspaceName, this, session),
- Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, "/", true, null,
- new String[]{getNodeType()}, false);
+ session
+ .getWorkspace()
+ .getObservationManager()
+ .addEventListener(new GroovyScript2RestUpdateListener(repositoryName, workspaceName, this, session),
+ Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, "/", true, null,
+ new String[]{getNodeType()}, false);
}
}
catch (Exception e)
@@ -552,7 +565,7 @@
/**
* Create JCR node.
- *
+ *
* @param parent parent node
* @param name name of node to be created
* @param stream data stream for property jcr:data
@@ -572,7 +585,7 @@
/**
* Read parameters from RegistryService.
- *
+ *
* @param sessionProvider the SessionProvider
* @throws RepositoryException
* @throws PathNotFoundException
@@ -622,7 +635,7 @@
/**
* Write parameters to RegistryService.
- *
+ *
* @param sessionProvider the SessionProvider
* @throws ParserConfigurationException
* @throws SAXException
@@ -637,8 +650,7 @@
LOG.debug(">>> Save init parametrs in registry service.");
}
- Document doc = SecurityHelper.doPriviledgedParserConfigurationAction(new PrivilegedExceptionAction<Document>()
- {
+ Document doc = SecurityHelper.doPriviledgedParserConfigurationAction(new PrivilegedExceptionAction<Document>() {
public Document run() throws Exception
{
return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
@@ -675,7 +687,7 @@
/**
* Get attribute value.
- *
+ *
* @param element The element to get attribute value
* @param attr The attribute name
* @return Value of attribute if present and null in other case
@@ -687,7 +699,7 @@
/**
* Set attribute value. If value is null the attribute will be removed.
- *
+ *
* @param element The element to set attribute value
* @param attr The attribute name
* @param value The value of attribute
@@ -735,7 +747,7 @@
* This method is useful for clients that can send script in request body
* without form-data. At required to set specific Content-type header
* 'script/groovy'.
- *
+ *
* @param stream the stream that contains groovy source code
* @param uriInfo see {@link UriInfo}
* @param repository repository name
@@ -805,8 +817,7 @@
try
{
final String fName = name;
- SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Void>()
- {
+ SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception
{
groovyClassLoader.parseClass(script, fName);
@@ -828,7 +839,7 @@
* This method is useful for clients that can send script in request body
* without form-data. At required to set specific Content-type header
* 'script/groovy'.
- *
+ *
* @param stream the stream that contains groovy source code
* @param uriInfo see {@link UriInfo}
* @param repository repository name
@@ -883,7 +894,7 @@
* script. This method is created just for comfort loading script from HTML
* form. NOT use this script for uploading few files in body of
* 'multipart/form-data' or other type of multipart.
- *
+ *
* @param items iterator {@link FileItem}
* @param uriInfo see {@link UriInfo}
* @param repository repository name
@@ -954,7 +965,7 @@
* script. This method is created just for comfort loading script from HTML
* form. NOT use this script for uploading few files in body of
* 'multipart/form-data' or other type of multipart.
- *
+ *
* @param items iterator {@link FileItem}
* @param uriInfo see {@link UriInfo}
* @param repository repository name
@@ -1010,7 +1021,7 @@
/**
* Get source code of groovy script.
- *
+ *
* @param repository repository name
* @param workspace workspace name
* @param path JCR path to node that contains script
@@ -1029,8 +1040,9 @@
sessionProviderService.getSessionProvider(null).getSession(workspace,
repositoryService.getRepository(repository));
Node scriptFile = (Node)ses.getItem("/" + path);
- return Response.status(Response.Status.OK).entity(
- scriptFile.getNode("jcr:content").getProperty("jcr:data").getStream()).type("script/groovy").build();
+ return Response.status(Response.Status.OK)
+ .entity(scriptFile.getNode("jcr:content").getProperty("jcr:data").getStream()).type("script/groovy")
+ .build();
}
catch (PathNotFoundException e)
{
@@ -1055,7 +1067,7 @@
/**
* Get groovy script's meta-information.
- *
+ *
* @param repository repository name
* @param workspace workspace name
* @param path JCR path to node that contains script
@@ -1105,7 +1117,7 @@
/**
* Remove node that contains groovy script.
- *
+ *
* @param repository repository name
* @param workspace workspace name
* @param path JCR path to node that contains script
@@ -1150,14 +1162,14 @@
* Change exo:autoload property. If this property is 'true' script will be
* deployed automatically when JCR repository startup and automatically
* re-deployed when script source code changed.
- *
+ *
* @param repository repository name
* @param workspace workspace name
* @param path JCR path to node that contains script
* @param state value for property exo:autoload, if it is not specified then
- * 'true' will be used as default. <br />
- * Example: .../scripts/groovy/test1.groovy/load is the same to
- * .../scripts/groovy/test1.groovy/load?state=true
+ * 'true' will be used as default. <br />
+ * Example: .../scripts/groovy/test1.groovy/load is the same to
+ * .../scripts/groovy/test1.groovy/load?state=true
*/
@POST
@Path("autoload/{repository}/{workspace}/{path:.*}")
@@ -1201,16 +1213,16 @@
* script will be deployed as REST service if 'false' the script will be
* undeployed. NOTE is script already deployed and <tt>state</tt> is
* <tt>true</tt> script will be re-deployed.
- *
+ *
* @param repository repository name
* @param workspace workspace name
* @param path the path to JCR node that contains groovy script to be
- * deployed
+ * deployed
* @param state <code>true</code> if resource should be loaded and
- * <code>false</code> otherwise. If this attribute is not present in
- * HTTP request then it will be considered as <code>true</code>
+ * <code>false</code> otherwise. If this attribute is not present
+ * in HTTP request then it will be considered as <code>true</code>
* @param properties optional properties to be applied to loaded resource.
- * Ignored if <code>state</code> parameter is false
+ * Ignored if <code>state</code> parameter is false
*/
@POST
@Path("load/{repository}/{workspace}/{path:.*}")
@@ -1236,9 +1248,9 @@
{
if (null == groovyPublisher.unpublishResource(key))
{
- return Response.status(Response.Status.BAD_REQUEST).entity(
- "Can't unbind script " + path + ", not bound or has wrong mapping to the resource class ").type(
- MediaType.TEXT_PLAIN).build();
+ return Response.status(Response.Status.BAD_REQUEST)
+ .entity("Can't unbind script " + path + ", not bound or has wrong mapping to the resource class ")
+ .type(MediaType.TEXT_PLAIN).build();
}
}
return Response.status(Response.Status.NO_CONTENT).build();
@@ -1276,12 +1288,12 @@
/**
* Returns the list of all groovy-scripts found in workspace.
- *
+ *
* @param repository Repository name.
* @param workspace Workspace name.
* @param name Additional search parameter. If not emtpy method returns the
- * list of script names matching wildcard else returns all the scripts
- * found in workspace.
+ * list of script names matching wildcard else returns all the
+ * scripts found in workspace.
* @return
*/
@POST
@@ -1367,7 +1379,7 @@
/**
* Extract path to node's parent from full path.
- *
+ *
* @param fullPath full path to node
* @return node's parent path
*/
@@ -1379,7 +1391,7 @@
/**
* Extract node's name from full node path.
- *
+ *
* @param fullPath full path to node
* @return node's name
*/
@@ -1459,7 +1471,7 @@
/**
* Returns the list of scripts.
- *
+ *
* @return the list of scripts.
*/
public List<String> getList()
@@ -1469,7 +1481,7 @@
/**
* ScriptList constructor.
- *
+ *
* @param the list of scripts
*/
public ScriptList(List<String> scriptList)
Added: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.script.groovy;
+
+import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
+
+import java.net.MalformedURLException;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class JcrClassPathEntry extends ClassPathEntry
+{
+ public JcrClassPathEntry(EntryType type, UnifiedNodeReference path) throws MalformedURLException
+ {
+ super(type, path.getURL());
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.script.groovy;
+
+import groovy.lang.GroovyClassLoader;
+
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
+import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class JcrGroovyClassLoaderProvider extends GroovyClassLoaderProvider
+{
+ /**
+ * @see org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider#getGroovyClassLoader(org.exoplatform.services.rest.ext.groovy.ClassPathEntry[])
+ */
+ @Override
+ public GroovyClassLoader getGroovyClassLoader(ClassPathEntry[] classPath) throws MalformedURLException
+ {
+ List<URL> files = new ArrayList<URL>();
+ List<URL> roots = new ArrayList<URL>();
+ for (int i = 0; i < classPath.length; i++)
+ {
+ ClassPathEntry classPathEntry = classPath[i];
+ if (EntryType.SRC_DIR == classPathEntry.getType())
+ {
+ roots.add(classPathEntry.getPath());
+ }
+ else
+ {
+ files.add(classPathEntry.getPath());
+ }
+ }
+ final GroovyClassLoader parent = getGroovyClassLoader();
+ GroovyClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
+ public GroovyClassLoader run()
+ {
+ return new GroovyClassLoader(parent);
+ }
+ });
+ classLoader.setResourceLoader(new JcrGroovyResourceLoader(roots.toArray(new URL[roots.size()]), files
+ .toArray(new URL[files.size()])));
+ return classLoader;
+ }
+}
\ No newline at end of file
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java 2010-12-22 10:15:37 UTC (rev 3701)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -23,22 +23,23 @@
import groovy.lang.GroovyCodeSource;
import org.codehaus.groovy.control.CompilationFailedException;
-import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.services.jcr.ext.resource.JcrURLConnection;
import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
+import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
import org.picocontainer.Startable;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -46,7 +47,7 @@
/**
* JcrGroovyCompiler can load source code of groovy script from JCR and parse it
* via GroovyClassLoader.
- *
+ *
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id$
*/
@@ -55,36 +56,43 @@
/** Logger. */
private static final Log LOG = ExoLogger.getLogger(JcrGroovyCompiler.class);
- protected GroovyClassLoader gcl;
+ protected final GroovyClassLoaderProvider classLoaderProvider;
protected List<GroovyScriptAddRepoPlugin> addRepoPlugins;
- public JcrGroovyCompiler()
+ protected JcrGroovyCompiler(GroovyClassLoaderProvider classLoaderProvider)
{
- this.gcl = SecurityHelper.doPriviledgedAction(new PrivilegedAction<GroovyClassLoader>()
- {
- public GroovyClassLoader run()
- {
- return new GroovyClassLoader(getClass().getClassLoader());
- }
- });
+ this.classLoaderProvider = classLoaderProvider;
}
- public void addPlugin(ComponentPlugin cp)
+ public JcrGroovyCompiler()
{
- if (cp instanceof GroovyScriptAddRepoPlugin)
- {
- if (addRepoPlugins == null)
- {
- addRepoPlugins = new ArrayList<GroovyScriptAddRepoPlugin>();
- }
- addRepoPlugins.add((GroovyScriptAddRepoPlugin)cp);
- }
+ classLoaderProvider = new JcrGroovyClassLoaderProvider();
}
public Class<?>[] compile(UnifiedNodeReference... sourceReferences) throws IOException
{
- final GroovyClassLoader cl = getGroovyClassLoader();
+ // Add all compiled entries in class-path. Need to do this to resolve dependencies between compiled files.
+ ClassPathEntry[] classPath = new ClassPathEntry[sourceReferences.length];
+ for (int i = 0; i < classPath.length; i++)
+ classPath[i] = new JcrClassPathEntry(EntryType.FILE, sourceReferences[i]);
+ return doCompile(classLoaderProvider.getGroovyClassLoader(classPath), sourceReferences);
+ }
+
+ public Class<?>[] compile(ClassPathEntry[] classPath, UnifiedNodeReference... sourceReferences) throws IOException
+ {
+ ClassPathEntry[] compiled = new ClassPathEntry[sourceReferences.length];
+ for (int i = 0; i < compiled.length; i++)
+ compiled[i] = new JcrClassPathEntry(EntryType.FILE, sourceReferences[i]);
+ ClassPathEntry[] fullClassPath = new ClassPathEntry[compiled.length + classPath.length];
+ System.arraycopy(compiled, 0, fullClassPath, 0, compiled.length);
+ System.arraycopy(classPath, 0, fullClassPath, compiled.length, classPath.length);
+ return doCompile(classLoaderProvider.getGroovyClassLoader(fullClassPath), sourceReferences);
+ }
+
+ private Class<?>[] doCompile(final GroovyClassLoader cl, final UnifiedNodeReference... sourceReferences)
+ throws IOException
+ {
Class<?>[] classes = new Class<?>[sourceReferences.length];
for (int i = 0; i < sourceReferences.length; i++)
{
@@ -98,8 +106,7 @@
Class<?> clazz;
try
{
- clazz = SecurityHelper.doPriviledgedExceptionAction(new PrivilegedExceptionAction<Class<?>>()
- {
+ clazz = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws Exception
{
return cl.parseClass(createCodeSource(fConn.getInputStream(), url.toString()));
@@ -110,30 +117,20 @@
{
Throwable cause = pae.getCause();
if (cause instanceof CompilationFailedException)
- {
throw (CompilationFailedException)cause;
- }
else if (cause instanceof IOException)
- {
throw (IOException)cause;
- }
else if (cause instanceof RuntimeException)
- {
throw (RuntimeException)cause;
- }
else
- {
throw new RuntimeException(cause);
- }
}
classes[i] = clazz;
}
finally
{
if (conn != null)
- {
conn.disconnect();
- }
}
}
return classes;
@@ -142,24 +139,49 @@
/**
* @return get underling groovy class loader
*/
+ @Deprecated
public GroovyClassLoader getGroovyClassLoader()
{
- return gcl;
+ return classLoaderProvider.getGroovyClassLoader();
}
/**
* Set groovy class loader.
- *
+ *
* @param gcl groovy class loader
* @throws NullPointerException if <code>gcl == null</code>
*/
+ @Deprecated
public void setGroovyClassLoader(GroovyClassLoader gcl)
{
- if (gcl == null)
- throw new NullPointerException("GroovyClassLoader may not be null.");
- this.gcl = gcl;
+ classLoaderProvider.setGroovyClassLoader(gcl);
}
+ /**
+ * Create {@link GroovyCodeSource} from given stream and name. Code base
+ * 'file:/groovy/script' (default code base used for all Groovy classes) will
+ * be used.
+ *
+ * @param in groovy source code stream
+ * @param name code source name
+ * @return GroovyCodeSource
+ */
+ // Override this method if need other behavior.
+ protected GroovyCodeSource createCodeSource(final InputStream in, final String name)
+ {
+ GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
+ public GroovyCodeSource run()
+ {
+ return new GroovyCodeSource(in, name, "/groovy/script");
+ }
+ });
+ gcs.setCachable(false);
+ return gcs;
+ }
+
+ /**
+ * @see org.picocontainer.Startable#start()
+ */
public void start()
{
if (addRepoPlugins != null && addRepoPlugins.size() > 0)
@@ -168,10 +190,9 @@
{
Set<URL> repos = new HashSet<URL>();
for (GroovyScriptAddRepoPlugin pl : addRepoPlugins)
- {
repos.addAll(pl.getRepositories());
- }
- getGroovyClassLoader().setResourceLoader(new JcrGroovyResourceLoader(repos.toArray(new URL[repos.size()])));
+ classLoaderProvider.getGroovyClassLoader().setResourceLoader(
+ new JcrGroovyResourceLoader(repos.toArray(new URL[repos.size()])));
}
catch (MalformedURLException e)
{
@@ -180,31 +201,10 @@
}
}
- public void stop()
- {
- }
-
/**
- * Create {@link GroovyCodeSource} from given stream and name. Code base
- * 'file:/groovy/script' (default code base used for all Groovy classes) will
- * be used.
- *
- * @param in groovy source code stream
- * @param name code source name
- * @return GroovyCodeSource
+ * @see org.picocontainer.Startable#stop()
*/
- // Override this method if need other behavior.
- protected GroovyCodeSource createCodeSource(final InputStream in, final String name)
+ public void stop()
{
- GroovyCodeSource gcs = SecurityHelper.doPriviledgedAction(new PrivilegedAction<GroovyCodeSource>()
- {
- public GroovyCodeSource run()
- {
- return new GroovyCodeSource(in, name, "/groovy/script");
- }
- });
-
- gcs.setCachable(false);
- return gcs;
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java 2010-12-22 10:15:37 UTC (rev 3701)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -19,6 +19,8 @@
package org.exoplatform.services.jcr.ext.script.groovy;
import org.exoplatform.services.jcr.ext.resource.JcrURLConnection;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.ext.groovy.DefaultGroovyResourceLoader;
import java.io.IOException;
@@ -31,6 +33,7 @@
*/
public class JcrGroovyResourceLoader extends DefaultGroovyResourceLoader
{
+ private static final Log LOG = ExoLogger.getLogger(JcrGroovyResourceLoader.class);
private static URL[] normalizeJcrURL(URL[] src) throws MalformedURLException
{
@@ -58,72 +61,89 @@
return res;
}
+ public JcrGroovyResourceLoader(URL[] roots, URL[] files) throws MalformedURLException
+ {
+ super(normalizeJcrURL(roots), files);
+ }
+
public JcrGroovyResourceLoader(URL[] roots) throws MalformedURLException
{
- super(normalizeJcrURL(roots));
+ this(roots, new URL[0]);
}
+ public JcrGroovyResourceLoader(URL root) throws MalformedURLException
+ {
+ this(new URL[]{root}, new URL[0]);
+ }
+
+ /**
+ * @see org.exoplatform.services.rest.ext.groovy.DefaultGroovyResourceLoader#getResource(java.lang.String)
+ */
@Override
protected URL getResource(String filename) throws MalformedURLException
{
+ if (LOG.isDebugEnabled())
+ LOG.debug("Process file: " + filename);
+
+ URL resource = null;
filename = filename.intern();
- URL resource = null;
synchronized (filename)
{
resource = resources.get(filename);
boolean inCache = resource != null;
- for (URL root : roots)
+ if (inCache && !checkResource(resource))
+ resource = null;
+ for (int i = 0; i < files.length && resource == null; i++)
{
- if (resource == null)
- {
- if ("jcr".equals(root.getProtocol()))
- {
- // In JCR URL path represented by fragment
- // jcr://repository/workspace#/path
- String ref = root.getRef();
- resource = new URL(root, "#" + ref + filename);
- }
- else
- {
- resource = new URL(root, filename);
- }
- }
- URLConnection connection = null;
- try
- {
- if (GroovyScript2RestLoader.LOG.isDebugEnabled())
- GroovyScript2RestLoader.LOG.debug("Try to load resource from URL : " + resource);
-
- connection = resource.openConnection();
- connection.getInputStream().close();
-
- break;
- }
- catch (IOException e)
- {
- if (GroovyScript2RestLoader.LOG.isDebugEnabled())
- GroovyScript2RestLoader.LOG.debug("Can't open URL : " + resource);
-
- resource = null;
- }
- finally
- {
- if (connection != null && resource != null && "jcr".equals(resource.getProtocol()))
- {
- ((JcrURLConnection)connection).disconnect();
- }
- }
+ URL tmp = files[i];
+ if (tmp.toString().endsWith(filename) && checkResource(tmp))
+ resource = tmp;
}
+ for (int i = 0; i < roots.length && resource == null; i++)
+ {
+ // In JCR URL path represented by fragment jcr://repository/workspace#/path
+ URL tmp =
+ ("jcr".equals(roots[i].getProtocol())) ? new URL(roots[i], "#" + roots[i].getRef() + filename)
+ : new URL(roots[i], filename);
+ if (checkResource(tmp))
+ resource = tmp;
+ }
if (resource != null)
- {
resources.put(filename, resource);
- }
else if (inCache)
- {
- // Remove from map if resource is unreachable
resources.remove(filename);
- }
}
return resource;
}
+
+ /**
+ * @see org.exoplatform.services.rest.ext.groovy.DefaultGroovyResourceLoader#checkResource(java.net.URL)
+ */
+ @Override
+ protected boolean checkResource(URL resource)
+ {
+ URLConnection connection = null;
+ try
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Try to load resource from URL : " + resource);
+
+ connection = resource.openConnection();
+ connection.getInputStream().close();
+
+ return true;
+ }
+ catch (IOException e)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Can't open URL : " + resource);
+
+ return false;
+ }
+ finally
+ {
+ if (connection != null && resource != null && "jcr".equals(resource.getProtocol()))
+ ((JcrURLConnection)connection).disconnect();
+ }
+ }
}
\ No newline at end of file
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyTest.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyTest.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.script.groovy;
+
+import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Calendar;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public abstract class BaseGroovyTest extends BaseStandaloneTest
+{
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ protected String createScript(Node parent, String packageName, String name, String text) throws RepositoryException
+ {
+ return createScript(parent, packageName, name, new ByteArrayInputStream(text.getBytes()));
+ }
+
+ protected String createScript(Node parent, String packageName, String name, InputStream text) throws RepositoryException
+ {
+ Node current = parent;
+ if (packageName != null && packageName.length() > 0)
+ {
+ for (String s : packageName.split("\\."))
+ {
+ if (!current.hasNode(s))
+ current = current.addNode(s, "nt:folder");
+ else
+ current = current.getNode(s);
+ }
+ }
+ Node script = current.addNode(name + ".groovy", "nt:file");
+ Node scriptContent = script.addNode("jcr:content", "nt:resource");
+ scriptContent.setProperty("jcr:mimeType", "script/groovy");
+ scriptContent.setProperty("jcr:lastModified", Calendar.getInstance());
+ scriptContent.setProperty("jcr:data", text);
+ session.save();
+ return script.getPath();
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java 2010-12-22 10:15:37 UTC (rev 3701)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -21,56 +21,104 @@
import groovy.lang.GroovyObject;
-import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
+import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
-import java.util.Calendar;
-
import javax.jcr.Node;
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id$
*/
-public class GroovyCompilerTest extends BaseStandaloneTest
+public class GroovyCompilerTest extends BaseGroovyTest
{
+ private Node groovyRepo;
+
+ private Node otherGroovyRepo;
+
+ private String scriptA;
+
+ private String scriptB;
+
public void setUp() throws Exception
{
super.setUp();
- Node groovyRepo = root.addNode("groovyRepo", "nt:folder");
- Node org = groovyRepo.addNode("org", "nt:folder");
- Node exo = org.addNode("exoplatform", "nt:folder");
- Node a = exo.addNode("A.groovy", "nt:file");
- a = a.addNode("jcr:content", "nt:resource");
- a.setProperty("jcr:mimeType", "script/groovy");
- a.setProperty("jcr:lastModified", Calendar.getInstance());
- a.setProperty("jcr:data", //
+ groovyRepo = root.addNode("groovyRepo", "nt:folder");
+ otherGroovyRepo = root.addNode("otherGroovyRepo", "nt:folder");
+
+ // Add script in shared "dependency repository".
+ scriptA = createScript(groovyRepo, "org.exoplatform", "A", //
"package org.exoplatform\n" + //
- " class A { String message = 'groovy compiler test' }");
+ "class A { String message = 'groovy compiler test' }");
- Node test = exo.addNode("test", "nt:folder");
- Node b = test.addNode("B.groovy", "nt:file");
- b = b.addNode("jcr:content", "nt:resource");
- b.setProperty("jcr:mimeType", "script/groovy");
- b.setProperty("jcr:lastModified", Calendar.getInstance());
- b.setProperty("jcr:data", //
+ scriptB = createScript(groovyRepo, "org.exoplatform.test", "B", //
"package org.exoplatform.test\n" + //
- " import org.exoplatform.A\n" + //
- " class B extends A {}");
- session.save();
+ "import org.exoplatform.A\n" + //
+ "class B extends A {}");
}
- public void testGroovyDependency() throws Exception
+ public void testSnaredDependencies() throws Exception
{
- JcrGroovyCompiler compiler = new JcrGroovyCompiler();
- compiler.getGroovyClassLoader().setResourceLoader(
+ GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ classLoaderProvider.getGroovyClassLoader().setResourceLoader(
new JcrGroovyResourceLoader(new java.net.URL[]{new java.net.URL("jcr://db1/ws#/groovyRepo")}));
+ JcrGroovyCompiler compiler = new JcrGroovyCompiler(classLoaderProvider);
+
+ Class<?>[] classes = compiler.compile(new UnifiedNodeReference("db1", "ws", scriptB));
+ assertEquals(1, classes.length);
+ GroovyObject go = (GroovyObject)classes[0].newInstance();
+ assertEquals("groovy compiler test", go.invokeMethod("getMessage", new Object[0]));
+ }
+
+ public void testDependenciesBetweenCompiled() throws Exception
+ {
+ GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ JcrGroovyCompiler compiler = new JcrGroovyCompiler(classLoaderProvider);
Class<?>[] classes =
- compiler.compile(new UnifiedNodeReference("db1", "ws", "/groovyRepo/org/exoplatform/test/B.groovy"));
+ compiler.compile(new UnifiedNodeReference("db1", "ws", scriptB),
+ new UnifiedNodeReference("db1", "ws", scriptA));
+ assertEquals(2, classes.length);
+ GroovyObject go = (GroovyObject)classes[0].newInstance();
+ assertEquals("groovy compiler test", go.invokeMethod("getMessage", new Object[0]));
+ go = (GroovyObject)classes[1].newInstance();
+ assertEquals("groovy compiler test", go.invokeMethod("getMessage", new Object[0]));
+ }
+
+ public void testAddDependenciesInRuntime() throws Exception
+ {
+ GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ JcrGroovyCompiler compiler = new JcrGroovyCompiler(classLoaderProvider);
+ Class<?>[] classes = compiler.compile( //
+ new ClassPathEntry[]{new JcrClassPathEntry(EntryType.FILE, new UnifiedNodeReference("db1", "ws", scriptA))}, //
+ new UnifiedNodeReference("db1", "ws", scriptB));
assertEquals(1, classes.length);
GroovyObject go = (GroovyObject)classes[0].newInstance();
assertEquals("groovy compiler test", go.invokeMethod("getMessage", new Object[0]));
}
+ public void testCombinedDependencies() throws Exception
+ {
+ String scriptC = createScript(otherGroovyRepo, "org.exoplatform.test", "C", //
+ "package org.exoplatform.test\n" + //
+ "import org.exoplatform.*\n" + //
+ "class C extends B {}");
+
+ String scriptD = createScript(otherGroovyRepo, "org.exoplatform.test.other", "D", //
+ "package org.exoplatform.test.other\n" + //
+ "import org.exoplatform.test.C\n" + //
+ "class D extends C {}");
+
+ GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ classLoaderProvider.getGroovyClassLoader().setResourceLoader(
+ new JcrGroovyResourceLoader(new java.net.URL[]{new java.net.URL("jcr://db1/ws#/groovyRepo")}));
+
+ JcrGroovyCompiler compiler = new JcrGroovyCompiler(classLoaderProvider);
+ Class<?>[] classes =
+ compiler.compile(new UnifiedNodeReference("db1", "ws", scriptD),
+ new UnifiedNodeReference("db1", "ws", scriptC));
+ assertEquals(2, classes.length);
+ }
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-12-22 10:15:37 UTC (rev 3701)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-12-22 10:24:13 UTC (rev 3702)
@@ -18,7 +18,6 @@
*/
package org.exoplatform.services.jcr.ext.script.groovy;
-import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
import org.exoplatform.services.jcr.ext.app.ThreadLocalSessionProviderService;
import org.exoplatform.services.jcr.ext.common.SessionProvider;
import org.exoplatform.services.jcr.ext.registry.RESTRegistryTest.DummyContainerResponseWriter;
@@ -56,7 +55,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class GroovyScript2RestLoaderTest extends BaseStandaloneTest
+public class GroovyScript2RestLoaderTest extends BaseGroovyTest
{
private Node testRoot;
@@ -111,17 +110,16 @@
providers.addMethodInvokerFilter(new MethodAccessFilter());
session.save();
-
+
Set<String> adminRoles = new HashSet<String>();
adminRoles.add("administrators");
- adminSecurityContext = new DummySecurityContext(new Principal()
- {
+ adminSecurityContext = new DummySecurityContext(new Principal() {
public String getName()
{
return "root";
}
}, adminRoles);
-
+
}
public void testStartQuery() throws Exception
@@ -279,18 +277,13 @@
public void testGroovyDependency() throws Exception
{
// Add script in dependency repository
- Node deps = groovyRepo.addNode("dependencies", "nt:folder");
- Node dep = deps.addNode("Dep1.groovy", "nt:file");
- dep = dep.addNode("jcr:content", "nt:resource");
- dep.setProperty("jcr:mimeType", "script/groovy");
- dep.setProperty("jcr:lastModified", Calendar.getInstance());
- dep.setProperty("jcr:data", "package dependencies; class Dep1 { String name = getClass().getName() }");
+ createScript(groovyRepo, "dependencies", "Dep1", //
+ "package dependencies\n" + //
+ "class Dep1 { String name = getClass().getName() }");
- session.save();
+ script.setProperty("jcr:data",
+ Thread.currentThread().getContextClassLoader().getResourceAsStream("TestDependency.groovy"));
- script.setProperty("jcr:data", Thread.currentThread().getContextClassLoader().getResourceAsStream(
- "TestDependency.groovy"));
-
session.save();
// must be rebounded , not created other one
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-12-22 10:15:37 UTC (rev 3701)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-12-22 10:24:13 UTC (rev 3702)
@@ -40,7 +40,7 @@
<property name="log4j.rootLogger" value="INFO, stdout, file" />
<property name="log4j.appender.stdout" value="org.apache.log4j.ConsoleAppender" />
- <property name="log4j.appender.stdout.threshold" value="INFO" />
+ <property name="log4j.appender.stdout.threshold" value="DEBUG" />
<property name="log4j.appender.stdout.layout" value="org.apache.log4j.PatternLayout" />
<property name="log4j.appender.stdout.layout.ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
@@ -55,6 +55,8 @@
<property name="log4j.category.ext.BackupManagerImpl" value="DEBUG"/ -->
<property name="log4j.category.jcr.ext.RestRepositoryService" value="DEBUG"/>
+ <!-- property name="log4j.category.org.exoplatform.services.jcr.ext.script.groovy.JcrGroovyResourceLoader" value="DEBUG" / -->
+
</properties-param>
</init-params>
</component>
15 years, 5 months
exo-jcr SVN: r3701 - in ws/trunk/exo.ws.rest.ext/src: test/java/org/exoplatform/services/rest/ext and 2 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-22 05:15:37 -0500 (Wed, 22 Dec 2010)
New Revision: 3701
Added:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/provider/
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProviderTest.java
Removed:
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
Log:
EXOJCR-1105
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java 2010-12-22 10:15:37 UTC (rev 3701)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.groovy;
+
+import java.net.URL;
+
+/**
+ * Item of Groovy classpath. It may describe source file of folder that contains
+ * source files. If <code>ClassPathEntry</code> point to the folder then like
+ * Java package structure is expected.
+ *
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class ClassPathEntry
+{
+ /** Type of class-path entry. */
+ public enum EntryType {
+ SRC_DIR, FILE
+ }
+
+ /** Type of entry. */
+ private EntryType type;
+
+ /** URL. */
+ private URL path;
+
+ public ClassPathEntry(EntryType type, URL path)
+ {
+ this.type = type;
+ this.path = path;
+ }
+
+ public EntryType getType()
+ {
+ return type;
+ }
+
+ public URL getPath()
+ {
+ return path;
+ }
+
+ public void setPath(URL path)
+ {
+ this.path = path;
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-12-22 09:24:37 UTC (rev 3700)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-12-22 10:15:37 UTC (rev 3701)
@@ -22,7 +22,6 @@
import groovy.lang.GroovyResourceLoader;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
@@ -40,28 +39,29 @@
*/
public class DefaultGroovyResourceLoader implements GroovyResourceLoader
{
+ private static final String[] DEFAULT_SCRIPT_EXTENSIONS = new String[]{".groovy"};
protected URL[] roots;
+ protected URL[] files;
+
// TODO need configurable ?
private int maxEntries = 512;
protected final Map<String, URL> resources;
- public DefaultGroovyResourceLoader(URL[] roots) throws MalformedURLException
+ @SuppressWarnings("serial")
+ public DefaultGroovyResourceLoader(URL[] roots, URL[] files) throws MalformedURLException
{
+ this.files = files;
this.roots = new URL[roots.length];
for (int i = 0; i < roots.length; i++)
{
String str = roots[i].toString();
if (str.charAt(str.length() - 1) != '/')
- {
this.roots[i] = new URL(str + '/');
- }
else
- {
this.roots[i] = roots[i];
- }
}
resources = Collections.synchronizedMap(new LinkedHashMap<String, URL>()
{
@@ -72,6 +72,11 @@
});
}
+ public DefaultGroovyResourceLoader(URL[] roots) throws MalformedURLException
+ {
+ this(roots, new URL[0]);
+ }
+
public DefaultGroovyResourceLoader(URL root) throws MalformedURLException
{
this(new URL[]{root});
@@ -82,65 +87,81 @@
*/
public final URL loadGroovySource(String classname) throws MalformedURLException
{
- final String filename = classname.replace('.', '/') + ".groovy";
- try
+ URL resource = null;
+ final String baseName = classname.replace('.', '/');
+ String[] extensions = getScriptExtensions();
+ for (int i = 0; i < extensions.length && resource == null; i++)
{
- return AccessController.doPrivileged(new PrivilegedExceptionAction<URL>()
+ final String ext = extensions[i];
+ try
{
- public URL run() throws Exception
+ resource = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>()
{
- return getResource(filename);
- }
- });
+ public URL run() throws Exception
+ {
+ return getResource(baseName + ext);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof Error)
+ throw (Error)cause;
+ if (cause instanceof RuntimeException)
+ throw (RuntimeException)cause;
+ throw (MalformedURLException)cause;
+ }
}
- catch (PrivilegedActionException e)
- {
- Throwable cause = e.getCause();
- if (cause instanceof Error)
- throw (Error)cause;
- if (cause instanceof RuntimeException)
- throw (RuntimeException)cause;
- throw (MalformedURLException)cause;
- }
+ return resource;
}
protected URL getResource(String filename) throws MalformedURLException
{
+ URL resource = null;
filename = filename.intern();
- URL resource = null;
synchronized (filename)
{
resource = resources.get(filename);
boolean inCache = resource != null;
- for (URL root : roots)
+ if (inCache && !checkResource(resource))
+ resource = null; // Resource in cache is unreachable.
+ for (int i = 0; i < files.length && resource == null; i++)
{
- if (resource == null)
- {
- resource = new URL(root, filename);
- }
- try
- {
- InputStream script = resource.openStream();
- script.close();
- break;
- }
- catch (IOException e)
- {
- resource = null;
- }
+ URL tmp = files[i];
+ if (tmp.toString().endsWith(filename) && checkResource(tmp))
+ resource = tmp;
}
+ for (int i = 0; i < roots.length && resource == null; i++)
+ {
+ URL tmp = new URL(roots[i], filename);
+ if (checkResource(tmp))
+ resource = tmp;
+ }
if (resource != null)
- {
resources.put(filename, resource);
- }
else if (inCache)
- {
- // Remove from map if resource is unreachable
resources.remove(filename);
- }
}
return resource;
}
+ protected boolean checkResource(URL resource)
+ {
+ try
+ {
+ resource.openStream().close();
+ return true;
+ }
+ catch (IOException e)
+ {
+ return false;
+ }
+ }
+
+ protected String[] getScriptExtensions()
+ {
+ return DEFAULT_SCRIPT_EXTENSIONS;
+ }
}
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java 2010-12-22 10:15:37 UTC (rev 3701)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.groovy;
+
+import groovy.lang.GroovyClassLoader;
+
+import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Factory of Groovy class loader. It can provide preset GroovyClassLoader
+ * instance or customized instance of GroovyClassLoader able resolve additional
+ * Groovy source files.
+ *
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class GroovyClassLoaderProvider
+{
+ /** Preset default GroovyClassLoader. */
+ private GroovyClassLoader defaultClassLoader;
+
+ /**
+ * Create GroovyClassLoaderProvider that will use specified GroovyClassLoader
+ * as default.
+ *
+ * @param defaultClassLoader GroovyClassLoader
+ */
+ public GroovyClassLoaderProvider(GroovyClassLoader defaultClassLoader)
+ {
+ this.defaultClassLoader = defaultClassLoader;
+ }
+
+ public GroovyClassLoaderProvider()
+ {
+ defaultClassLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>()
+ {
+ public GroovyClassLoader run()
+ {
+ return new GroovyClassLoader(getClass().getClassLoader());
+ }
+ });
+ }
+
+ /**
+ * Get default GroovyClassLoader.
+ *
+ * @return default GroovyClassLoader
+ */
+ public GroovyClassLoader getGroovyClassLoader()
+ {
+ return defaultClassLoader;
+ }
+
+ /**
+ * Get customized instance of GroovyClassLoader that able to resolve
+ * additional Groovy source files.
+ *
+ * @param classPath additional Groovy sources
+ * @return GroovyClassLoader
+ * @throws MalformedURLException if any of entries in <code>classPath</code>
+ * has invalid URL.
+ */
+ public GroovyClassLoader getGroovyClassLoader(ClassPathEntry[] classPath) throws MalformedURLException
+ {
+ List<URL> files = new ArrayList<URL>();
+ List<URL> roots = new ArrayList<URL>();
+ for (int i = 0; i < classPath.length; i++)
+ {
+ ClassPathEntry classPathEntry = classPath[i];
+ if (EntryType.SRC_DIR == classPathEntry.getType())
+ {
+ roots.add(classPathEntry.getPath());
+ }
+ else
+ {
+ files.add(classPathEntry.getPath());
+ }
+ }
+ final GroovyClassLoader parent = getGroovyClassLoader();
+ GroovyClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>()
+ {
+ public GroovyClassLoader run()
+ {
+ return new GroovyClassLoader(parent);
+ }
+ });
+ classLoader.setResourceLoader(new DefaultGroovyResourceLoader(roots.toArray(new URL[roots.size()]), files
+ .toArray(new URL[files.size()])));
+ return classLoader;
+ }
+
+ /**
+ * Set default Groovy class loader.
+ *
+ * @param defaultClassLoader default Groovy class loader
+ * @throws NullPointerException if <code>defaultClassLoader == null</code>
+ */
+ public void setGroovyClassLoader(GroovyClassLoader defaultClassLoader)
+ {
+ if (defaultClassLoader == null)
+ throw new NullPointerException("GroovyClassLoader may not be null. ");
+ this.defaultClassLoader = defaultClassLoader;
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-12-22 09:24:37 UTC (rev 3700)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-12-22 10:15:37 UTC (rev 3701)
@@ -33,6 +33,7 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.security.PrivilegedAction;
@@ -46,7 +47,7 @@
/**
* Manage via {@link ResourceBinder} Groovy based RESTful services.
- *
+ *
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id$
*/
@@ -63,44 +64,58 @@
protected final GroovyScriptInstantiator instantiator;
- protected GroovyClassLoader gcl;
+ protected final GroovyClassLoaderProvider classLoaderProvider;
protected final Map<ResourceId, String> resources = Collections.synchronizedMap(new HashMap<ResourceId, String>());
+ protected GroovyJaxrsPublisher(ResourceBinder binder, GroovyScriptInstantiator instantiator,
+ GroovyClassLoaderProvider classLoaderProvider)
+ {
+ this.binder = binder;
+ this.instantiator = instantiator;
+ this.classLoaderProvider = classLoaderProvider;
+ }
+
/**
* Create GroovyJaxrsPublisher which is able publish per-request and
* singleton resources. Any required dependencies for per-request resource
* injected by {@link PerRequestObjectFactory}, instance of singleton
* resources will be created by {@link GroovyScriptInstantiator}.
- *
+ *
* @param binder resource binder
* @param instantiator instantiate java object from given groovy source
*/
public GroovyJaxrsPublisher(ResourceBinder binder, GroovyScriptInstantiator instantiator)
{
- this.binder = binder;
- this.instantiator = instantiator;
- final ClassLoader cl = getClass().getClassLoader();
- this.gcl = SecurityHelper.doPriviledgedAction(new PrivilegedAction<GroovyClassLoader>()
- {
- public GroovyClassLoader run()
- {
- return new GroovyClassLoader(cl);
- }
- });
+ this(binder, instantiator, new GroovyClassLoaderProvider());
}
/**
* @return get underling groovy class loader
*/
+ @Deprecated
public GroovyClassLoader getGroovyClassLoader()
{
- return gcl;
+ return classLoaderProvider.getGroovyClassLoader();
}
/**
+ * Set groovy class loader.
+ *
+ * @param gcl groovy class loader
+ * @throws NullPointerException if <code>gcl == null</code>
+ */
+ @Deprecated
+ public void setGroovyClassLoader(GroovyClassLoader gcl)
+ {
+ if (gcl == null)
+ throw new NullPointerException("GroovyClassLoader may not be null. ");
+ classLoaderProvider.setGroovyClassLoader(gcl);
+ }
+
+ /**
* Get resource corresponded to specified id <code>resourceId</code> .
- *
+ *
* @param resourceId resource id
* @return resource or <code>null</code>
*/
@@ -127,7 +142,7 @@
/**
* Check is groovy resource with specified id is published or not
- *
+ *
* @param resourceId id of resource to be checked
* @return <code>true</code> if resource is published and <code>false</code>
* otherwise
@@ -139,23 +154,50 @@
/**
* Parse given stream and publish result as per-request RESTful service.
- *
+ *
* @param in stream which contains groovy source code of RESTful service
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
- * <code>null</code>
+ * <code>null</code>
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
- * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
+ * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
*/
public void publishPerRequest(final InputStream in, final ResourceId resourceId,
MultivaluedMap<String, String> properties)
{
- Class<?> rc = SecurityHelper.doPriviledgedAction(new PrivilegedAction<Class<?>>()
- {
+ publishPerRequest(in, resourceId, properties, null);
+ }
+
+ /**
+ * Parse given stream and publish result as per-request RESTful service.
+ *
+ * @param in stream which contains groovy source code of RESTful service
+ * @param resourceId id to be assigned to resource
+ * @param properties optional resource properties. This parameter may be
+ * <code>null</code>
+ * @param classPath additional path to Groovy sources
+ * @throws NullPointerException if <code>resourceId == null</code>
+ * @throws ResourcePublicationException see
+ * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
+ */
+ public void publishPerRequest(final InputStream in, final ResourceId resourceId,
+ final MultivaluedMap<String, String> properties, final ClassPathEntry[] classPath)
+ {
+ Class<?> rc = SecurityHelper.doPriviledgedAction(new PrivilegedAction<Class<?>>() {
public Class<?> run()
{
- return gcl.parseClass(createCodeSource(in, resourceId.getId()));
+ try
+ {
+ GroovyClassLoader cl = (classPath == null || classPath.length == 0) //
+ ? classLoaderProvider.getGroovyClassLoader() //
+ : classLoaderProvider.getGroovyClassLoader(classPath);
+ return cl.parseClass(createCodeSource(in, resourceId.getId()));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new ResourcePublicationException(e.getMessage());
+ }
}
});
@@ -166,113 +208,216 @@
/**
* Parse given <code>source</code> and publish result as per-request RESTful
* service.
- *
+ *
* @param source groovy source code of RESTful service
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
- * <code>null</code>
+ * <code>null</code>
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
- * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
+ * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
*/
public final void publishPerRequest(String source, ResourceId resourceId, MultivaluedMap<String, String> properties)
{
- publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties);
+ publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, null);
}
/**
* Parse given <code>source</code> and publish result as per-request RESTful
* service.
- *
+ *
* @param source groovy source code of RESTful service
+ * @param resourceId id to be assigned to resource
+ * @param properties optional resource properties. This parameter may be
+ * <code>null</code>
+ * @param classPath additional path to Groovy sources
+ * @throws NullPointerException if <code>resourceId == null</code>
+ * @throws ResourcePublicationException see
+ * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
+ */
+ public final void publishPerRequest(String source, ResourceId resourceId, MultivaluedMap<String, String> properties,
+ ClassPathEntry[] classPath)
+ {
+ publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, classPath);
+ }
+
+ /**
+ * Parse given <code>source</code> and publish result as per-request RESTful
+ * service.
+ *
+ * @param source groovy source code of RESTful service
* @param charset source string charset. May be <code>null</code> than
- * default charset will be in use
+ * default charset will be in use
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
- * <code>null</code>.
+ * <code>null</code>.
* @throws UnsupportedCharsetException if <code>charset</code> is unsupported
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
- * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
+ * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
*/
public final void publishPerRequest(String source, String charset, ResourceId resourceId,
MultivaluedMap<String, String> properties)
{
- publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties);
+ publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
+ null);
}
/**
+ * Parse given <code>source</code> and publish result as per-request RESTful
+ * service.
+ *
+ * @param source groovy source code of RESTful service
+ * @param charset source string charset. May be <code>null</code> than
+ * default charset will be in use
+ * @param resourceId id to be assigned to resource
+ * @param properties optional resource properties. This parameter may be
+ * <code>null</code>.
+ * @param classPath additional path to Groovy sources
+ * @throws UnsupportedCharsetException if <code>charset</code> is unsupported
+ * @throws NullPointerException if <code>resourceId == null</code>
+ * @throws ResourcePublicationException see
+ * {@link ResourceBinder#addResource(Class, MultivaluedMap)}
+ */
+ public final void publishPerRequest(String source, String charset, ResourceId resourceId,
+ MultivaluedMap<String, String> properties, ClassPathEntry[] classPath)
+ {
+ publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
+ classPath);
+ }
+
+ /**
* Parse given stream and publish result as singleton RESTful service.
- *
+ *
* @param in stream which contains groovy source code of RESTful service
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
- * <code>null</code>
+ * <code>null</code>
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
- * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
+ * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
*/
public void publishSingleton(InputStream in, ResourceId resourceId, MultivaluedMap<String, String> properties)
{
- Object r = instantiator.instantiateScript(createCodeSource(in, resourceId.getId()), gcl);
- binder.addResource(r, properties);
- resources.put(resourceId, r.getClass().getAnnotation(Path.class).value());
+ publishSingleton(in, resourceId, properties, null);
}
/**
+ * Parse given stream and publish result as singleton RESTful service.
+ *
+ * @param in stream which contains groovy source code of RESTful service
+ * @param resourceId id to be assigned to resource
+ * @param properties optional resource properties. This parameter may be
+ * <code>null</code>
+ * @param classPath additional path to Groovy sources
+ * @throws NullPointerException if <code>resourceId == null</code>
+ * @throws ResourcePublicationException see
+ * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
+ */
+ public void publishSingleton(InputStream in, ResourceId resourceId, MultivaluedMap<String, String> properties,
+ ClassPathEntry[] classPath)
+ {
+ Object resource;
+ try
+ {
+ resource =
+ instantiator.instantiateScript(createCodeSource(in, resourceId.getId()),
+ (classPath == null || classPath.length == 0) //
+ ? classLoaderProvider.getGroovyClassLoader() //
+ : classLoaderProvider.getGroovyClassLoader(classPath));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new ResourcePublicationException(e.getMessage());
+ }
+ binder.addResource(resource, properties);
+ resources.put(resourceId, resource.getClass().getAnnotation(Path.class).value());
+ }
+
+ /**
* Parse given <code>source</code> and publish result as singleton RESTful
* service.
- *
+ *
* @param source groovy source code of RESTful service
* @param resourceId name of resource
* @param properties optional resource properties. This parameter may be
- * <code>null</code>.
+ * <code>null</code>.
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
- * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
+ * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
*/
public final void publishSingleton(String source, ResourceId resourceId, MultivaluedMap<String, String> properties)
{
- publishSingleton(source, DEFAULT_CHARSET, resourceId, properties);
+ publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, null);
}
/**
* Parse given <code>source</code> and publish result as singleton RESTful
* service.
- *
+ *
* @param source groovy source code of RESTful service
+ * @param resourceId name of resource
+ * @param properties optional resource properties. This parameter may be
+ * <code>null</code>.
+ * @param classPath additional path to Groovy sources
+ * @throws NullPointerException if <code>resourceId == null</code>
+ * @throws ResourcePublicationException see
+ * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
+ */
+ public final void publishSingleton(String source, ResourceId resourceId, MultivaluedMap<String, String> properties,
+ ClassPathEntry[] classPath)
+ {
+ publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, classPath);
+ }
+
+ /**
+ * Parse given <code>source</code> and publish result as singleton RESTful
+ * service.
+ *
+ * @param source groovy source code of RESTful service
* @param charset source string charset. May be <code>null</code> than
- * default charset will be in use
+ * default charset will be in use
* @param resourceId name of resource
* @param properties optional resource properties. This parameter may be
- * <code>null</code>.
+ * <code>null</code>.
* @throws UnsupportedCharsetException if <code>charset</code> is unsupported
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
- * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
+ * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
*/
public final void publishSingleton(String source, String charset, ResourceId resourceId,
MultivaluedMap<String, String> properties)
{
- publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties);
+ publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
+ null);
}
/**
- * Set groovy class loader.
- *
- * @param gcl groovy class loader
- * @throws NullPointerException if <code>gcl == null</code>
+ * Parse given <code>source</code> and publish result as singleton RESTful
+ * service.
+ *
+ * @param source groovy source code of RESTful service
+ * @param charset source string charset. May be <code>null</code> than
+ * default charset will be in use
+ * @param resourceId name of resource
+ * @param properties optional resource properties. This parameter may be
+ * <code>null</code>.
+ * @param classPath additional path to Groovy sources
+ * @throws UnsupportedCharsetException if <code>charset</code> is unsupported
+ * @throws NullPointerException if <code>resourceId == null</code>
+ * @throws ResourcePublicationException see
+ * {@link ResourceBinder#addResource(Object, MultivaluedMap)}
*/
- public void setGroovyClassLoader(GroovyClassLoader gcl)
+ public final void publishSingleton(String source, String charset, ResourceId resourceId,
+ MultivaluedMap<String, String> properties, ClassPathEntry[] classPath)
{
- if (gcl == null)
- throw new NullPointerException("GroovyClassLoader may not be null.");
- this.gcl = gcl;
+ publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
+ classPath);
}
/**
* Unpublish resource with specified id.
- *
+ *
* @param resourceId id of resource to be unpublished
* @return <code>true</code> if resource was published and <code>false</code>
* otherwise, e.g. because there is not resource corresponded to
@@ -294,31 +439,30 @@
}
private void publishPerRequest(String source, Charset charset, ResourceId resourceId,
- MultivaluedMap<String, String> properties)
+ MultivaluedMap<String, String> properties, ClassPathEntry[] classPath)
{
byte[] bytes = source.getBytes(charset);
publishPerRequest(new ByteArrayInputStream(bytes), resourceId, properties);
}
private void publishSingleton(String source, Charset charset, ResourceId resourceId,
- MultivaluedMap<String, String> properties)
+ MultivaluedMap<String, String> properties, ClassPathEntry[] classPath)
{
byte[] bytes = source.getBytes(charset);
- publishSingleton(new ByteArrayInputStream(bytes), resourceId, properties);
+ publishSingleton(new ByteArrayInputStream(bytes), resourceId, properties, classPath);
}
/**
* Create {@link GroovyCodeSource} from given stream and name. Code base
* 'file:/groovy/script/jaxrs' will be used.
- *
+ *
* @param in groovy source code stream
* @param name code source name
* @return GroovyCodeSource
*/
protected GroovyCodeSource createCodeSource(final InputStream in, final String name)
{
- GroovyCodeSource gcs = SecurityHelper.doPriviledgedAction(new PrivilegedAction<GroovyCodeSource>()
- {
+ GroovyCodeSource gcs = SecurityHelper.doPriviledgedAction(new PrivilegedAction<GroovyCodeSource>() {
public GroovyCodeSource run()
{
return new GroovyCodeSource(in, name, "/groovy/script/jaxrs");
Deleted: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java 2010-12-22 09:24:37 UTC (rev 3700)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java 2010-12-22 10:15:37 UTC (rev 3701)
@@ -1,21 +0,0 @@
-package org.exoplatform.services.rest.ext.filter;
-
-import junit.framework.TestCase;
-
-import org.exoplatform.common.util.HierarchicalProperty;
-import org.exoplatform.services.rest.ext.provider.HierarchicalPropertyEntityProvider;
-
-import java.io.ByteArrayInputStream;
-
-public class HierarchicalPropertyEntityProviderTest extends TestCase
-{
- public void testRequestBodyXMLParsing() throws Exception
- {
- String s = "\n<root>\n <l1>\n\t<l2>hel\nlo</l2>\n </l1> \n</root>\n";
- System.out.println(s);
- HierarchicalProperty hp =
- new HierarchicalPropertyEntityProvider().readFrom(HierarchicalProperty.class, null, null, null, null,
- new ByteArrayInputStream(s.getBytes()));
- assertTrue(hp.getChild(0).getChild(0).getValue().equals("hel\nlo"));
- }
-}
\ No newline at end of file
Copied: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProviderTest.java (from rev 3678, ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java)
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProviderTest.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProviderTest.java 2010-12-22 10:15:37 UTC (rev 3701)
@@ -0,0 +1,21 @@
+package org.exoplatform.services.rest.ext.provider;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.common.util.HierarchicalProperty;
+import org.exoplatform.services.rest.ext.provider.HierarchicalPropertyEntityProvider;
+
+import java.io.ByteArrayInputStream;
+
+public class HierarchicalPropertyEntityProviderTest extends TestCase
+{
+ public void testRequestBodyXMLParsing() throws Exception
+ {
+ String s = "\n<root>\n <l1>\n\t<l2>hel\nlo</l2>\n </l1> \n</root>\n";
+ //System.out.println(s);
+ HierarchicalProperty hp =
+ new HierarchicalPropertyEntityProvider().readFrom(HierarchicalProperty.class, null, null, null, null,
+ new ByteArrayInputStream(s.getBytes()));
+ assertTrue(hp.getChild(0).getChild(0).getValue().equals("hel\nlo"));
+ }
+}
\ No newline at end of file
Property changes on: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProviderTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 5 months