diff --git a/exo.ws.rest.core/pom.xml b/exo.ws.rest.core/pom.xml index f4b23ea7f..f5f9b79f3 100644 --- a/exo.ws.rest.core/pom.xml +++ b/exo.ws.rest.core/pom.xml @@ -33,7 +33,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Implementation of REST Core for Exoplatform SAS 'Web Services' project. - 0.73 + 0.72 diff --git a/exo.ws.rest.ext/pom.xml b/exo.ws.rest.ext/pom.xml index 135b8ed16..6ea97b293 100644 --- a/exo.ws.rest.ext/pom.xml +++ b/exo.ws.rest.ext/pom.xml @@ -33,7 +33,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Implementation of REST Extentions for Exoplatform SAS 'Web Services' project. - 0.31 + 0.11 @@ -42,14 +42,6 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. exo.kernel.commons.test test - - io.meeds.core - exo.core.component.xml-processing - - - io.meeds.core - exo.core.component.script.groovy - io.meeds.ws exo.ws.commons diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java deleted file mode 100644 index 68a390407..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -/** - * Base implementation of ResourceId. - * - * @author Andrey Parfonov - * @version $Id$ - */ -public class BaseResourceId implements ResourceId -{ - - protected final String id; - - public BaseResourceId(String id) - { - this.id = id; - } - - /** - * {@inheritDoc} - */ - public String getId() - { - return id; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) - { - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - return id.equals(((BaseResourceId)obj).id); - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() - { - return id.hashCode(); - } - - /** - * {@inheritDoc} - */ - public String toString() - { - return getClass().getSimpleName() + '(' + id + ')'; - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java deleted file mode 100644 index 941462b3c..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -import java.net.URL; - -/** - * Item of Groovy classpath. - * - * @author Andrey Parfonov - * @version $Id$ - */ -public abstract class ClassPathEntry -{ - private final URL path; - - public ClassPathEntry(URL path) - { - this.path = path; - } - - public URL getPath() - { - return path; - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java deleted file mode 100644 index 2c59fcba6..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -import groovy.lang.GroovyResourceLoader; - -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.Callable; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.FutureTask; - -/** - * @author Andrey Parfonov - * @version $Id: DefaultGroovyResourceLoader.java 2680 2010-06-22 11:43:00Z - * aparfonov $ - */ -public class DefaultGroovyResourceLoader implements GroovyResourceLoader -{ - private static final String DEFAULT_SOURCE_FILE_EXTENSION = ".groovy"; - - private static final Log LOG = ExoLogger.getLogger("exo.ws.rest.ext.DefaultGroovyResourceLoader"); - - public final ConcurrentMap> findResourceURLTasks = new ConcurrentHashMap>(); - - private int maxEntries = 512; - - protected final Map resources; - - protected final URL[] roots; - - @SuppressWarnings("serial") - public DefaultGroovyResourceLoader(URL[] roots) throws MalformedURLException - { - 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() - { - protected boolean removeEldestEntry(Entry eldest) - { - return size() > maxEntries; - } - }); - } - - public DefaultGroovyResourceLoader(URL root) throws MalformedURLException - { - this(new URL[]{root}); - } - - /** - * {@inheritDoc} - */ - public final URL loadGroovySource(String filename) throws MalformedURLException - { - URL resource = null; - final String ffilename = filename.replace('.', '/') + getSourceFileExtension(); - return getResource(ffilename); - } - - protected URL getResource(final String filename) throws MalformedURLException - { - // First we check the cache outside the synchronized block - URL resource = resources.get(filename); - if (resource != null && checkResource(resource)) - { - // The resource could be found in the cache and is reachable - return resource; - } - // The resource cannot be found or is unreachable - // Check if a corresponding findResourceURL task exists - Future findResourceURLTask = findResourceURLTasks.get(filename); - if (findResourceURLTask == null) - { - // The task doesn't exist so we create it - FutureTask f = new FutureTask(new Callable() - { - public URL call() throws Exception - { - return findResourceURL(filename); - } - }); - // We add the new task to the existing tasks - findResourceURLTask = findResourceURLTasks.putIfAbsent(filename, f); - if (findResourceURLTask == null) - { - // The task has not be registered so we launch it - findResourceURLTask = f; - f.run(); - } - } - try - { - return findResourceURLTask.get(); - } - catch (CancellationException e) - { - if (LOG.isTraceEnabled()) - { - LOG.trace("An exception occurred: " + e.getMessage()); - } - } - catch (ExecutionException e) - { - throw (MalformedURLException)e.getCause(); - } - catch (InterruptedException e) - { - Thread.currentThread().interrupt(); - } - finally - { - findResourceURLTasks.remove(filename, findResourceURLTask); - } - return null; - } - - protected URL findResourceURL(String filename) throws MalformedURLException - { - URL resource = resources.get(filename); - boolean inCache = resource != null; - if (inCache && !checkResource(resource)) - resource = null; // Resource in cache is unreachable. - for (int i = 0; i < roots.length && resource == null; i++) - { - URL tmp = createURL(roots[i], filename); - if (checkResource(tmp)) - resource = tmp; - } - if (resource != null) - resources.put(filename, resource); - else if (inCache) - resources.remove(filename); - return resource; - } - - protected URL createURL(URL root, String filename) throws MalformedURLException - { - return new URL(root, filename); - } - - protected String getSourceFileExtension() - { - return DEFAULT_SOURCE_FILE_EXTENSION; - } - - protected boolean checkResource(URL resource) - { - try - { - resource.openStream().close(); - return true; - } - catch (IOException e) - { - return false; - } - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java deleted file mode 100644 index fed11f301..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -import groovy.lang.GroovyClassLoader; - -import org.codehaus.groovy.ast.ClassNode; -import org.codehaus.groovy.ast.ModuleNode; -import org.codehaus.groovy.control.CompilationFailedException; -import org.codehaus.groovy.control.CompilationUnit; -import org.codehaus.groovy.control.CompilerConfiguration; -import org.codehaus.groovy.control.Phases; -import org.codehaus.groovy.control.SourceUnit; - -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.CodeSource; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * @author Andrey Parfonov - * @version $Id: ExtendedGroovyClassLoader.java 3731 2010-12-27 13:35:46Z - * aparfonov $ - */ -@SuppressWarnings({"rawtypes", "unchecked"}) -public class ExtendedGroovyClassLoader extends GroovyClassLoader -{ - public static final String CODE_BASE = "/groovy/script/jaxrs"; - - public static class SingleClassCollector extends GroovyClassLoader.ClassCollector - { - protected final CompilationUnit cunit; - protected final SourceUnit sunit; - protected Class target; - - protected SingleClassCollector(ExtendedInnerLoader cl, CompilationUnit cunit, SourceUnit sunit) - { - super(cl, cunit, sunit); - this.cunit = cunit; - this.sunit = sunit; - } - - @Override - protected Class createClass(byte[] code, ClassNode classNode) - { - ExtendedInnerLoader cl = (ExtendedInnerLoader)getDefiningClassLoader(); - /*String classname = classNode.getName(); - int i = classname.lastIndexOf('.'); - if (i != -1) - { - String pkgname = classname.substring(0, i); - cl.definePackage(pkgname); - }*/ - Class clazz = cl.defineClass(classNode.getName(), code, cunit.getAST().getCodeSource()); - getLoadedClasses().add(clazz); - if (target == null) - { - ClassNode targetClassNode = null; - SourceUnit targetSunit = null; - ModuleNode module = classNode.getModule(); - - if (module != null) - { - targetClassNode = (ClassNode)module.getClasses().get(0); - targetSunit = module.getContext(); - } - - if (targetSunit == sunit && targetClassNode == classNode) //NOSONAR - { - target = clazz; - } - } - return clazz; - } - - public Class getTarget() - { - return target; - } - } - - public static class MultipleClassCollector extends GroovyClassLoader.ClassCollector - { - protected final CompilationUnit cunit; - protected final Set sunitSet; - private final List compiledClasses; - - protected MultipleClassCollector(ExtendedInnerLoader cl, CompilationUnit cunit, Set sunitSet) - { - super(cl, cunit, null); - this.cunit = cunit; - this.sunitSet = sunitSet; - this.compiledClasses = new ArrayList(); - } - - @Override - protected Class createClass(byte[] code, ClassNode classNode) - { - ExtendedInnerLoader cl = (ExtendedInnerLoader)getDefiningClassLoader(); - /*String classname = classNode.getName(); - int i = classname.lastIndexOf('.'); - if (i != -1) - { - String pkgname = classname.substring(0, i); - cl.definePackage(pkgname); - }*/ - Class clazz = cl.defineClass(classNode.getName(), code, cunit.getAST().getCodeSource()); - getLoadedClasses().add(clazz); - ModuleNode module = classNode.getModule(); - if (module != null) - { - SourceUnit currentSunit = module.getContext(); - if (sunitSet.contains(currentSunit)) - compiledClasses.add(clazz); - } - return clazz; - } - - public List getCompiledClasses() - { - return compiledClasses; - } - } - - public static class ExtendedInnerLoader extends GroovyClassLoader.InnerLoader - { - public ExtendedInnerLoader(ExtendedGroovyClassLoader parent) - { - super(parent); - } - - protected Class defineClass(String name, byte[] code, CodeSource cs) - { - return super.defineClass(name, code, 0, code.length, cs); - } - - protected void definePackage(String name) throws IllegalArgumentException - { - Package pkg = getPackage(name); - if (pkg == null) - super.definePackage(name, null, null, null, null, null, null, null); - } - } - - public ExtendedGroovyClassLoader(ClassLoader classLoader) - { - super(classLoader); - } - - public ExtendedGroovyClassLoader(GroovyClassLoader parent) - { - super(parent); - } - - public Class parseClass(InputStream in, String fileName, SourceFile[] files) throws CompilationFailedException - { - return doParseClass(in, fileName, files, Phases.CLASS_GENERATION, null, false); - } - - protected Class doParseClass(InputStream in, String fileName, SourceFile[] files, int phase, - CompilerConfiguration config, boolean shouldCacheSource) throws CompilationFailedException - { - synchronized (sourceCache) - { - Class target = (Class)sourceCache.get(fileName); - if (target == null) - { - CodeSource cs = new CodeSource(getCodeSource(), (java.security.cert.Certificate[])null); - CompilationUnit cunit = createCompilationUnit(config, cs); - SourceUnit targetSunit = cunit.addSource(fileName, in); - if (files != null) - { - for (int i = 0; i < files.length; i++) - cunit.addSource(files[i].getPath()); - } - SingleClassCollector collector = createSingleCollector(cunit, targetSunit); - cunit.setClassgenCallback(collector); - cunit.compile(phase); - - for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();) - { - Class clazz = (Class)iter.next(); - String classname = clazz.getName(); - int i = classname.lastIndexOf('.'); - if (i != -1) - { - String pkgname = classname.substring(0, i); - Package pkg = getPackage(pkgname); - if (pkg == null) - definePackage(pkgname, null, null, null, null, null, null, null); - } - setClassCacheEntry(clazz); - } - - target = collector.getTarget(); - - if (shouldCacheSource) - sourceCache.put(fileName, target); - } - - return target; - } - } - - public Class[] parseClasses(SourceFile[] files) - { - return doParseClasses(files, Phases.CLASS_GENERATION, null); - } - - protected Class[] doParseClasses(SourceFile[] sources, int phase, CompilerConfiguration config) - { - synchronized (classCache) - { - CodeSource cs = new CodeSource(getCodeSource(), (java.security.cert.Certificate[])null); - CompilationUnit cunit = createCompilationUnit(config, cs); - Set setSunit = new HashSet(); - for (int i = 0; i < sources.length; i++) - setSunit.add(cunit.addSource(sources[i].getPath())); - MultipleClassCollector collector = createMultipleCollector(cunit, setSunit); - cunit.setClassgenCallback(collector); - cunit.compile(phase); - - for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();) - { - Class clazz = (Class)iter.next(); - String classname = clazz.getName(); - int i = classname.lastIndexOf('.'); - if (i != -1) - { - String pkgname = classname.substring(0, i); - Package pkg = getPackage(pkgname); - if (pkg == null) - definePackage(pkgname, null, null, null, null, null, null, null); - } - setClassCacheEntry(clazz); - } - List compiledClasses = collector.getCompiledClasses(); - return compiledClasses.toArray(new Class[compiledClasses.size()]); - } - } - - /** - * @see groovy.lang.GroovyClassLoader#createCompilationUnit(org.codehaus.groovy.control.CompilerConfiguration, - * java.security.CodeSource) - */ - @Override - protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource cs) - { - return new CompilationUnit(config, cs, this); - } - - protected SingleClassCollector createSingleCollector(CompilationUnit unit, SourceUnit sunit) - { - ExtendedInnerLoader loader = new ExtendedInnerLoader(ExtendedGroovyClassLoader.this); - return new SingleClassCollector(loader, unit, sunit); - } - - protected MultipleClassCollector createMultipleCollector(CompilationUnit unit, Set setSunit) - { - ExtendedInnerLoader loader = new ExtendedInnerLoader(ExtendedGroovyClassLoader.this); - return new MultipleClassCollector(loader, unit, setSunit); - } - - protected URL getCodeSource() - { - return getCodeSource(CODE_BASE); - } - - private URL getCodeSource(String codeBase) - { - try - { - return new URL("file", "", codeBase); - } - catch (MalformedURLException e) - { - throw new IllegalArgumentException("Unable create code source URL from: " + codeBase + ". " + e.getMessage(), - e); - } - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java deleted file mode 100644 index 81ed0a3f1..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -import groovy.lang.GroovyClassLoader; - - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * Factory of Groovy class loader. It can provide preset GroovyClassLoader - * instance or customized instance of GroovyClassLoader able resolve additional - * Groovy source files. - * - * @author Andrey Parfonov - * @version $Id: GroovyClassLoaderProvider.java 3701 2010-12-22 10:15:37Z - * aparfonov $ - */ -public class GroovyClassLoaderProvider -{ - /** Preset default GroovyClassLoader. */ - private ExtendedGroovyClassLoader defaultClassLoader; - - public GroovyClassLoaderProvider() - { - this(new ExtendedGroovyClassLoader(GroovyClassLoaderProvider.class.getClassLoader())); - } - - protected GroovyClassLoaderProvider(ExtendedGroovyClassLoader defaultClassLoader) - { - this.defaultClassLoader = defaultClassLoader; - } - - /** - * Get default GroovyClassLoader. - * - * @return default GroovyClassLoader - */ - public ExtendedGroovyClassLoader getGroovyClassLoader() - { - return defaultClassLoader; - } - - /** - * Get customized instance of GroovyClassLoader that able to resolve - * additional Groovy source files. - * - * @param sources additional Groovy sources - * @return GroovyClassLoader - * @throws MalformedURLException if any of entries in sources - * has invalid URL. - */ - public ExtendedGroovyClassLoader getGroovyClassLoader(SourceFolder[] sources) throws MalformedURLException - { - if (sources == null || sources.length == 0) - return getGroovyClassLoader(); - - URL[] roots = new URL[sources.length]; - for (int i = 0; i < sources.length; i++) - roots[i] = sources[i].getPath(); - - final GroovyClassLoader parent = getGroovyClassLoader(); - ExtendedGroovyClassLoader classLoader = new ExtendedGroovyClassLoader(parent); - classLoader.setResourceLoader(new DefaultGroovyResourceLoader(roots)); - return classLoader; - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java deleted file mode 100644 index 59f8294f9..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java +++ /dev/null @@ -1,681 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -import groovy.lang.GroovyClassLoader; -import groovy.lang.GroovyCodeSource; -import groovy.lang.GroovySystem; - -import org.codehaus.groovy.control.CompilationFailedException; -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.ExoContainerContext; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.exoplatform.services.rest.ObjectFactory; -import org.exoplatform.services.rest.PerRequestObjectFactory; -import org.exoplatform.services.rest.impl.ResourceBinder; -import org.exoplatform.services.rest.impl.ResourcePublicationException; -import org.exoplatform.services.rest.resource.AbstractResourceDescriptor; -import org.exoplatform.services.rest.uri.UriPattern; -import org.exoplatform.services.script.groovy.GroovyScriptInstantiator; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.charset.Charset; -import java.nio.charset.UnsupportedCharsetException; //NOSONAR -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.Path; -import javax.ws.rs.core.MultivaluedMap; - -/** - * Manage via {@link ResourceBinder} Groovy based RESTful services. - * - * @author Andrey Parfonov - * @version $Id$ - */ -public class GroovyJaxrsPublisher -{ - private static final Log LOG = ExoLogger.getExoLogger(GroovyJaxrsPublisher.class); - static - { - // We get the version of groovy as workaround, to make - // sure that it will be able to load the META-INF/dgminfo - String version = GroovySystem.getVersion(); - LOG.debug("The version of groovy used is {}", version); - } - - @SuppressWarnings("rawtypes") - private static final Comparator constructorComparator = new Comparator() { - public int compare(Constructor o1, Constructor o2) - { - int c1 = o1.getParameterTypes().length; - int c2 = o2.getParameterTypes().length; - if (c1 < c2) - return 1; - if (c1 > c2) - return -1; - return 0; - } - }; - - /** Default character set name. */ - protected static final String DEFAULT_CHARSET_NAME = "UTF-8"; - - /** Default character set. */ - protected static final Charset DEFAULT_CHARSET = Charset.forName(DEFAULT_CHARSET_NAME); - - protected final ResourceBinder binder; - - protected final GroovyScriptInstantiator instantiator; - - protected final GroovyClassLoaderProvider classLoaderProvider; - - protected final Map resources = Collections.synchronizedMap(new HashMap()); - - public 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, instantiator, new GroovyClassLoaderProvider()); - } - - /** - * @return get underling groovy class loader - */ - @Deprecated - public GroovyClassLoader getGroovyClassLoader() - { - return classLoaderProvider.getGroovyClassLoader(); - } - - /** - * Set groovy class loader. - * - * @param gcl groovy class loader - * @throws NullPointerException if gcl == null - */ - @Deprecated - public void setGroovyClassLoader(GroovyClassLoader gcl) - { - LOG.warn("Method setGroovyClassLoader is deprecated."); - } - - /** - * Get resource corresponded to specified id resourceId . - * - * @param resourceId resource id - * @return resource or null - */ - public ObjectFactory getResource(ResourceId resourceId) - { - String path = resources.get(resourceId); - if (path == null) - return null; - - UriPattern pattern = new UriPattern(path); - List> rootResources = binder.getResources(); - synchronized (rootResources) - { - for (ObjectFactory res : rootResources) - { - if (res.getObjectModel().getUriPattern().equals(pattern)) - return res; - } - } - // If resource not exists any more but still in mapping. - resources.remove(resourceId); - return null; - } - - /** - * Check is groovy resource with specified id is published or not - * - * @param resourceId id of resource to be checked - * @return true if resource is published and false - * otherwise - */ - public boolean isPublished(ResourceId resourceId) - { - return null != getResource(resourceId); - } - - /** - * 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 - * null - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Class, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public void publishPerRequest(InputStream in, ResourceId resourceId, MultivaluedMap properties) - { - publishPerRequest(in, resourceId, properties, null, 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 - * null - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Class, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public void publishPerRequest(final InputStream in, final ResourceId resourceId, - final MultivaluedMap properties, final SourceFolder[] src, final SourceFile[] files) - { - Class rc; - try - { - ExtendedGroovyClassLoader cl = - (src == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider - .getGroovyClassLoader(src); - rc = cl.parseClass(in, resourceId.getId(), files); - } - catch (MalformedURLException e) - { - throw new IllegalArgumentException(e.getMessage(), e); - } - - binder.addResource(rc, properties); - resources.put(resourceId, rc.getAnnotation(Path.class).value()); - } - - /** - * Parse given source 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 - * null - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Class, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishPerRequest(String source, ResourceId resourceId, MultivaluedMap properties) - { - publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, null, null); - } - - /** - * Parse given source 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 - * null - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Class, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishPerRequest(String source, ResourceId resourceId, MultivaluedMap properties, - SourceFolder[] src, SourceFile[] files) - { - publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, src, files); - } - - /** - * Parse given source and publish result as per-request RESTful - * service. - * - * @param source groovy source code of RESTful service - * @param charset source string charset. May be null than - * default charset will be in use - * @param resourceId id to be assigned to resource - * @param properties optional resource properties. This parameter may be - * null. - * @throws UnsupportedCharsetException if charset is unsupported - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Class, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishPerRequest(String source, String charset, ResourceId resourceId, - MultivaluedMap properties) - { - publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties, - null, null); - } - - /** - * Parse given source and publish result as per-request RESTful - * service. - * - * @param source groovy source code of RESTful service - * @param charset source string charset. May be null than - * default charset will be in use - * @param resourceId id to be assigned to resource - * @param properties optional resource properties. This parameter may be - * null. - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws UnsupportedCharsetException if charset is unsupported - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Class, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishPerRequest(String source, String charset, ResourceId resourceId, - MultivaluedMap properties, SourceFolder[] src, SourceFile[] files) - { - publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties, - src, files); - } - - /** - * 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 - * null - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Object, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public void publishSingleton(InputStream in, ResourceId resourceId, MultivaluedMap properties) - { - publishSingleton(in, resourceId, properties, null, 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 - * null - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Object, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public void publishSingleton(final InputStream in, final ResourceId resourceId, - MultivaluedMap properties, final SourceFolder[] src, final SourceFile[] files) - { - Object resource; - try - { - ExtendedGroovyClassLoader cl = - (src == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider.getGroovyClassLoader(src); - @SuppressWarnings("rawtypes") - Class clazz = cl.parseClass(in, resourceId.getId(), files); - resource = createInstance(clazz); - } - catch (IllegalArgumentException e) - { - throw new ResourcePublicationException(e.getMessage()); - } - catch (InstantiationException e) - { - throw new ResourcePublicationException(e.getMessage()); - } - catch (IllegalAccessException e) - { - throw new ResourcePublicationException(e.getMessage()); - } - catch (InvocationTargetException e) - { - throw new ResourcePublicationException(e.getMessage()); - } - catch (MalformedURLException e) - { - throw new IllegalArgumentException(e.getMessage(), e); - } - binder.addResource(resource, properties); - resources.put(resourceId, resource.getClass().getAnnotation(Path.class).value()); - } - - /** - * Parse given source 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 - * null. - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Object, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishSingleton(String source, ResourceId resourceId, MultivaluedMap properties) - { - publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, null, null); - } - - /** - * Parse given source 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 - * null. - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Object, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishSingleton(String source, ResourceId resourceId, MultivaluedMap properties, - SourceFolder[] src, SourceFile[] files) - { - publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, src, files); - } - - /** - * Parse given source and publish result as singleton RESTful - * service. - * - * @param source groovy source code of RESTful service - * @param charset source string charset. May be null than - * default charset will be in use - * @param resourceId name of resource - * @param properties optional resource properties. This parameter may be - * null. - * @throws UnsupportedCharsetException if charset is unsupported - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Object, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishSingleton(String source, String charset, ResourceId resourceId, - MultivaluedMap properties) - { - publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties, - null, null); - } - - /** - * Parse given source and publish result as singleton RESTful - * service. - * - * @param source groovy source code of RESTful service - * @param charset source string charset. May be null than - * default charset will be in use - * @param resourceId name of resource - * @param properties optional resource properties. This parameter may be - * null. - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws UnsupportedCharsetException if charset is unsupported - * @throws NullPointerException if resourceId == null - * @throws ResourcePublicationException see - * {@link ResourceBinder#addResource(Object, MultivaluedMap)} - * @throws CompilationFailedException if compilation fails from source errors - */ - public final void publishSingleton(String source, String charset, ResourceId resourceId, - MultivaluedMap properties, SourceFolder[] src, SourceFile[] files) - { - publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties, - src, files); - } - - /** - * Unpublish resource with specified id. - * - * @param resourceId id of resource to be unpublished - * @return true if resource was published and false - * otherwise, e.g. because there is not resource corresponded to - * supplied resourceId - */ - public ObjectFactory unpublishResource(ResourceId resourceId) - { - String path = resources.get(resourceId); - if (path == null) - return null; - ObjectFactory resource = binder.removeResource(path); - if (resource != null) - resources.remove(resourceId); - return resource; - } - - /** - * Validate does stream contain Groovy source code which is conforms with - * requirement to JAX-RS resource. - * - * @param in Groovy source stream - * @param name script name. This name will be used by GroovyClassLoader to - * identify script, e.g. specified name will be used in error - * message in compilation of Groovy fails. If this parameter is - * null then GroovyClassLoader will use automatically - * generated name - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws MalformedScriptException if source has errors or there is no - * required JAX-RS annotation - */ - public void validateResource(final InputStream in, final String name, final SourceFolder[] src, - final SourceFile[] files) throws MalformedScriptException - { - try - { - ExtendedGroovyClassLoader cl = - (src == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider - .getGroovyClassLoader(src); - cl.parseClass(in, (name != null && name.length() > 0) ? name : cl.generateScriptName(), files); - } - catch (MalformedURLException e) - { - // MalformedURLException - throw new IllegalArgumentException(e.getMessage(), e); - } - catch (CompilationFailedException e) - { - throw new MalformedScriptException(e.getMessage()); - } - /// XXX : Temporary disable resource class validation. Just try to compile - // class and assume resource class is OK if compilation is successful. - /*try - { - new AbstractResourceDescriptorImpl(rc).accept(ResourceDescriptorValidator.getInstance()); - } - catch (RuntimeException e) - { - throw new MalformedScriptException(e.getMessage()); - }*/ - } - - /** - * Validate does stream contain Groovy source code which is conforms with - * requirement to JAX-RS resource. - * - * @param in Groovy source stream - * @param name script name. This name will be used by GroovyClassLoader to - * identify script, e.g. specified name will be used in error - * message in compilation of Groovy fails. If this parameter is - * null then GroovyClassLoader will use automatically - * generated name - * @throws MalformedScriptException if source has errors or there is no - * required JAX-RS annotation - */ - public void validateResource(InputStream in, String name) throws MalformedScriptException - { - validateResource(in, name, null, null); - } - - /** - * Validate does source contain Groovy source code which is - * conforms with requirement to JAX-RS resource. - * - * @param source Groovy source code as String - * @param charset source string charset. May be null than - * default charset will be in use - * @param name script name. This name will be used by GroovyClassLoader to - * identify script, e.g. specified name will be used in error - * message in compilation of Groovy fails. If this parameter is - * null then GroovyClassLoader will use automatically - * generated name - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws MalformedScriptException if source has errors or there is no - * required JAX-RS annotation - */ - public final void validateResource(String source, String charset, String name, SourceFolder[] src, SourceFile[] files) - throws MalformedScriptException - { - validateResource(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), name, src, files); - } - - /** - * Validate does source contain Groovy source code which is - * conforms with requirement to JAX-RS resource. - * - * @param source Groovy source code as String - * @param name script name. This name will be used by GroovyClassLoader to - * identify script, e.g. specified name will be used in error - * message in compilation of Groovy fails. If this parameter is - * null then GroovyClassLoader will use automatically - * generated name - * @param src additional path to Groovy sources - * @param files Groovy source files to be added in build path directly - * @throws MalformedScriptException if source has errors or there is no - * required JAX-RS annotation - */ - public final void validateResource(String source, String name, SourceFolder[] src, SourceFile[] files) - throws MalformedScriptException - { - validateResource(source, DEFAULT_CHARSET, name, src, files); - } - - /** - * Validate does source contain Groovy source code which is - * conforms with requirement to JAX-RS resource. - * - * @param source Groovy source code as String - * @param name script name. This name will be used by GroovyClassLoader to - * identify script, e.g. specified name will be used in error - * message in compilation of Groovy fails. If this parameter is - * null then GroovyClassLoader will use automatically - * generated name - * @throws MalformedScriptException if source has errors or there is no - * required JAX-RS annotation - */ - public final void validateResource(String source, String name) throws MalformedScriptException - { - validateResource(source, DEFAULT_CHARSET, name, null, null); - } - - @SuppressWarnings("rawtypes") - protected Object createInstance(Class clazz) throws IllegalArgumentException, InstantiationException, - IllegalAccessException, InvocationTargetException - { - ExoContainer container = ExoContainerContext.getCurrentContainer(); - Constructor[] constructors = clazz.getConstructors(); - //Sort constructors by number of parameters. With more parameters must be first. - Arrays.sort(constructors, constructorComparator); - l : for (Constructor c : constructors) - { - Class[] parameterTypes = c.getParameterTypes(); - if (parameterTypes.length == 0) - return c.newInstance(); - Object[] parameters = new Object[parameterTypes.length]; - for (int i = 0; i < parameterTypes.length; i++) - { - Object param = container.getComponentInstanceOfType(parameterTypes[i]); - if (param == null) - continue l; - parameters[i] = param; - } - return c.newInstance(parameters); - } - throw new ResourcePublicationException("Unbale create instance of class " + clazz.getName() - + ". Required constructor's dependencies can't be resolved. "); - } - - private void publishPerRequest(String source, Charset charset, ResourceId resourceId, - MultivaluedMap properties, SourceFolder[] src, SourceFile[] files) - { - byte[] bytes = source.getBytes(charset); - publishPerRequest(new ByteArrayInputStream(bytes), resourceId, properties, src, files); - } - - private void publishSingleton(String source, Charset charset, ResourceId resourceId, - MultivaluedMap properties, SourceFolder[] src, SourceFile[] files) - { - byte[] bytes = source.getBytes(charset); - publishSingleton(new ByteArrayInputStream(bytes), resourceId, properties, src, files); - } - - private void validateResource(String source, Charset charset, String name, SourceFolder[] src, SourceFile[] files) - throws MalformedScriptException - { - byte[] bytes = source.getBytes(charset); - validateResource(new ByteArrayInputStream(bytes), name, src, files); - } - - /** - * Create {@link GroovyCodeSource} from given location (URL). - * - * @param url groovy source url - * @exception java.io.IOException - * @return GroovyCodeSource - */ - protected GroovyCodeSource createCodeSource(final URL url) throws IOException - { - GroovyCodeSource gcs = new GroovyCodeSource(url); - gcs.setCachable(false); - return gcs; - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/MalformedScriptException.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/MalformedScriptException.java deleted file mode 100644 index 10968735e..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/MalformedScriptException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -/** - * Thrown if Groovy script is not comply with requirement to JAX-RS resources. - * - * @author Andrey Parfonov - * @version $Id$ - */ -@SuppressWarnings("serial") -public class MalformedScriptException extends Exception -{ - /** - * @param message detail message about wrong with Groovy script. - */ - public MalformedScriptException(String message) - { - super(message); - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java deleted file mode 100644 index 1ac0d641c..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -/** - * @author Andrey Parfonov - * @version $Id$ - */ -public interface ResourceId -{ - - /** - * Gets the id of resource as string - * - * @return the resource id - */ - String getId(); - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java deleted file mode 100644 index 7fe36d536..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -import java.net.URL; - -/** - * Describe location of Groovy source file. - * - * @author Andrey Parfonov - * @version $Id$ - */ -public class SourceFile extends ClassPathEntry -{ - public SourceFile(URL path) - { - super(path); - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java deleted file mode 100644 index 01d3ad02c..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -import java.net.URL; - -/** - * Folder with groovy sources. - * - * @author Andrey Parfonov - * @version $Id$ - */ -public class SourceFolder extends ClassPathEntry -{ - public SourceFolder(URL path) - { - super(path); - } -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/provider/XSLTStreamingOutput.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/provider/XSLTStreamingOutput.java deleted file mode 100644 index 9c5e237b3..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/provider/XSLTStreamingOutput.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.provider; - -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.ExoContainerContext; -import org.exoplatform.services.xml.transform.NotSupportedIOTypeException; -import org.exoplatform.services.xml.transform.impl.trax.TRAXTemplatesServiceImpl; -import org.exoplatform.services.xml.transform.trax.TRAXTemplates; -import org.exoplatform.services.xml.transform.trax.TRAXTemplatesService; -import org.exoplatform.services.xml.transform.trax.TRAXTransformer; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Map; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.StreamingOutput; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.stream.StreamResult; - -/** - * This type should be used by resource methods when need to apply XSLT - * transformation for returned {@link Source}. - * - * @see StreamingOutput - * @author Dmytro Katayev - * @version $Id: XLSTStreamingOutPut.java - */ -public class XSLTStreamingOutput implements StreamingOutput -{ - - private String schemeName; - - private Source source; - - private Map xsltParams; - - /** - * XSLTStreamingOutput constructor. - * - * @param schemeName XLST scheme name. Must be registered in - * {@link org.exoplatform.services.xml.transform.impl.trax.TRAXTemplatesLoaderPlugin - * TRAXTemplatesLoaderPlugin } - * @param source entity to write into output stream. - */ - public XSLTStreamingOutput(String schemeName, Source source) - { - this.schemeName = schemeName; - this.source = source; - } - - /** - * XSLTStreamingOutput constructor. - * - * @param schemeName XLST scheme name. Must be registered in - * {@link org.exoplatform.services.xml.transform.impl.trax.TRAXTemplatesLoaderPlugin - * TRAXTemplatesLoaderPlugin } - * @param source entity to write into output stream. - * @param xsltParams XSLT parameters - */ - public XSLTStreamingOutput(String schemeName, Source source, Map xsltParams) - { - this(schemeName, source); - this.xsltParams = xsltParams; - } - - /** - * {@inheritDoc} . - */ - public void write(OutputStream outStream) throws IOException, WebApplicationException - { - - ExoContainer container = ExoContainerContext.getCurrentContainer(); - - TRAXTemplatesService templatesService = - (TRAXTemplatesService)container.getComponentInstanceOfType(TRAXTemplatesServiceImpl.class); - - try - { - TRAXTransformer transformer = null; - if (schemeName != null) - { - TRAXTemplates t = templatesService.getTemplates(schemeName); - if (t == null) - { - String msg = "Template " + schemeName + " not found."; - throw new IllegalArgumentException(msg); - } - transformer = t.newTransformer(); - } - else - { - throw new IllegalArgumentException("XSLT scheme name is null."); - } - transformer.initResult(new StreamResult(outStream)); - if (xsltParams != null) - { - for (Map.Entry e : xsltParams.entrySet()) - { - transformer.setParameter(e.getKey(), e.getValue()); - } - } - transformer.transform(source); - } - catch (TransformerConfigurationException tce) - { - throw new IOException("Can't write to output stream " + tce, tce); - } - catch (NotSupportedIOTypeException nse) - { - throw new IOException("Can't write to output stream " + nse, nse); - } - catch (TransformerException tre) - { - throw new IOException("Can't write to output stream " + tre, tre); - } - } - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/ACL.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/ACL.java deleted file mode 100644 index 4f27239b1..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/ACL.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * - * Created by The eXo Platform SAS . - * - * @author Vitaliy Gulyy - * @version $ - */ - -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("ACL") -public @interface ACL { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/CHECKIN.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/CHECKIN.java deleted file mode 100644 index 185965578..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/CHECKIN.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("CHECKIN") -public @interface CHECKIN { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/CHECKOUT.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/CHECKOUT.java deleted file mode 100644 index c7e63791c..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/CHECKOUT.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ - -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("CHECKOUT") -public @interface CHECKOUT { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/COPY.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/COPY.java deleted file mode 100644 index cb7f6ee27..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/COPY.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("COPY") -public @interface COPY { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/LOCK.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/LOCK.java deleted file mode 100644 index 4cf7251bd..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/LOCK.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("LOCK") -public @interface LOCK { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/MKCOL.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/MKCOL.java deleted file mode 100644 index b7823df2b..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/MKCOL.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("MKCOL") -public @interface MKCOL { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/MOVE.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/MOVE.java deleted file mode 100644 index 3f3147986..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/MOVE.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("MOVE") -public @interface MOVE { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/OPTIONS.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/OPTIONS.java deleted file mode 100644 index 6436f9697..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/OPTIONS.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("OPTIONS") -public @interface OPTIONS { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/ORDERPATCH.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/ORDERPATCH.java deleted file mode 100644 index 1731d974c..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/ORDERPATCH.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("ORDERPATCH") -public @interface ORDERPATCH { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/PROPFIND.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/PROPFIND.java deleted file mode 100644 index 7badde6e0..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/PROPFIND.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("PROPFIND") -public @interface PROPFIND { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/PROPPATCH.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/PROPPATCH.java deleted file mode 100644 index 622098fa1..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/PROPPATCH.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("PROPPATCH") -public @interface PROPPATCH { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/REPORT.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/REPORT.java deleted file mode 100644 index 3a0309d13..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/REPORT.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("REPORT") -public @interface REPORT { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/SEARCH.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/SEARCH.java deleted file mode 100644 index ed4c97f5b..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/SEARCH.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("SEARCH") -public @interface SEARCH { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/UNCHECKOUT.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/UNCHECKOUT.java deleted file mode 100644 index a71f706f5..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/UNCHECKOUT.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("UNCHECKOUT") -public @interface UNCHECKOUT { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/UNLOCK.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/UNLOCK.java deleted file mode 100644 index ed37f3a5b..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/UNLOCK.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("UNLOCK") -public @interface UNLOCK { - -} diff --git a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/VERSIONCONTROL.java b/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/VERSIONCONTROL.java deleted file mode 100644 index 5dc74a8d0..000000000 --- a/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/webdav/method/VERSIONCONTROL.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.webdav.method; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.ws.rs.HttpMethod; - -/** - * Created by The eXo Platform SAS. - * @author Dmytro Katayev - * 22 Oct 2008 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@HttpMethod("VERSION-CONTROL") -public @interface VERSIONCONTROL { - -} diff --git a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java index a09f1fead..c8331a1fa 100644 --- a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java +++ b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java @@ -17,51 +17,43 @@ package org.exoplatform.services.rest.ext; -import junit.framework.TestCase; - import org.exoplatform.container.StandaloneContainer; -import org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher; import org.exoplatform.services.rest.impl.ApplicationContextImpl; import org.exoplatform.services.rest.impl.ProviderBinder; import org.exoplatform.services.rest.impl.RequestHandlerImpl; import org.exoplatform.services.rest.impl.ResourceBinder; import org.exoplatform.services.rest.tools.ResourceLauncher; +import junit.framework.TestCase; + /** * @author Andrey Parfonov * @version $Id$ */ -public abstract class BaseTest extends TestCase -{ - protected StandaloneContainer container; - - protected ProviderBinder providers; +public abstract class BaseTest extends TestCase { - protected ResourceBinder binder; + protected StandaloneContainer container; - protected RequestHandlerImpl requestHandler; + protected ProviderBinder providers; - protected GroovyJaxrsPublisher groovyPublisher; + protected ResourceBinder binder; - protected ResourceLauncher launcher; + protected RequestHandlerImpl requestHandler; - public void setUp() throws Exception - { - StandaloneContainer.setConfigurationPath("src/test/resources/conf/standalone/test-configuration.xml"); - container = StandaloneContainer.getInstance(); - binder = (ResourceBinder)container.getComponentInstanceOfType(ResourceBinder.class); - requestHandler = (RequestHandlerImpl)container.getComponentInstanceOfType(RequestHandlerImpl.class); - // reset providers to be sure it is clean - ProviderBinder.setInstance(new ProviderBinder()); - providers = ProviderBinder.getInstance(); - ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers)); - binder.clear(); - groovyPublisher = (GroovyJaxrsPublisher)container.getComponentInstanceOfType(GroovyJaxrsPublisher.class); - launcher = new ResourceLauncher(requestHandler); - } + protected ResourceLauncher launcher; - public void tearDown() throws Exception - { - } + @Override + public void setUp() throws Exception { + StandaloneContainer.setConfigurationPath("src/test/resources/conf/standalone/test-configuration.xml"); + container = StandaloneContainer.getInstance(); + binder = container.getComponentInstanceOfType(ResourceBinder.class); + requestHandler = container.getComponentInstanceOfType(RequestHandlerImpl.class); + // reset providers to be sure it is clean + ProviderBinder.setInstance(new ProviderBinder()); + providers = ProviderBinder.getInstance(); + ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers)); + binder.clear(); + launcher = new ResourceLauncher(requestHandler); + } } diff --git a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoaderTest.java b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoaderTest.java deleted file mode 100644 index 40cc1d48e..000000000 --- a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoaderTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -import org.exoplatform.services.rest.ext.BaseTest; - -import java.io.File; -import java.net.URL; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class DefaultGroovyResourceLoaderTest extends BaseTest -{ - private DefaultGroovyResourceLoader groovyResourceLoader; - private URL root; - - public void setUp() throws Exception - { - super.setUp(); - root = Thread.currentThread().getContextClassLoader().getResource("repo"); - root = new URL(root.toString() + '/'); - groovyResourceLoader = new DefaultGroovyResourceLoader(root); - } - - public void testLoadGroovySource() throws Exception - { - URL url = groovyResourceLoader.loadGroovySource("MyClass"); - assertNull(url); - File f = new File(new URL(root, "MyClass.groovy").toURI()); - f.createNewFile(); - // Clean up data so that Unit Test can be executed several time - f.deleteOnExit(); - url = groovyResourceLoader.loadGroovySource("MyClass"); - assertNotNull(url); - } -} diff --git a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java deleted file mode 100644 index 81342deae..000000000 --- a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.services.rest.ext.groovy; - -import groovy.lang.GroovyObject; - -import org.exoplatform.services.rest.ext.BaseTest; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Andrey Parfonov - * @version $Id$ - */ -@SuppressWarnings("rawtypes") -public class ExtendedClassLoaderTest extends BaseTest -{ - public void testParseClasses() throws Exception - { - ExtendedGroovyClassLoader loader = new GroovyClassLoaderProvider().getGroovyClassLoader(); - SourceFile[] sources = new SourceFile[2]; - sources[0] = new SourceFile(Thread.currentThread().getContextClassLoader().getResource("GMain1.groovy")); - sources[1] = - new SourceFile(Thread.currentThread().getContextClassLoader().getResource("repo/dependencies/Dep1.groovy")); - Class[] classes = loader.parseClasses(sources); - assertEquals(2, classes.length); - List names = new ArrayList(2); - for (Class c : classes) - names.add(c.getName()); - assertTrue(names.contains("GMain1")); - assertTrue(names.contains("dependencies.Dep1")); - } - - public void testParseClasses2() throws Exception - { - ExtendedGroovyClassLoader loader = - new GroovyClassLoaderProvider().getGroovyClassLoader(new SourceFolder[]{new SourceFolder(Thread - .currentThread().getContextClassLoader().getResource("repo"))}); - SourceFile[] sources = new SourceFile[1]; - sources[0] = new SourceFile(Thread.currentThread().getContextClassLoader().getResource("GMain1.groovy")); - Class[] classes = loader.parseClasses(sources); - assertEquals(1, classes.length); - List names = new ArrayList(1); - for (Class c : classes) - names.add(c.getName()); - assertTrue(names.contains("GMain1")); - } - - public void testParseClassWithDependency() throws Exception - { - ExtendedGroovyClassLoader loader = new GroovyClassLoaderProvider().getGroovyClassLoader(); - SourceFile[] sources = - new SourceFile[]{new SourceFile(Thread.currentThread().getContextClassLoader() - .getResource("repo/dependencies/Dep1.groovy"))}; - Class clazz = - loader.parseClass(Thread.currentThread().getContextClassLoader().getResourceAsStream("GMain1.groovy"), - "GMain1", sources); - assertEquals("GMain1", clazz.getName()); - assertEquals("dependencies.Dep1", ((GroovyObject)clazz.newInstance()).invokeMethod("m0", new Object[0])); - } -} diff --git a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java deleted file mode 100644 index f05fc800d..000000000 --- a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -import org.exoplatform.services.rest.ext.BaseTest; -import org.exoplatform.services.rest.impl.ContainerResponse; -import org.exoplatform.services.rest.impl.EnvironmentContext; -import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter; -import org.exoplatform.services.test.mock.MockHttpServletRequest; - -import java.io.InputStream; - -import jakarta.servlet.http.HttpServletRequest; - -/** - * @author Andrey Parfonov - * @version $Id: GroovyContextParamTest.java 2647 2010-06-17 08:39:29Z aparfonov - * $ - */ -public class GroovyContextParamTest extends BaseTest -{ - - private InputStream script; - - public void setUp() throws Exception - { - super.setUp(); - script = Thread.currentThread().getContextClassLoader().getResourceAsStream("groovy1.groovy"); - assertNotNull(script); - } - - @Override - public void tearDown() throws Exception - { - groovyPublisher.resources.clear(); - super.tearDown(); - } - - public void testPerRequest() throws Exception - { - assertEquals(0, binder.getSize()); - assertEquals(0, groovyPublisher.resources.size()); - - groovyPublisher.publishPerRequest(script, new BaseResourceId("g1"), null); - - assertEquals(1, binder.getSize()); - assertEquals(1, groovyPublisher.resources.size()); - - ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter(); - - EnvironmentContext envctx = new EnvironmentContext(); - - HttpServletRequest httpRequest = - new MockHttpServletRequest("http://localhost:8080/context/a/b", null, 0, "GET", null); - envctx.put(HttpServletRequest.class, httpRequest); - - ContainerResponse resp = - launcher.service("GET", "http://localhost:8080/context/a/b", "http://localhost:8080/context", null, null, - writer, envctx); - assertEquals(200, resp.getStatus()); - assertEquals("GET\n/context/a/b", new String(writer.getBody())); - } - -} diff --git a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyDependenciesTest.java b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyDependenciesTest.java deleted file mode 100644 index 252ad55ea..000000000 --- a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyDependenciesTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -import org.exoplatform.services.rest.ext.BaseTest; -import org.exoplatform.services.rest.impl.ContainerResponse; -import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter; - -import java.io.InputStream; -import java.net.URL; - -/** - * @author Andrey Parfonov - * @version $Id$ - */ -public class GroovyDependenciesTest extends BaseTest -{ - private InputStream script; - - @Override - public void setUp() throws Exception - { - super.setUp(); - URL root = Thread.currentThread().getContextClassLoader().getResource("repo"); - DefaultGroovyResourceLoader groovyResourceLoader = new DefaultGroovyResourceLoader(root); - groovyPublisher.getGroovyClassLoader().setResourceLoader(groovyResourceLoader); - - script = Thread.currentThread().getContextClassLoader().getResourceAsStream("GMain1.groovy"); - assertNotNull(script); - } - - public void testDependency() throws Exception - { - groovyPublisher.publishPerRequest(script, new BaseResourceId("GMain1"), null); - ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter(); - ContainerResponse resp = launcher.service("GET", "/a", "", null, null, writer, null); - assertEquals(200, resp.getStatus()); - assertEquals("dependencies.Dep1", new String(writer.getBody())); - } - - @Override - public void tearDown() throws Exception - { - groovyPublisher.resources.clear(); - super.tearDown(); - } -} diff --git a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java deleted file mode 100644 index 37914e79c..000000000 --- a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -import org.exoplatform.services.rest.ext.BaseTest; -import org.exoplatform.services.rest.impl.ContainerResponse; -import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter; - -import java.io.InputStream; - -/** - * @author Andrey Parfonov - * @version $Id$ - */ -public class GroovyExoComponentTest extends BaseTest -{ - - private InputStream script; - - @Override - public void setUp() throws Exception - { - super.setUp(); - container.registerComponentInstance(Component1.class.getName(), new Component1()); - script = Thread.currentThread().getContextClassLoader().getResourceAsStream("groovy2.groovy"); - assertNotNull(script); - } - - @Override - public void tearDown() throws Exception - { - container.unregisterComponent(Component1.class.getName()); - groovyPublisher.resources.clear(); - super.tearDown(); - } - - public void testExoComponentPerRequest() throws Exception - { - containerComponentTest(false, new BaseResourceId("g1")); - } - - public void testExoComponentSingleton() throws Exception - { - containerComponentTest(true, new BaseResourceId("g2")); - } - - private void containerComponentTest(boolean singleton, ResourceId resourceId) throws Exception - { - assertEquals(0, binder.getSize()); - assertEquals(0, groovyPublisher.resources.size()); - - if (singleton) - groovyPublisher.publishSingleton(script, resourceId, null); - else - groovyPublisher.publishPerRequest(script, resourceId, null); - - assertEquals(1, binder.getSize()); - assertEquals(1, groovyPublisher.resources.size()); - - ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter(); - ContainerResponse resp = launcher.service("GET", "/a/b", "", null, null, writer, null); - assertEquals(200, resp.getStatus()); - assertEquals("exo container's component", new String(writer.getBody())); - } - - public static class Component1 - { - public String getName() - { - return "exo container's component"; - } - } - -} diff --git a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java b/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java deleted file mode 100644 index 3b04bdaae..000000000 --- a/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the Meeds project (https://meeds.io/). - * Copyright (C) 2020 Meeds Association - * contact@meeds.io - * This program 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 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 - * Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.exoplatform.services.rest.ext.groovy; - -import org.exoplatform.services.rest.ext.BaseTest; -import org.exoplatform.services.rest.impl.ContainerResponse; -import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter; - -/** - * @author Andrey Parfonov - * @version $Id$ - */ -public class GroovySimpleTest extends BaseTest -{ - - @Override - public void tearDown() throws Exception - { - groovyPublisher.resources.clear(); - super.tearDown(); - } - - public void testPerRequest() throws Exception - { - publicationTest(false, new BaseResourceId("g1")); - } - - public void testSingleton() throws Exception - { - publicationTest(true, new BaseResourceId("g2")); - } - - private void publicationTest(boolean singleton, ResourceId resourceId) throws Exception - { - String script = // - "@javax.ws.rs.Path(\"a\")" // - + "class GroovyResource {" // - + "@javax.ws.rs.GET @javax.ws.rs.Path(\"{who}\")" // - + "def m0(@javax.ws.rs.PathParam(\"who\") String who) { return (\"hello \" + who)}" // - + "}"; - - assertEquals(0, binder.getSize()); - assertEquals(0, groovyPublisher.resources.size()); - - if (singleton) - groovyPublisher.publishSingleton(script, resourceId, null); - else - groovyPublisher.publishPerRequest(script, resourceId, null); - - assertEquals(1, binder.getSize()); - assertEquals(1, groovyPublisher.resources.size()); - assertTrue(groovyPublisher.isPublished(resourceId)); - - String cs = - binder.getResources().get(0).getObjectModel().getObjectClass().getProtectionDomain().getCodeSource() - .getLocation().toString(); - assertEquals("file:/groovy/script/jaxrs", cs); - - ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter(); - ContainerResponse resp = launcher.service("GET", "/a/groovy", "", null, null, writer, null); - assertEquals(200, resp.getStatus()); - assertEquals("hello groovy", new String(writer.getBody())); - - groovyPublisher.unpublishResource(resourceId); - - assertEquals(0, binder.getSize()); - assertEquals(0, groovyPublisher.resources.size()); - } - -}