merge for release 4.13.1

git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/common/common-smartgears/2.1@174727 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Lucio Lelii 2018-12-10 17:36:19 +00:00
parent a49c4de5dd
commit 1b60aa2d44
18 changed files with 223 additions and 76 deletions

View File

@ -27,7 +27,7 @@
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

View File

@ -1 +1,4 @@
${gcube.license}
gCube System - License
------------------------------------------------------------
${gcube.license}

View File

@ -10,13 +10,13 @@
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<outputDirectory>${file.separator}</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
@ -24,9 +24,8 @@
</fileSets>
<files>
<file>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
<source>target${file.separator}${build.finalName}.${project.packaging}</source>
<outputDirectory>${file.separator}${artifactId}</outputDirectory>
</file>
</files>
</assembly>

View File

@ -1,14 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!DOCTYPE xml>
<Resource>
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>Common</Class>
<Class>${serviceClass}</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${description}</Description>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
@ -16,8 +18,9 @@
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Type>Library</Type>
<Files>
<File>${build.finalName}.jar</File>
<File>${build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.6-SNAPSHOT</version>
<name>SmartGears</name>
<dependencyManagement>
@ -149,7 +149,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<version>1.2.3</version>
<scope>runtime</scope>
</dependency>

View File

@ -84,7 +84,7 @@ public class Constants {
/**
* The wildcard exclude directive.
*/
public static final String EXCLUDE_ALL = "*";
public static final String WILDCARD = "*";
/**

View File

@ -138,6 +138,12 @@ public interface ApplicationConfiguration {
*/
Set<Exclude> excludes();
/**
* Returns a set of request paths that should be subjected to request management.
* @return the set of exclude paths.
*/
Set<Include> includes();
/**
* Sets the persistence manager of the application.
@ -162,6 +168,8 @@ public interface ApplicationConfiguration {
void merge(ApplicationConfiguration config);
ApplicationConfiguration excludes(Exclude ... excludes);
ApplicationConfiguration includes(Include ... includes);

View File

@ -120,6 +120,11 @@ public class BridgedApplicationConfiguration implements ApplicationConfiguration
return application.excludes();
}
@Override
public Set<Include> includes() {
return application.includes();
}
@Override
public void merge(ApplicationConfiguration config) {
application.merge(config);
@ -159,4 +164,11 @@ public class BridgedApplicationConfiguration implements ApplicationConfiguration
public ApplicationConfiguration excludes(Exclude ... excludes) {
return application.excludes(excludes);
}
@Override
public ApplicationConfiguration includes(Include... includes) {
return application.includes(includes);
}
}

View File

@ -67,6 +67,9 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
@XmlElementRef
Set<Exclude> excludes= new LinkedHashSet<Exclude>();
@XmlElementRef
Set<Include> includes= new LinkedHashSet<Include>();
@XmlElementRef(type=DefaultPersistence.class)
@NotNull @IsValid
@ -77,6 +80,11 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
return excludes;
}
@Override
public Set<Include> includes() {
return includes;
}
public DefaultApplicationConfiguration() {}
@Override
@ -111,6 +119,12 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
return this;
}
@Override
public ApplicationConfiguration includes(Include... includes) {
this.includes=new HashSet<Include>(Arrays.asList(includes));
return this;
}
@Override
public ApplicationConfiguration name(String name) {
this.name=name;
@ -207,6 +221,9 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
for (ValidationError error : validator.validate(this))
msgs.add(error.toString());
if (!this.excludes().isEmpty() && !this.includes().isEmpty())
msgs.add("exclude tags and includes tags are mutually exclusive");
if (!msgs.isEmpty())
throw new IllegalStateException("invalid configuration: "+msgs);
@ -309,4 +326,6 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
return true;
}
}

View File

@ -0,0 +1,79 @@
package org.gcube.smartgears.configuration.application;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
@XmlRootElement(name="include")
@XmlAccessorType(XmlAccessType.FIELD)
public class Include {
@XmlAttribute(name="handlers")
private List<String> handlers = new ArrayList<String>();
@XmlValue
private String path;
public List<String> getHandlers() {
return handlers;
}
public String getPath() {
return path;
}
protected Include() {}
public Include(String path) {
super();
this.path = path;
}
public Include(List<String> handlers, String path) {
super();
this.handlers = handlers;
this.path = path;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((path == null) ? 0 : path.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Include other = (Include) obj;
if (handlers == null) {
if (other.handlers != null)
return false;
} else if (!handlers.equals(other.handlers))
return false;
if (path == null) {
if (other.path != null)
return false;
} else if (!path.equals(other.path))
return false;
return true;
}
@Override
public String toString() {
return "Include [handlers=" + handlers + ", path=" + path + "]";
}
}

View File

@ -5,8 +5,6 @@ package org.gcube.smartgears.handlers.container.lifecycle;
import static org.gcube.smartgears.Constants.accounting_management;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
@ -26,7 +24,7 @@ public class AccountingManager extends ContainerHandler {
@Override
public void onStop(ContainerLifecycleEvent.Stop e) {
logger.trace("Going to flush accounting data");
AccountingPersistenceFactory.shutDown(1000, TimeUnit.MILLISECONDS);
AccountingPersistenceFactory.shutDown();
}
@Override

View File

@ -77,7 +77,7 @@ public class ApplicationManager {
context.configuration().validate();
if (context.configuration().secure() &&
container.configuration().securePort()==null)
throw new IllegalStateException(
@ -128,11 +128,14 @@ public class ApplicationManager {
return context;
} catch (RuntimeException e) {
log.error("error starting application {} ", context.name(),e);
if (context != null)
if (context != null) {
log.error("error starting application {}",context.name(), e);
context.lifecycle().moveTo(failed);
} else
log.error("error starting application with context not initialized",e );
throw e;
}
@ -240,9 +243,12 @@ public class ApplicationManager {
extension.init(context);
//register excludes
context.configuration().excludes().addAll(extension.excludes());
if (context.configuration().includes().isEmpty()) {
//register excludes for extension in case of includes they are excluded by default
context.configuration().excludes().addAll(extension.excludes());
}
String mapping = extension.mapping();
application.addServlet(context.configuration().name() + "-" + extension.name(), extension)

View File

@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.gcube.smartgears.configuration.application.Exclude;
import org.gcube.smartgears.configuration.application.Include;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.context.application.DefaultApplicationContext;
import org.gcube.smartgears.handlers.application.ApplicationPipeline;
@ -63,20 +64,20 @@ public class RequestManager implements Filter {
HttpServletRequest httprequest = (HttpServletRequest) request;
HttpServletResponse httpresponse = (HttpServletResponse) response;
List<RequestHandler> filterHandlers = getPipelineWithExcluded(httprequest, handlers);
List<RequestHandler> filterHandlers = getPipelineHandlers(httprequest, handlers);
if (filterHandlers.isEmpty()){
log.trace("filtered handlers are empty");
chain.doFilter(request, response);
}else {
ApplicationPipeline<RequestHandler> pipeline = new ApplicationPipeline<RequestHandler>(filterHandlers);
log.trace("filtered handler for this call are {}", filterHandlers);
// create a per-request context with temporary properties
ApplicationContext ctx = new DefaultApplicationContext(context);
@ -112,44 +113,66 @@ public class RequestManager implements Filter {
}
}
private List<RequestHandler> getPipelineWithExcluded(
private List<RequestHandler> getPipelineHandlers(
HttpServletRequest request, List<RequestHandler> handlersToFilter) {
String query = request.getQueryString();
log.debug("servletPath is {} and pathInfo is {}",request.getServletPath(), request.getPathInfo());
if ("wsdl".equals(query) || "wsdl=1".equals(query))
return Collections.emptyList();
String path = request.getServletPath()==null?"":request.getServletPath();
path += request.getPathInfo() ==null?"":request.getPathInfo();
log.debug("check wich handler should be excluded {}", path);
for (Exclude exclude : context.configuration().excludes()){
String excludePath= exclude.getPath();
log.trace("exclude is {}",exclude);
if (
(EXCLUDE_ALL).equals(excludePath) ||
(excludePath.endsWith(EXCLUDE_ALL) && path!=null && path.startsWith(excludePath.substring(0,excludePath.length()-2))) ||
excludePath.equals(path) || (path.endsWith("/") && excludePath.equals(path.substring(0, path.length()-1)))
){
//ALL handler are filtered
if (exclude.getHandlers().isEmpty()) return Collections.emptyList();
List<RequestHandler> filteredHandlers = new ArrayList<>();
for (RequestHandler rh : handlersToFilter){
if (!exclude.getHandlers().contains(rh.getName()))
filteredHandlers.add(rh);
if (!context.configuration().excludes().isEmpty()) {
for (Exclude exclude : context.configuration().excludes()){
String excludePath= exclude.getPath();
log.trace("exclude is {}",exclude);
if (
(WILDCARD).equals(excludePath) ||
(excludePath.endsWith(WILDCARD) && path!=null && path.startsWith(excludePath.substring(0,excludePath.length()-2))) ||
excludePath.equals(path) || (path.endsWith("/") && excludePath.equals(path.substring(0, path.length()-1)))
){
//ALL handler are filtered
if (exclude.getHandlers().isEmpty()) return Collections.emptyList();
List<RequestHandler> filteredHandlers = new ArrayList<>();
for (RequestHandler rh : handlersToFilter){
if (!exclude.getHandlers().contains(rh.getName()))
filteredHandlers.add(rh);
}
return filteredHandlers;
}
return filteredHandlers;
}
}
} else if (!context.configuration().includes().isEmpty()) {
for (Include include : context.configuration().includes()){
String includePath= include.getPath();
log.trace("include is {}",include);
if (
(WILDCARD).equals(includePath) ||
(includePath.endsWith(WILDCARD) && path!=null && path.startsWith(includePath.substring(0,includePath.length()-2))) ||
includePath.equals(path) || (path.endsWith("/") && includePath.equals(path.substring(0, path.length()-1)))
){
//ALL handler are used
if (include.getHandlers().isEmpty()) return handlersToFilter;
List<RequestHandler> filteredHandlers = new ArrayList<>();
for (RequestHandler rh : handlersToFilter){
if (include.getHandlers().contains(rh.getName()))
filteredHandlers.add(rh);
}
return filteredHandlers;
}
}
return new ArrayList<>();
}
//in case no path is recognized in excludes it return all handlers
return handlersToFilter;
}
@ -186,23 +209,23 @@ public class RequestManager implements Filter {
}
// helpers
/*
/*
private boolean shouldExcludeRequest(HttpServletRequest request) {
String query = request.getQueryString();
log.debug("servletPath is {} and pathInfo is {}",request.getServletPath(), request.getPathInfo());
if ("wsdl".equals(query) || "wsdl=1".equals(query))
return true;
String path = request.getServletPath()==null?"":request.getServletPath();
path += request.getPathInfo() ==null?"":request.getPathInfo();
log.debug("check if should exclude call with path {}", path);
for (Exclude exclude : context.configuration().excludes()){
if (!exclude.getHandlers().isEmpty()) continue;
String excludePath= exclude.getPath();

View File

@ -16,7 +16,6 @@ import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.FileUtils;
import org.apache.tomcat.util.scan.StandardJarScanner;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.ScopedPublisher;
import org.gcube.smartgears.Constants;
import org.gcube.smartgears.configuration.Mode;
@ -35,11 +34,11 @@ import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import com.sun.jersey.api.client.ClientResponse;
import utils.TestProvider;
import utils.TestUtils;
import com.sun.jersey.api.client.ClientResponse;
/**
* Simulates a single-servlet application to be transformed into a gCube resource.
* <p>

View File

@ -133,7 +133,7 @@ public class CallValidationTest {
SomeApp app = new SomeApp();
app.configuration().excludes().add(new Exclude(Constants.EXCLUDE_ALL));
app.configuration().excludes().add(new Exclude(Constants.WILDCARD));
app.handlers().set(new ProfileManager()).set(new RequestValidator());
@ -160,7 +160,7 @@ public class CallValidationTest {
SomeApp app = new SomeApp();
app.configuration().excludes().add(new Exclude("/path"+Constants.EXCLUDE_ALL));
app.configuration().excludes().add(new Exclude("/path"+Constants.WILDCARD));
app.handlers().set(new ProfileManager()).set(new RequestValidator());

View File

@ -12,6 +12,7 @@ import org.gcube.smartgears.configuration.application.ApplicationConfigurationBi
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
import org.gcube.smartgears.configuration.application.DefaultApplicationConfiguration;
import org.gcube.smartgears.configuration.application.Exclude;
import org.gcube.smartgears.configuration.application.Include;
import org.gcube.smartgears.extensions.ApplicationExtension;
import org.gcube.smartgears.persistence.DefaultPersistence;
import org.junit.Test;
@ -28,7 +29,7 @@ public class ConfigurationTest {
"<description>desc</description>" +
"<scope>start/scope</scope>"+
"<scope>another/start/scope</scope>"+
"<exclude handlers='request-validation request-accounting'>/path</exclude>" +
"<include>/pathBis</include>" +
"<persistence location='target'/>" +
"</application>";
@ -37,6 +38,7 @@ public class ConfigurationTest {
ApplicationConfiguration bound = binder.bind(new ByteArrayInputStream(xml.getBytes()));
System.out.println(bound);
assertEquals(sampleConfiguration(),bound);
@ -104,7 +106,7 @@ public class ConfigurationTest {
.context("ctx")
.name("name")
.serviceClass("class")
.excludes(new Exclude(Arrays.asList("request-validation","request-accounting"),"/path"))
.includes(new Include("/pathBis"))
.version("version")
.description("desc")
.persistence(new DefaultPersistence("target"));

View File

@ -15,10 +15,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.informationsystem.publisher.ScopedPublisher;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
@ -36,8 +33,8 @@ import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;
import utils.TestUtils.Box;
import app.SomeApp;
import utils.TestUtils.Box;
public class StartupTest {
@ -214,7 +211,7 @@ public class StartupTest {
assertEquals(active,context.lifecycle().state());
Set<String> runningScopes = new HashSet<>(context.profile(GCoreEndpoint.class).scopes().asCollection());
//Set<String> runningScopes = new HashSet<>(context.profile(GCoreEndpoint.class).scopes().asCollection());
//assertEquals(singleton(vre),runningScopes);

View File

@ -2,7 +2,6 @@ package utils;
import javax.servlet.ServletContext;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.ScopedPublisher;
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.configuration.application.ApplicationExtensions;