removed all JAXB dependencies
This commit is contained in:
parent
e48f50e91b
commit
766238c8e3
16
pom.xml
16
pom.xml
|
@ -37,6 +37,16 @@
|
||||||
<url>https://code-repo.d4science.org/gCubeSystem/common-smartgears</url>
|
<url>https://code-repo.d4science.org/gCubeSystem/common-smartgears</url>
|
||||||
</scm>
|
</scm>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.9.10</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>1.21</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.classgraph</groupId>
|
<groupId>io.github.classgraph</groupId>
|
||||||
<artifactId>classgraph</artifactId>
|
<artifactId>classgraph</artifactId>
|
||||||
|
@ -106,12 +116,6 @@
|
||||||
<version>4.0.1</version>
|
<version>4.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Added to support Java 11 JDK -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.xml.bind</groupId>
|
|
||||||
<artifactId>jaxb-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- END Added to support Java 11 JDK -->
|
|
||||||
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-core -->
|
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-core -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.micrometer</groupId>
|
<groupId>io.micrometer</groupId>
|
||||||
|
|
|
@ -86,6 +86,7 @@ public class Bootstrap implements ServletContainerInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
|
@SuppressWarnings("resource")
|
||||||
private void initialiseContainer() {
|
private void initialiseContainer() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class Constants {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The container configuration file path, relative to the container configuration directory.
|
* The container configuration file path, relative to the container configuration directory.
|
||||||
*/
|
*/
|
||||||
public static final String container_configuraton_file_path = "container.ini";
|
public static final String container_configuraton_file_path = "container.ini";
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,19 +36,15 @@ public class Constants {
|
||||||
*/
|
*/
|
||||||
public static final String container_profile_file_path = "ghn.xml";
|
public static final String container_profile_file_path = "ghn.xml";
|
||||||
|
|
||||||
|
/*
|
||||||
public static final String container_profile_file_path_copy = "ghn.xml.copy";
|
public static final String container_profile_file_path_copy = "ghn.xml.copy";
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* The library configuration resource path.
|
|
||||||
*/
|
|
||||||
public static final String library_configuration_file_path = "/META-INF/smartgears-config.xml";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the context property that contains the node profile.
|
* The name of the context property that contains the node profile.
|
||||||
*/
|
|
||||||
public static final String container_profile_property = "ghn-profile";
|
public static final String container_profile_property = "ghn-profile";
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default value of for the container publication frequency.
|
* The default value of for the container publication frequency.
|
||||||
|
@ -59,7 +55,7 @@ public class Constants {
|
||||||
/**
|
/**
|
||||||
* The application configuration resource path.
|
* The application configuration resource path.
|
||||||
*/
|
*/
|
||||||
public static final String configuration_file_path = "/WEB-INF/gcube-app.xml";
|
public static final String configuration_file_path = "/WEB-INF/application.yaml";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,16 +69,6 @@ public class Constants {
|
||||||
*/
|
*/
|
||||||
public static final String root_mapping = "/gcube/resource";
|
public static final String root_mapping = "/gcube/resource";
|
||||||
|
|
||||||
/**
|
|
||||||
* The application extensions configuration resource path.
|
|
||||||
*/
|
|
||||||
public static final String extensions_file_path = "/WEB-INF/gcube-extensions.xml";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default application extensions configuration resource path.
|
|
||||||
*/
|
|
||||||
public static final String default_extensions_file_path = "/META-INF/default-extensions.xml";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The application frontpage resource path.
|
* The application frontpage resource path.
|
||||||
*/
|
*/
|
||||||
|
@ -126,8 +112,6 @@ public class Constants {
|
||||||
public static final String remote_management = "remote-management";
|
public static final String remote_management = "remote-management";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path of the application profile file, relative to the service configuration directory.
|
* The path of the application profile file, relative to the service configuration directory.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.gcube.smartgears.configuration;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo.As;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
|
||||||
|
|
||||||
|
@JsonTypeInfo(include=As.PROPERTY, use=Id.CLASS, property= "className")
|
||||||
|
public interface ComponentConfiguration {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.gcube.smartgears.configuration;
|
||||||
|
|
||||||
|
public interface Configurable {
|
||||||
|
|
||||||
|
void configure(ComponentConfiguration configuration);
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.gcube.smartgears.configuration;
|
||||||
|
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface ConfiguredWith {
|
||||||
|
|
||||||
|
public Class<? extends ComponentConfiguration> value();
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.gcube.smartgears.configuration;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
import org.gcube.common.validator.annotations.IsValid;
|
||||||
|
import org.gcube.common.validator.annotations.NotNull;
|
||||||
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||||
|
|
||||||
|
@JsonInclude(value = Include.NON_NULL)
|
||||||
|
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||||
|
public class PersistenceConfiguration {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Class<? extends PersistenceWriter> implementationClass;
|
||||||
|
|
||||||
|
@IsValid
|
||||||
|
private ComponentConfiguration writerConfiguration;
|
||||||
|
|
||||||
|
protected PersistenceConfiguration() {}
|
||||||
|
|
||||||
|
public <T extends ComponentConfiguration> PersistenceConfiguration(Class<? extends PersistenceWriter> implementationClass, T writerConfiguration) {
|
||||||
|
super();
|
||||||
|
this.implementationClass = implementationClass;
|
||||||
|
this.writerConfiguration = writerConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<? extends PersistenceWriter> getImplementationClass() {
|
||||||
|
return this.implementationClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComponentConfiguration getWriterConfiguration() {
|
||||||
|
return writerConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,140 +1,182 @@
|
||||||
package org.gcube.smartgears.configuration.application;
|
package org.gcube.smartgears.configuration.application;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import org.gcube.common.validator.ValidationError;
|
||||||
|
import org.gcube.common.validator.Validator;
|
||||||
|
import org.gcube.common.validator.ValidatorFactory;
|
||||||
|
import org.gcube.common.validator.annotations.NotEmpty;
|
||||||
|
import org.gcube.common.validator.annotations.NotNull;
|
||||||
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configuration of the application.
|
* The configuration of a managed app.
|
||||||
*
|
* <p>
|
||||||
* @author Fabio Simeoni
|
* Includes the list of its client services.
|
||||||
|
*
|
||||||
|
* @author Lucio Lelii
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface ApplicationConfiguration {
|
@JsonInclude(value = Include.NON_NULL)
|
||||||
|
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||||
|
public class ApplicationConfiguration {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String name;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String group;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String version;
|
||||||
|
|
||||||
|
String description="";
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
String context;
|
||||||
|
|
||||||
|
private boolean proxable = true;
|
||||||
|
|
||||||
/**
|
Set<GCubeExclude> excludes= null;
|
||||||
* Returns the context path of the application
|
|
||||||
* @return the context path
|
|
||||||
*/
|
|
||||||
String context();
|
|
||||||
|
|
||||||
boolean proxable();
|
Set<GCubeInclude> includes= null;
|
||||||
|
|
||||||
ProxyAddress proxyAddress();
|
@NotEmpty @JsonProperty("persistence")
|
||||||
|
PersistenceConfiguration persistenceConfiguration;
|
||||||
|
|
||||||
ApplicationConfiguration proxyAddress(ProxyAddress proxy);
|
public Set<GCubeExclude> excludes() {
|
||||||
|
return excludes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public Set<GCubeInclude> includes() {
|
||||||
* Sets the context path of the application
|
return includes;
|
||||||
* @param context the context path
|
}
|
||||||
* @return this configuration
|
|
||||||
*/
|
|
||||||
ApplicationConfiguration context(String context);
|
|
||||||
|
|
||||||
|
public ApplicationConfiguration() {}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String context() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration excludes(GCubeExclude ... excludes) {
|
||||||
|
this.excludes=new HashSet<GCubeExclude>(Arrays.asList(excludes));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration includes(GCubeInclude... includes) {
|
||||||
|
this.includes=new HashSet<GCubeInclude>(Arrays.asList(includes));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration context(String context) {
|
||||||
|
this.context = context;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration name(String name) {
|
||||||
|
this.name=name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration persistenceConfiguration(PersistenceConfiguration configuration) {
|
||||||
|
this.persistenceConfiguration = configuration;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration proxable(boolean proxable) {
|
||||||
|
this.proxable = proxable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serviceClass() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ApplicationConfiguration serviceClass(String group) {
|
||||||
|
this.group=group;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String version() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration version(String version) {
|
||||||
|
this.version=version;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String description() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfiguration description(String description) {
|
||||||
|
this.description=description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean proxable() {
|
||||||
|
return proxable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public PersistenceConfiguration persistenceConfiguration() {
|
||||||
* Returns the name of the application.
|
return persistenceConfiguration;
|
||||||
* @return the name
|
}
|
||||||
*/
|
|
||||||
String name();
|
public void validate() {
|
||||||
|
|
||||||
|
List<String> msgs = new ArrayList<String>();
|
||||||
/**
|
|
||||||
* Sets the name of the application.
|
Validator validator = ValidatorFactory.validator();
|
||||||
* @param name the name
|
|
||||||
* @return this configuration
|
for (ValidationError error : validator.validate(this))
|
||||||
*/
|
msgs.add(error.toString());
|
||||||
ApplicationConfiguration name(String name);
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns the class of the application
|
public int hashCode() {
|
||||||
* @return the class
|
return Objects.hash(description, excludes, group, includes, name, proxable, version);
|
||||||
*/
|
}
|
||||||
String serviceClass();
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Sets the class of the application.
|
public boolean equals(Object obj) {
|
||||||
* @param serviceClass the class
|
if (this == obj)
|
||||||
* @return this configuration
|
return true;
|
||||||
*/
|
if (obj == null)
|
||||||
ApplicationConfiguration serviceClass(String serviceClass);
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
/**
|
return false;
|
||||||
* Returns the version of the application.
|
ApplicationConfiguration other = (ApplicationConfiguration) obj;
|
||||||
* @return the version
|
return Objects.equals(description, other.description)
|
||||||
*/
|
&& Objects.equals(excludes, other.excludes) && Objects.equals(group, other.group)
|
||||||
String version();
|
&& Objects.equals(includes, other.includes) && Objects.equals(name, other.name)
|
||||||
|
&& proxable == other.proxable && Objects.equals(version, other.version);
|
||||||
/**
|
}
|
||||||
* Sets the version of the application.
|
|
||||||
* @param version the version
|
|
||||||
* @return this configuration
|
|
||||||
*/
|
|
||||||
ApplicationConfiguration version(String version);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the description of the application.
|
|
||||||
* @return the description
|
|
||||||
*/
|
|
||||||
String description();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the description of the application.
|
|
||||||
* @param description the description
|
|
||||||
* @return this configuration
|
|
||||||
*/
|
|
||||||
ApplicationConfiguration description(String description);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the persistence manager of the application.
|
|
||||||
* @return the manager
|
|
||||||
*/
|
|
||||||
PersistenceWriter persistence();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a set of request paths that should not be subjected to request management.
|
|
||||||
* @return the set of exclude paths.
|
|
||||||
*/
|
|
||||||
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.
|
|
||||||
* @param manager the manager
|
|
||||||
* @return this configuration
|
|
||||||
*/
|
|
||||||
ApplicationConfiguration persistence(PersistenceWriter manager);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates this configuration.
|
|
||||||
*
|
|
||||||
* @throws IllegalStateException if the configuration is not valid
|
|
||||||
*/
|
|
||||||
void validate();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges this configuration with another configuration
|
|
||||||
* @param config the other configuration
|
|
||||||
*/
|
|
||||||
void merge(ApplicationConfiguration config);
|
|
||||||
|
|
||||||
ApplicationConfiguration excludes(Exclude ... excludes);
|
|
||||||
|
|
||||||
ApplicationConfiguration includes(Include ... includes);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,26 +1,17 @@
|
||||||
package org.gcube.smartgears.configuration.application;
|
package org.gcube.smartgears.configuration.application;
|
||||||
|
|
||||||
import static org.gcube.smartgears.utils.Utils.closeSafely;
|
|
||||||
import static org.gcube.smartgears.utils.Utils.unchecked;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ServiceLoader;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
|
|
||||||
import org.gcube.smartgears.extensions.ApplicationExtension;
|
|
||||||
import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler;
|
import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler;
|
||||||
import org.gcube.smartgears.handlers.application.RequestHandler;
|
import org.gcube.smartgears.handlers.application.RequestHandler;
|
||||||
import org.gcube.smartgears.handlers.application.lifecycle.ApplicationProfileManager;
|
import org.gcube.smartgears.handlers.application.lifecycle.ApplicationProfileManager;
|
||||||
import org.gcube.smartgears.handlers.application.request.RequestAccounting;
|
import org.gcube.smartgears.handlers.application.request.RequestAccounting;
|
||||||
import org.gcube.smartgears.handlers.application.request.RequestMetrics;
|
import org.gcube.smartgears.handlers.application.request.RequestMetrics;
|
||||||
import org.gcube.smartgears.handlers.application.request.RequestValidator;
|
import org.gcube.smartgears.handlers.application.request.RequestValidator;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds {@link ApplicationConfiguration}s to and from XML serialisations.
|
* Binds {@link ApplicationConfiguration}s to and from XML serialisations.
|
||||||
|
@ -37,21 +28,15 @@ public class ApplicationConfigurationBinder {
|
||||||
* @return the configuration
|
* @return the configuration
|
||||||
* @throws RuntimeException if the serialisation is invalid
|
* @throws RuntimeException if the serialisation is invalid
|
||||||
*/
|
*/
|
||||||
public ApplicationConfiguration bind(InputStream stream) {
|
public ApplicationConfiguration load(InputStream stream) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Yaml yaml = new Yaml();
|
||||||
JAXBContext ctx = JAXBContext.newInstance(DefaultApplicationConfiguration.class);
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String mapAsString = mapper.writeValueAsString(yaml.load(stream));
|
||||||
return (ApplicationConfiguration) ctx.createUnmarshaller().unmarshal(stream);
|
|
||||||
|
return mapper.readValue(mapAsString, ApplicationConfiguration.class);
|
||||||
} catch (JAXBException e) {
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
throw new RuntimeException("invalid service configuration", e);
|
|
||||||
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
closeSafely(stream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +77,7 @@ public class ApplicationConfigurationBinder {
|
||||||
* @param stream the serialisation
|
* @param stream the serialisation
|
||||||
* @return the extensions
|
* @return the extensions
|
||||||
* @throws RuntimeException if the serialisation is invalid
|
* @throws RuntimeException if the serialisation is invalid
|
||||||
*/
|
|
||||||
public ApplicationExtensions bindExtensions(InputStream stream) {
|
public ApplicationExtensions bindExtensions(InputStream stream) {
|
||||||
|
|
||||||
//collects handler classes
|
//collects handler classes
|
||||||
|
@ -136,7 +121,8 @@ public class ApplicationConfigurationBinder {
|
||||||
|
|
||||||
return scanned;
|
return scanned;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public void scanForApplicationHandlers(ClassLoader currentClassLoader) {
|
public void scanForApplicationHandlers(ClassLoader currentClassLoader) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
package org.gcube.smartgears.configuration.application;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.xml.bind.Unmarshaller;
|
|
||||||
import javax.xml.bind.annotation.XmlAnyElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
import org.gcube.common.validator.ValidationError;
|
|
||||||
import org.gcube.common.validator.Validator;
|
|
||||||
import org.gcube.common.validator.ValidatorFactory;
|
|
||||||
import org.gcube.common.validator.annotations.IsValid;
|
|
||||||
import org.gcube.smartgears.extensions.ApplicationExtension;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link ApplicationExtension}s that manage the application.
|
|
||||||
*
|
|
||||||
* @author Fabio Simeoni
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@XmlRootElement(name="extensions")
|
|
||||||
public class ApplicationExtensions {
|
|
||||||
|
|
||||||
@XmlAnyElement(lax=true) @IsValid
|
|
||||||
List<ApplicationExtension> extensions = new ArrayList<ApplicationExtension>();
|
|
||||||
|
|
||||||
public ApplicationExtensions() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the extensions for the application.
|
|
||||||
* @return the extensions
|
|
||||||
*/
|
|
||||||
public List<ApplicationExtension> extensions() {
|
|
||||||
return extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the extensions for the application.
|
|
||||||
* @param extensions the extensions
|
|
||||||
* @return this configuration
|
|
||||||
*/
|
|
||||||
public ApplicationExtensions set(ApplicationExtension ... extensions) {
|
|
||||||
this.extensions = Arrays.asList(extensions);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return extensions.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate() {
|
|
||||||
|
|
||||||
List<String> msgs = new ArrayList<String>();
|
|
||||||
|
|
||||||
Validator validator = ValidatorFactory.validator();
|
|
||||||
|
|
||||||
for (ValidationError error : validator.validate(this))
|
|
||||||
msgs.add(error.toString());
|
|
||||||
|
|
||||||
if (!msgs.isEmpty())
|
|
||||||
throw new IllegalStateException("invalid configuration: "+msgs);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//since we use @AnyElement, after deserialisation, we check there are no DOM elements
|
|
||||||
void afterUnmarshal(Unmarshaller u, Object parent) {
|
|
||||||
for (Object o : extensions)
|
|
||||||
if (o instanceof Element)
|
|
||||||
throw new RuntimeException("invalid extensions detected: "+Element.class.cast(o).getLocalName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,149 +0,0 @@
|
||||||
package org.gcube.smartgears.configuration.application;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
|
||||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
|
||||||
import org.gcube.smartgears.persistence.LocalPersistence;
|
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Fabio Simeoni
|
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
|
||||||
*/
|
|
||||||
public class BridgedApplicationConfiguration implements ApplicationConfiguration {
|
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(ApplicationConfiguration.class);
|
|
||||||
|
|
||||||
private final ApplicationConfiguration application;
|
|
||||||
|
|
||||||
|
|
||||||
public BridgedApplicationConfiguration(ContainerConfiguration container, ApplicationConfiguration config) {
|
|
||||||
|
|
||||||
this.application=config;
|
|
||||||
|
|
||||||
if (application.persistence()==null) {
|
|
||||||
|
|
||||||
String location = container.persistence().getLocation()+"/"+application.name();
|
|
||||||
File dir = new File(location);
|
|
||||||
if (!dir.exists())
|
|
||||||
dir.mkdirs();
|
|
||||||
|
|
||||||
application.persistence(new LocalPersistence(location));
|
|
||||||
|
|
||||||
log.trace("setting persistence location for {} @ {}",application.name(), dir.getAbsolutePath());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (application.proxable() && container.proxy()!=null)
|
|
||||||
application.proxyAddress(container.proxy());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationConfiguration inner() {
|
|
||||||
return application;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String context() {
|
|
||||||
return application.context();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration context(String context) {
|
|
||||||
return application.context(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String name() {
|
|
||||||
return application.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationConfiguration name(String name) {
|
|
||||||
return application.name(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String serviceClass() {
|
|
||||||
return application.serviceClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationConfiguration serviceClass(String group) {
|
|
||||||
return application.serviceClass(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String version() {
|
|
||||||
return application.version();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationConfiguration version(String version) {
|
|
||||||
return application.version(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String description() {
|
|
||||||
return application.description();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationConfiguration description(String description) {
|
|
||||||
return application.description(description);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PersistenceWriter persistence() {
|
|
||||||
return application.persistence();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationConfiguration persistence(PersistenceWriter manager) {
|
|
||||||
return application.persistence(manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void validate() {
|
|
||||||
|
|
||||||
application.validate();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Exclude> excludes() {
|
|
||||||
return application.excludes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Include> includes() {
|
|
||||||
return application.includes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void merge(ApplicationConfiguration config) {
|
|
||||||
application.merge(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean proxable() {
|
|
||||||
return application.proxable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration excludes(Exclude ... excludes) {
|
|
||||||
return application.excludes(excludes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration includes(Include... includes) {
|
|
||||||
return application.includes(includes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProxyAddress proxyAddress() {
|
|
||||||
return application.proxyAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration proxyAddress(ProxyAddress proxy) {
|
|
||||||
return proxyAddress(proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,207 +0,0 @@
|
||||||
package org.gcube.smartgears.configuration.application;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlElementRef;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
import org.gcube.common.validator.ValidationError;
|
|
||||||
import org.gcube.common.validator.Validator;
|
|
||||||
import org.gcube.common.validator.ValidatorFactory;
|
|
||||||
import org.gcube.common.validator.annotations.IsValid;
|
|
||||||
import org.gcube.common.validator.annotations.NotNull;
|
|
||||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
|
||||||
import org.gcube.smartgears.persistence.LocalPersistence;
|
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The configuration of a managed app.
|
|
||||||
* <p>
|
|
||||||
* Includes the list of its client services.
|
|
||||||
*
|
|
||||||
* @author Fabio Simeoni
|
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@XmlRootElement(name="application")
|
|
||||||
public class DefaultApplicationConfiguration implements ApplicationConfiguration {
|
|
||||||
|
|
||||||
String context;
|
|
||||||
|
|
||||||
@XmlAttribute(name = "proxable")
|
|
||||||
private boolean proxable = true;
|
|
||||||
|
|
||||||
@XmlElement(name="name" , required=true)
|
|
||||||
@NotNull
|
|
||||||
String name;
|
|
||||||
|
|
||||||
@XmlElement(name="group", required=true)
|
|
||||||
@NotNull
|
|
||||||
String group;
|
|
||||||
|
|
||||||
@XmlElement(name="version", required=true)
|
|
||||||
@NotNull
|
|
||||||
String version;
|
|
||||||
|
|
||||||
@XmlElement(name="description")
|
|
||||||
String description="";
|
|
||||||
|
|
||||||
@XmlElementRef
|
|
||||||
Set<Exclude> excludes= new LinkedHashSet<Exclude>();
|
|
||||||
|
|
||||||
@XmlElementRef
|
|
||||||
Set<Include> includes= new LinkedHashSet<Include>();
|
|
||||||
|
|
||||||
@XmlElementRef(type=LocalPersistence.class)
|
|
||||||
@NotNull @IsValid
|
|
||||||
private PersistenceWriter persistenceManager;
|
|
||||||
|
|
||||||
@IsValid
|
|
||||||
ProxyAddress proxyAddress;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Exclude> excludes() {
|
|
||||||
return excludes;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Include> includes() {
|
|
||||||
return includes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultApplicationConfiguration() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String name() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String context() {
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration context(String context) {
|
|
||||||
this.context=context;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration excludes(Exclude ... excludes) {
|
|
||||||
this.excludes=new HashSet<Exclude>(Arrays.asList(excludes));
|
|
||||||
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;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String serviceClass() {
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration serviceClass(String group) {
|
|
||||||
this.group=group;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String version() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration version(String version) {
|
|
||||||
this.version=version;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String description() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration description(String description) {
|
|
||||||
this.description=description;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean proxable() {
|
|
||||||
return proxable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxyAddress proxyAddress() {
|
|
||||||
return proxyAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ApplicationConfiguration proxyAddress(ProxyAddress proxyAddress) {
|
|
||||||
this.proxyAddress = proxyAddress;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PersistenceWriter persistence() {
|
|
||||||
return persistenceManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationConfiguration persistence(PersistenceWriter manager) {
|
|
||||||
this.persistenceManager=manager;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validate() {
|
|
||||||
|
|
||||||
List<String> msgs = new ArrayList<String>();
|
|
||||||
|
|
||||||
Validator validator = ValidatorFactory.validator();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void merge(ApplicationConfiguration config) {
|
|
||||||
|
|
||||||
if (config.persistence()!=null)
|
|
||||||
persistence(config.persistence());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,20 +3,14 @@ package org.gcube.smartgears.configuration.application;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import org.gcube.common.validator.annotations.NotEmpty;
|
||||||
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="exclude")
|
public class GCubeExclude {
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
|
||||||
public class Exclude {
|
|
||||||
|
|
||||||
@XmlAttribute(name="handlers")
|
@NotEmpty
|
||||||
private List<String> handlers = new ArrayList<String>();
|
private List<String> handlers = new ArrayList<String>();
|
||||||
|
|
||||||
@XmlValue
|
@NotEmpty
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
public List<String> getHandlers() {
|
public List<String> getHandlers() {
|
||||||
|
@ -27,14 +21,14 @@ public class Exclude {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Exclude() {}
|
protected GCubeExclude() {}
|
||||||
|
|
||||||
public Exclude(String path) {
|
public GCubeExclude(String path) {
|
||||||
super();
|
super();
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Exclude(List<String> handlers, String path) {
|
public GCubeExclude(List<String> handlers, String path) {
|
||||||
super();
|
super();
|
||||||
this.handlers = handlers;
|
this.handlers = handlers;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
@ -57,7 +51,7 @@ public class Exclude {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Exclude other = (Exclude) obj;
|
GCubeExclude other = (GCubeExclude) obj;
|
||||||
if (handlers == null) {
|
if (handlers == null) {
|
||||||
if (other.handlers != null)
|
if (other.handlers != null)
|
||||||
return false;
|
return false;
|
|
@ -3,20 +3,14 @@ package org.gcube.smartgears.configuration.application;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import org.gcube.common.validator.annotations.NotEmpty;
|
||||||
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")
|
public class GCubeInclude {
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
|
||||||
public class Include {
|
|
||||||
|
|
||||||
@XmlAttribute(name="handlers")
|
@NotEmpty
|
||||||
private List<String> handlers = new ArrayList<String>();
|
private List<String> handlers = new ArrayList<String>();
|
||||||
|
|
||||||
@XmlValue
|
@NotEmpty
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
public List<String> getHandlers() {
|
public List<String> getHandlers() {
|
||||||
|
@ -27,14 +21,14 @@ public class Include {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Include() {}
|
protected GCubeInclude() {}
|
||||||
|
|
||||||
public Include(String path) {
|
public GCubeInclude(String path) {
|
||||||
super();
|
super();
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Include(List<String> handlers, String path) {
|
public GCubeInclude(List<String> handlers, String path) {
|
||||||
super();
|
super();
|
||||||
this.handlers = handlers;
|
this.handlers = handlers;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
@ -57,7 +51,7 @@ public class Include {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Include other = (Include) obj;
|
GCubeInclude other = (GCubeInclude) obj;
|
||||||
if (handlers == null) {
|
if (handlers == null) {
|
||||||
if (other.handlers != null)
|
if (other.handlers != null)
|
||||||
return false;
|
return false;
|
|
@ -14,9 +14,9 @@ import org.gcube.common.validator.annotations.NotEmpty;
|
||||||
import org.gcube.common.validator.annotations.NotNull;
|
import org.gcube.common.validator.annotations.NotNull;
|
||||||
import org.gcube.smartgears.configuration.AuthorizationProviderConfiguration;
|
import org.gcube.smartgears.configuration.AuthorizationProviderConfiguration;
|
||||||
import org.gcube.smartgears.configuration.Mode;
|
import org.gcube.smartgears.configuration.Mode;
|
||||||
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
import org.gcube.smartgears.configuration.ProxyAddress;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configuration of the container.
|
* The configuration of the container.
|
||||||
|
@ -46,7 +46,7 @@ public class ContainerConfiguration {
|
||||||
|
|
||||||
|
|
||||||
@NotNull @IsValid
|
@NotNull @IsValid
|
||||||
private PersistenceWriter persistenceManager;
|
private PersistenceConfiguration persistenceConfiguration;
|
||||||
|
|
||||||
@NotNull @IsValid
|
@NotNull @IsValid
|
||||||
private AuthorizationProviderConfiguration authorizationConfiguration;
|
private AuthorizationProviderConfiguration authorizationConfiguration;
|
||||||
|
@ -72,8 +72,8 @@ public class ContainerConfiguration {
|
||||||
this.accountingFallbackLocation = accountingFallbackLocation;
|
this.accountingFallbackLocation = accountingFallbackLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPersistenceManager(PersistenceWriter persistenceManager) {
|
protected void setPersistenceConfiguration(PersistenceConfiguration persistenceConfiguration) {
|
||||||
this.persistenceManager = persistenceManager;
|
this.persistenceConfiguration = persistenceConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAuthorizationProviderConfiguration(
|
protected void setAuthorizationProviderConfiguration(
|
||||||
|
@ -195,8 +195,8 @@ public class ContainerConfiguration {
|
||||||
* Returns the persistence manager of the container.
|
* Returns the persistence manager of the container.
|
||||||
* @return the manager
|
* @return the manager
|
||||||
*/
|
*/
|
||||||
public PersistenceWriter persistence() {
|
public PersistenceConfiguration persistenceConfiguration() {
|
||||||
return persistenceManager;
|
return this.persistenceConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,7 +211,7 @@ public class ContainerConfiguration {
|
||||||
* Returns the authorization configuration.
|
* Returns the authorization configuration.
|
||||||
* @return AuthorizationProviderConfiguration the configuration
|
* @return AuthorizationProviderConfiguration the configuration
|
||||||
*/
|
*/
|
||||||
public AuthorizationProviderConfiguration getauthorizationConfiguration() {
|
public AuthorizationProviderConfiguration authorizationConfiguration() {
|
||||||
return authorizationConfiguration;
|
return authorizationConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ public class ContainerConfiguration {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ContainerConfiguration [baseConfiguration=" + baseConfiguration + ", properties=" + properties
|
return "ContainerConfiguration [baseConfiguration=" + baseConfiguration + ", properties=" + properties
|
||||||
+ ", site=" + site + ", proxy=" + proxy + ", accountingFallbackLocation=" + accountingFallbackLocation
|
+ ", site=" + site + ", proxy=" + proxy + ", accountingFallbackLocation=" + accountingFallbackLocation
|
||||||
+ ", persistenceManager=" + persistenceManager.getClass().getSimpleName()
|
+ ", persistence=" + persistenceConfiguration.getImplementationClass().getSimpleName()
|
||||||
+ ", authorizationProvider=" + authorizationConfiguration + "]";
|
+ ", authorizationProvider=" + authorizationConfiguration + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,15 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.gcube.common.security.credentials.Credentials;
|
import org.gcube.common.security.credentials.Credentials;
|
||||||
import org.gcube.smartgears.configuration.AuthorizationProviderConfiguration;
|
import org.gcube.smartgears.configuration.AuthorizationProviderConfiguration;
|
||||||
|
import org.gcube.smartgears.configuration.ComponentConfiguration;
|
||||||
|
import org.gcube.smartgears.configuration.ConfiguredWith;
|
||||||
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
import org.gcube.smartgears.configuration.ProxyAddress;
|
||||||
import org.gcube.smartgears.handlers.container.ContainerHandler;
|
import org.gcube.smartgears.handlers.container.ContainerHandler;
|
||||||
import org.gcube.smartgears.handlers.container.lifecycle.AccountingManager;
|
import org.gcube.smartgears.handlers.container.lifecycle.AccountingManager;
|
||||||
import org.gcube.smartgears.handlers.container.lifecycle.ContainerProfileManager;
|
import org.gcube.smartgears.handlers.container.lifecycle.ContainerProfileManager;
|
||||||
import org.gcube.smartgears.persistence.LocalPersistence;
|
import org.gcube.smartgears.persistence.LocalWriter;
|
||||||
|
import org.gcube.smartgears.persistence.LocalWriterConfiguration;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||||
import org.gcube.smartgears.security.AuthorizationProviderFactory;
|
import org.gcube.smartgears.security.AuthorizationProviderFactory;
|
||||||
import org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory;
|
import org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory;
|
||||||
|
@ -30,120 +34,138 @@ import org.ini4j.Profile.Section;
|
||||||
*/
|
*/
|
||||||
public class ContainerConfigurationBinder {
|
public class ContainerConfigurationBinder {
|
||||||
|
|
||||||
|
|
||||||
public ContainerConfiguration load(InputStream stream) {
|
public ContainerConfiguration load(InputStream stream) {
|
||||||
try {
|
try {
|
||||||
Ini configurator = new Ini(stream);
|
Ini configurator = new Ini(stream);
|
||||||
ContainerConfiguration conf = new ContainerConfiguration();
|
ContainerConfiguration conf = new ContainerConfiguration();
|
||||||
|
|
||||||
Section nodeSection = configurator.get("node");
|
Section nodeSection = configurator.get("node");
|
||||||
if (nodeSection != null ) {
|
if (nodeSection != null) {
|
||||||
BaseConfiguration nodeConf = new BaseConfiguration();
|
BaseConfiguration nodeConf = new BaseConfiguration();
|
||||||
nodeSection.to(nodeConf);
|
nodeSection.to(nodeConf);
|
||||||
conf.setBaseConfiguration(nodeConf);
|
conf.setBaseConfiguration(nodeConf);
|
||||||
}
|
}
|
||||||
|
|
||||||
Section propertiesSection = configurator.get("properties");
|
Section propertiesSection = configurator.get("properties");
|
||||||
if (propertiesSection!=null)
|
if (propertiesSection != null)
|
||||||
conf.setProperties(propertiesSection.entrySet().stream()
|
conf.setProperties(propertiesSection.entrySet().stream()
|
||||||
.collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
|
.collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
|
||||||
|
|
||||||
Section siteSection = configurator.get("site");
|
Section siteSection = configurator.get("site");
|
||||||
if (siteSection != null) {
|
if (siteSection != null) {
|
||||||
Site siteConf = new Site();
|
Site siteConf = new Site();
|
||||||
siteSection.to(siteConf);
|
siteSection.to(siteConf);
|
||||||
conf.setSite(siteConf);
|
conf.setSite(siteConf);
|
||||||
}
|
}
|
||||||
|
|
||||||
initAuthorizationPart(configurator, conf);
|
initAuthorizationPart(configurator, conf);
|
||||||
|
|
||||||
initPersistencePart(configurator, conf);
|
initPersistencePart(configurator, conf);
|
||||||
|
|
||||||
initProxyPart(configurator, conf);
|
initProxyPart(configurator, conf);
|
||||||
|
|
||||||
|
// TODO: find a solution for this shit
|
||||||
//TODO: find a solution for this shit
|
String location = Utils.home() + "/state";
|
||||||
String location = Utils.home()+"/state";
|
|
||||||
File dir = new File(location);
|
File dir = new File(location);
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
conf.setAccountingFallbackLocation(location);
|
conf.setAccountingFallbackLocation(location);
|
||||||
// END Shit
|
// END Shit
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initProxyPart(Ini configurator, ContainerConfiguration conf) throws Exception{
|
private void initProxyPart(Ini configurator, ContainerConfiguration conf) throws Exception {
|
||||||
Section proxySection = configurator.get("proxy");
|
Section proxySection = configurator.get("proxy");
|
||||||
if (proxySection != null) {
|
if (proxySection != null) {
|
||||||
ProxyAddress proxyConf = new ProxyAddress();
|
ProxyAddress proxyConf = new ProxyAddress();
|
||||||
proxySection.to(proxyConf);
|
proxySection.to(proxyConf);
|
||||||
conf.setProxy(proxyConf);
|
conf.setProxy(proxyConf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPersistencePart(Ini configurator, ContainerConfiguration conf) throws Exception{
|
@SuppressWarnings("unchecked")
|
||||||
|
private void initPersistencePart(Ini configurator, ContainerConfiguration conf) throws Exception {
|
||||||
Section persistenceSection = configurator.get("persistence");
|
Section persistenceSection = configurator.get("persistence");
|
||||||
if (persistenceSection != null) {
|
if (persistenceSection != null) {
|
||||||
String type = persistenceSection.get("class");
|
String type = persistenceSection.get("class");
|
||||||
if (type ==null)
|
if (type == null)
|
||||||
throw new Exception("ini file error: type not found in \"persistence\" section");
|
throw new Exception("ini file error: type not found in \"persistence\" section");
|
||||||
PersistenceWriter persistenceWriter;
|
/*
|
||||||
|
* PersistenceWriter persistenceWriter; try { Object persistenceImpl =
|
||||||
|
* Class.forName(type).getDeclaredConstructor().newInstance(); persistenceWriter
|
||||||
|
* = PersistenceWriter.class.cast(persistenceImpl); }catch (Exception e) { throw
|
||||||
|
* new
|
||||||
|
* Exception("ini file error: invalid persistence type in \"persistence\" section"
|
||||||
|
* , e); }
|
||||||
|
*/
|
||||||
|
// persistenceSection.to(persistenceWriter);
|
||||||
|
|
||||||
|
Class<? extends PersistenceWriter> persistenceClass = null;
|
||||||
try {
|
try {
|
||||||
Object persistenceImpl = Class.forName(type).newInstance();
|
persistenceClass = (Class<? extends PersistenceWriter>) Class.forName(type);
|
||||||
persistenceWriter = PersistenceWriter.class.cast(persistenceImpl);
|
} catch (Exception e) {
|
||||||
}catch (Exception e) {
|
|
||||||
throw new Exception("ini file error: invalid persistence type in \"persistence\" section", e);
|
throw new Exception("ini file error: invalid persistence type in \"persistence\" section", e);
|
||||||
}
|
}
|
||||||
persistenceSection.to(persistenceWriter);
|
if (!persistenceClass.isAnnotationPresent(ConfiguredWith.class))
|
||||||
conf.setPersistenceManager(persistenceWriter);
|
throw new Exception(
|
||||||
|
"ini file error: invalid class type in \"persistence\" section,ConfiguredWith annotation not present");
|
||||||
|
Class<? extends ComponentConfiguration> writerConfClass = persistenceClass
|
||||||
|
.getAnnotation(ConfiguredWith.class).value();
|
||||||
|
ComponentConfiguration writerConfiguration = writerConfClass.getDeclaredConstructor().newInstance();
|
||||||
|
persistenceSection.to(writerConfiguration, ".");
|
||||||
|
conf.setPersistenceConfiguration(
|
||||||
|
new PersistenceConfiguration((Class<PersistenceWriter>) persistenceClass, writerConfiguration));
|
||||||
} else {
|
} else {
|
||||||
String location = Utils.home()+"/state";
|
String location = Utils.home() + "/state";
|
||||||
File dir = new File(location);
|
File dir = new File(location);
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
conf.setPersistenceManager(new LocalPersistence(location));
|
|
||||||
|
conf.setPersistenceConfiguration(
|
||||||
|
new PersistenceConfiguration(LocalWriter.class, new LocalWriterConfiguration(location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAuthorizationPart(Ini configurator, ContainerConfiguration conf) throws Exception{
|
private void initAuthorizationPart(Ini configurator, ContainerConfiguration conf) throws Exception {
|
||||||
Section authorizationSection = configurator.get("authorization");
|
Section authorizationSection = configurator.get("authorization");
|
||||||
if (authorizationSection != null) {
|
if (authorizationSection != null) {
|
||||||
|
|
||||||
String provider = authorizationSection.get("factory");
|
String provider = authorizationSection.get("factory");
|
||||||
AuthorizationProviderFactory<?> authProviderFactory;
|
AuthorizationProviderFactory<?> authProviderFactory;
|
||||||
if (provider!=null) {
|
if (provider != null) {
|
||||||
try {
|
try {
|
||||||
Object authProviderImpl = Class.forName(provider).newInstance();
|
Object authProviderImpl = Class.forName(provider).getDeclaredConstructor().newInstance();
|
||||||
authProviderFactory = AuthorizationProviderFactory.class.cast(authProviderImpl);
|
authProviderFactory = AuthorizationProviderFactory.class.cast(authProviderImpl);
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("ini file error: invalid provider type in \"authorization\" section", e);
|
throw new Exception("ini file error: invalid provider type in \"authorization\" section", e);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
authProviderFactory = new DefaultAuthorizationProviderFactory();
|
authProviderFactory = new DefaultAuthorizationProviderFactory();
|
||||||
|
|
||||||
authorizationSection.to(authProviderFactory, "factory.");
|
authorizationSection.to(authProviderFactory, "factory.");
|
||||||
|
|
||||||
|
|
||||||
String type = authorizationSection.get("credentials.class");
|
String type = authorizationSection.get("credentials.class");
|
||||||
if (type ==null)
|
if (type == null)
|
||||||
throw new Exception("ini file error: credentials type not found in \"authorization\" section");
|
throw new Exception("ini file error: credentials type not found in \"authorization\" section");
|
||||||
Credentials credentials;
|
Credentials credentials;
|
||||||
try {
|
try {
|
||||||
Object credentialsImpl = Class.forName(type).newInstance();
|
Object credentialsImpl = Class.forName(type).getDeclaredConstructor().newInstance();
|
||||||
credentials = Credentials.class.cast(credentialsImpl);
|
credentials = Credentials.class.cast(credentialsImpl);
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("ini file error: invalid credentials type in \"authorization\" section", e);
|
throw new Exception("ini file error: invalid credentials type in \"authorization\" section", e);
|
||||||
}
|
}
|
||||||
authorizationSection.to(credentials, "credentials.");
|
authorizationSection.to(credentials, "credentials.");
|
||||||
|
|
||||||
conf.setAuthorizationProviderConfiguration(new AuthorizationProviderConfiguration(authProviderFactory, credentials));
|
conf.setAuthorizationProviderConfiguration(
|
||||||
|
new AuthorizationProviderConfiguration(authProviderFactory, credentials));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the handlers of the container from their XML serialisation.
|
* Returns the handlers of the container from their XML serialisation.
|
||||||
*
|
*
|
||||||
|
@ -154,24 +176,22 @@ public class ContainerConfigurationBinder {
|
||||||
public List<ContainerHandler> bindHandlers(ClassLoader classloader) {
|
public List<ContainerHandler> bindHandlers(ClassLoader classloader) {
|
||||||
|
|
||||||
LinkedList<ContainerHandler> handlers = new LinkedList<ContainerHandler>();
|
LinkedList<ContainerHandler> handlers = new LinkedList<ContainerHandler>();
|
||||||
|
|
||||||
//ADDING BASE Handlers (order is important)
|
// ADDING BASE Handlers (order is important)
|
||||||
handlers.add(new AccountingManager());
|
handlers.add(new AccountingManager());
|
||||||
handlers.add(new ContainerProfileManager());
|
handlers.add(new ContainerProfileManager());
|
||||||
|
|
||||||
handlers.addAll(scanForContainerHadlers(classloader));
|
handlers.addAll(scanForContainerHadlers(classloader));
|
||||||
|
|
||||||
return handlers;
|
return handlers;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<? extends ContainerHandler> scanForContainerHadlers(ClassLoader classloader) throws RuntimeException {
|
private List<? extends ContainerHandler> scanForContainerHadlers(ClassLoader classloader) throws RuntimeException {
|
||||||
|
|
||||||
//TODO: scan for Container Handler
|
// TODO: scan for Container Handler
|
||||||
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,14 @@ package org.gcube.smartgears.configuration.library;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
import org.gcube.common.validator.ValidationError;
|
import org.gcube.common.validator.ValidationError;
|
||||||
import org.gcube.common.validator.Validator;
|
import org.gcube.common.validator.Validator;
|
||||||
import org.gcube.common.validator.ValidatorFactory;
|
import org.gcube.common.validator.ValidatorFactory;
|
||||||
import org.gcube.common.validator.annotations.NotEmpty;
|
import org.gcube.common.validator.annotations.NotEmpty;
|
||||||
|
|
||||||
@XmlRootElement(name="smartgears")
|
|
||||||
public class SmartGearsConfiguration {
|
public class SmartGearsConfiguration {
|
||||||
|
|
||||||
@XmlAttribute @NotEmpty
|
@NotEmpty
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
public SmartGearsConfiguration(){
|
public SmartGearsConfiguration(){
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
package org.gcube.smartgears.configuration.library;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
|
||||||
import org.gcube.smartgears.utils.Utils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds {@link ContainerConfiguration}s to and from XML serialisations.
|
|
||||||
*
|
|
||||||
* @author Fabio Simeoni
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SmartGearsConfigurationBinder {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a {@link ContainerConfiguration} from its XML serialisation.
|
|
||||||
*
|
|
||||||
* @param stream the serialisation
|
|
||||||
* @return the configuration
|
|
||||||
* @throws RuntimeException if the serialisation is invalid
|
|
||||||
*/
|
|
||||||
public SmartGearsConfiguration bind(InputStream stream) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
JAXBContext ctx = JAXBContext.newInstance(SmartGearsConfiguration.class);
|
|
||||||
|
|
||||||
SmartGearsConfiguration config = (SmartGearsConfiguration) ctx.createUnmarshaller().unmarshal(stream);
|
|
||||||
|
|
||||||
return config;
|
|
||||||
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
|
|
||||||
throw new RuntimeException("invalid library configuration", e);
|
|
||||||
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
|
|
||||||
Utils.closeSafely(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +1,24 @@
|
||||||
package org.gcube.smartgears.context.application;
|
package org.gcube.smartgears.context.application;
|
||||||
|
|
||||||
|
import static org.gcube.smartgears.Constants.profile_file_path;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import org.gcube.common.events.Hub;
|
import org.gcube.common.events.Hub;
|
||||||
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
import org.gcube.smartgears.context.Properties;
|
import org.gcube.smartgears.context.Properties;
|
||||||
import org.gcube.smartgears.context.container.ContainerContext;
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default {@link ApplicationContext} implementation.
|
* Default {@link ApplicationContext} implementation.
|
||||||
|
@ -18,12 +28,15 @@ import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
*/
|
*/
|
||||||
public class DefaultApplicationContext implements ApplicationContext {
|
public class DefaultApplicationContext implements ApplicationContext {
|
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(DefaultApplicationContext.class);
|
||||||
|
|
||||||
private final ContainerContext container;
|
private final ContainerContext container;
|
||||||
private final ServletContext sctx;
|
private final ServletContext sctx;
|
||||||
private final ApplicationConfiguration configuration;
|
private final ApplicationConfiguration configuration;
|
||||||
private final ApplicationLifecycle lifecycle;
|
private final ApplicationLifecycle lifecycle;
|
||||||
private final Properties properties;
|
private final Properties properties;
|
||||||
private final Hub hub;
|
private final Hub hub;
|
||||||
|
private final PersistenceWriter persistenceWriter;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +48,30 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||||
* @param lifecycle the lifecycle
|
* @param lifecycle the lifecycle
|
||||||
* @param properties the properties
|
* @param properties the properties
|
||||||
*/
|
*/
|
||||||
public DefaultApplicationContext(String id,ContainerContext container,ServletContext sctx,ApplicationConfiguration configuration, Hub hub, ApplicationLifecycle lifecycle, Properties properties) {
|
public DefaultApplicationContext(ContainerContext container,ServletContext sctx,ApplicationConfiguration configuration, Hub hub, ApplicationLifecycle lifecycle, Properties properties) {
|
||||||
|
|
||||||
|
PersistenceConfiguration persistenceWriterConf = configuration.persistenceConfiguration();
|
||||||
|
|
||||||
|
try {
|
||||||
|
persistenceWriter = persistenceWriterConf.getImplementationClass().getDeclaredConstructor().newInstance();
|
||||||
|
persistenceWriter.configure(persistenceWriterConf.getWriterConfiguration());
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = persistenceWriter.file(profile_file_path);
|
||||||
|
String id = null;
|
||||||
|
if (file.exists()) {
|
||||||
|
log.info("loading persisted state for application {}", sctx.getContextPath());
|
||||||
|
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
|
||||||
|
id = (String) ois.readObject();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("error loading persisted state, creating new uuid", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (id == null)
|
||||||
|
id = UUID.randomUUID().toString();
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.container=container;
|
this.container=container;
|
||||||
this.sctx = sctx;
|
this.sctx = sctx;
|
||||||
|
@ -50,9 +86,21 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||||
* @param context the other instance
|
* @param context the other instance
|
||||||
*/
|
*/
|
||||||
public DefaultApplicationContext(ApplicationContext context) {
|
public DefaultApplicationContext(ApplicationContext context) {
|
||||||
this(context.id(), context.container(),context.application(),context.configuration(),context.events(), context.lifecycle(), new Properties(context.properties()));
|
this(context.id(), context.persistence(), context.container(),context.application(),context.configuration(),context.events(), context.lifecycle(), new Properties(context.properties()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DefaultApplicationContext(String id, PersistenceWriter writer, ContainerContext container,ServletContext sctx,ApplicationConfiguration configuration, Hub hub, ApplicationLifecycle lifecycle, Properties properties) {
|
||||||
|
this.id = id;
|
||||||
|
this.container=container;
|
||||||
|
this.sctx = sctx;
|
||||||
|
this.configuration=configuration;
|
||||||
|
this.hub=hub;
|
||||||
|
this.lifecycle = lifecycle;
|
||||||
|
this.properties=properties;
|
||||||
|
this.persistenceWriter = writer;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServletContext application() {
|
public ServletContext application() {
|
||||||
return sctx;
|
return sctx;
|
||||||
|
@ -85,10 +133,8 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PersistenceWriter persistence() {
|
public PersistenceWriter persistence() {
|
||||||
return configuration.persistence();
|
return persistenceWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Properties properties() {
|
public Properties properties() {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public interface ContainerContext {
|
||||||
* Returns the persistence manager of the container.
|
* Returns the persistence manager of the container.
|
||||||
* @return the manager
|
* @return the manager
|
||||||
*/
|
*/
|
||||||
PersistenceWriter persistence();
|
PersistenceWriter persistenceWriter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the properties of the container.
|
* Returns the properties of the container.
|
||||||
|
@ -51,5 +51,6 @@ public interface ContainerContext {
|
||||||
|
|
||||||
|
|
||||||
AuthorizationProvider authorizationProvider();
|
AuthorizationProvider authorizationProvider();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
package org.gcube.smartgears.context.container;
|
package org.gcube.smartgears.context.container;
|
||||||
|
|
||||||
import static org.gcube.smartgears.Constants.container_profile_property;
|
import static org.gcube.smartgears.Constants.container_profile_file_path;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.common.events.Hub;
|
import org.gcube.common.events.Hub;
|
||||||
import org.gcube.common.resources.gcore.HostingNode;
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||||
import org.gcube.smartgears.context.Properties;
|
import org.gcube.smartgears.context.Properties;
|
||||||
import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
|
import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default {@link ContainerContext} implementation.
|
* Default {@link ContainerContext} implementation.
|
||||||
|
@ -18,12 +25,15 @@ import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
*/
|
*/
|
||||||
public class DefaultContainerContext implements ContainerContext {
|
public class DefaultContainerContext implements ContainerContext {
|
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(DefaultContainerContext.class);
|
||||||
|
|
||||||
private final ContainerConfiguration configuration;
|
private final ContainerConfiguration configuration;
|
||||||
private final ContainerLifecycle lifecycle;
|
private final ContainerLifecycle lifecycle;
|
||||||
private final Properties properties;
|
private final Properties properties;
|
||||||
private final Hub hub;
|
private final Hub hub;
|
||||||
private final AuthorizationProvider authorizationProvider;
|
private final AuthorizationProvider authorizationProvider;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
private final PersistenceWriter persistenceWriter;
|
||||||
/**
|
/**
|
||||||
* Creates an instance with mandatory parameters.
|
* Creates an instance with mandatory parameters.
|
||||||
* @param configuration the configuration
|
* @param configuration the configuration
|
||||||
|
@ -31,19 +41,49 @@ public class DefaultContainerContext implements ContainerContext {
|
||||||
* @param lifecycle the lifecycle
|
* @param lifecycle the lifecycle
|
||||||
* @param properties the properties
|
* @param properties the properties
|
||||||
*/
|
*/
|
||||||
public DefaultContainerContext(String id,ContainerConfiguration configuration, Hub hub, ContainerLifecycle lifecycle, AuthorizationProvider authProvider,
|
public DefaultContainerContext(ContainerConfiguration configuration, Hub hub, ContainerLifecycle lifecycle, AuthorizationProvider authProvider,
|
||||||
Properties properties) {
|
Properties properties) {
|
||||||
this.id = id;
|
|
||||||
this.configuration=configuration;
|
this.configuration=configuration;
|
||||||
this.hub=hub;
|
this.hub=hub;
|
||||||
this.lifecycle = lifecycle;
|
this.lifecycle = lifecycle;
|
||||||
this.properties=properties;
|
this.properties=properties;
|
||||||
this.authorizationProvider = authProvider;
|
this.authorizationProvider = authProvider;
|
||||||
}
|
|
||||||
|
PersistenceConfiguration persistenceWriterConf = configuration.persistenceConfiguration();
|
||||||
|
|
||||||
|
try {
|
||||||
|
persistenceWriter = persistenceWriterConf.getImplementationClass().getDeclaredConstructor().newInstance();
|
||||||
|
persistenceWriter.configure(persistenceWriterConf.getWriterConfiguration());
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = persistenceWriter.file(container_profile_file_path);
|
||||||
|
|
||||||
|
String id = null;
|
||||||
|
if (file.exists()) {
|
||||||
|
log.info("loading persisted state for container");
|
||||||
|
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
|
||||||
|
id = (String) ois.readObject();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("error loading persisted state, creating new uuid", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (id == null) {
|
||||||
|
id = UUID.randomUUID().toString();
|
||||||
|
log.info("container id created is {}", id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public HostingNode profile() {
|
public HostingNode profile() {
|
||||||
return properties().lookup(container_profile_property).value(HostingNode.class);
|
return properties().lookup(container_profile_property).value(HostingNode.class);
|
||||||
};
|
};*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContainerConfiguration configuration() {
|
public ContainerConfiguration configuration() {
|
||||||
|
@ -61,8 +101,8 @@ public class DefaultContainerContext implements ContainerContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PersistenceWriter persistence() {
|
public PersistenceWriter persistenceWriter() {
|
||||||
return configuration.persistence();
|
return persistenceWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,7 +9,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.gcube.smartgears.Constants;
|
import org.gcube.smartgears.Constants;
|
||||||
import org.gcube.smartgears.configuration.application.Exclude;
|
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A resource-specifc API handled by an {@link HttpController}.
|
* A resource-specifc API handled by an {@link HttpController}.
|
||||||
|
@ -53,8 +53,8 @@ public abstract class ApiResource extends HttpExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Exclude> excludes() {
|
public Set<GCubeExclude> excludes() {
|
||||||
return Collections.singleton(new Exclude(Constants.root_mapping+mapping()));
|
return Collections.singleton(new GCubeExclude(Constants.root_mapping+mapping()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
import javax.servlet.Servlet;
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.application.Exclude;
|
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,5 +41,5 @@ public interface ApplicationExtension extends Servlet {
|
||||||
* Returns the set of request paths that should be excluded from request management.
|
* Returns the set of request paths that should be excluded from request management.
|
||||||
* @return the set of request paths that should be excluded from request management
|
* @return the set of request paths that should be excluded from request management
|
||||||
*/
|
*/
|
||||||
Set<Exclude> excludes();
|
Set<GCubeExclude> excludes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package org.gcube.smartgears.extensions;
|
package org.gcube.smartgears.extensions;
|
||||||
|
|
||||||
import static org.gcube.smartgears.Constants.*;
|
import static org.gcube.smartgears.Constants.accept;
|
||||||
import static org.gcube.smartgears.handlers.application.request.RequestError.*;
|
import static org.gcube.smartgears.Constants.allow;
|
||||||
import static org.gcube.smartgears.utils.Utils.*;
|
import static org.gcube.smartgears.Constants.content_type;
|
||||||
|
import static org.gcube.smartgears.handlers.application.request.RequestError.incoming_contenttype_unsupported_error;
|
||||||
|
import static org.gcube.smartgears.handlers.application.request.RequestError.method_unsupported_error;
|
||||||
|
import static org.gcube.smartgears.handlers.application.request.RequestError.outgoing_contenttype_unsupported_error;
|
||||||
|
import static org.gcube.smartgears.handlers.application.request.RequestError.resource_notfound_error;
|
||||||
|
import static org.gcube.smartgears.utils.Utils.notNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -17,7 +22,7 @@ import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.application.Exclude;
|
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,9 +74,18 @@ public class HttpController extends HttpExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Exclude> excludes() {
|
public void stop(){
|
||||||
|
super.stop();
|
||||||
|
for (ApiResource resource : resources.values())
|
||||||
|
resource.stop();
|
||||||
|
|
||||||
Set<Exclude> resourceExcludes = new LinkedHashSet<Exclude>();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<GCubeExclude> excludes() {
|
||||||
|
|
||||||
|
Set<GCubeExclude> resourceExcludes = new LinkedHashSet<GCubeExclude>();
|
||||||
|
|
||||||
for (ApiResource resource : resources.values())
|
for (ApiResource resource : resources.values())
|
||||||
resourceExcludes.addAll(resource.excludes());
|
resourceExcludes.addAll(resource.excludes());
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
package org.gcube.smartgears.extensions;
|
package org.gcube.smartgears.extensions;
|
||||||
|
|
||||||
import static org.gcube.common.events.impl.Utils.*;
|
import static org.gcube.common.events.impl.Utils.valid;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
import org.gcube.common.validator.annotations.NotEmpty;
|
import org.gcube.common.validator.annotations.NotEmpty;
|
||||||
import org.gcube.smartgears.configuration.application.Exclude;
|
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
import javax.ws.rs.HttpMethod;
|
|
||||||
/**
|
/**
|
||||||
* An {@link ApplicationExtension} that implements the {@link HttpServlet} interface
|
* An {@link ApplicationExtension} that implements the {@link HttpServlet} interface
|
||||||
*
|
*
|
||||||
|
@ -48,10 +47,10 @@ public abstract class HttpExtension extends HttpServlet implements ApplicationEx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlAttribute @NotEmpty
|
@NotEmpty
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@XmlAttribute @NotEmpty
|
@NotEmpty
|
||||||
private String mapping;
|
private String mapping;
|
||||||
|
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
@ -80,8 +79,8 @@ public abstract class HttpExtension extends HttpServlet implements ApplicationEx
|
||||||
public void stop() {}
|
public void stop() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Exclude> excludes() {
|
public Set<GCubeExclude> excludes() {
|
||||||
return new HashSet<Exclude>(); //all managed by default
|
return new HashSet<GCubeExclude>(); //all managed by default
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ApplicationContext context() {
|
protected ApplicationContext context() {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.Resources;
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
import org.gcube.smartgears.configuration.application.BridgedApplicationConfiguration;
|
|
||||||
import org.gcube.smartgears.extensions.ApiResource;
|
import org.gcube.smartgears.extensions.ApiResource;
|
||||||
import org.gcube.smartgears.extensions.ApiSignature;
|
import org.gcube.smartgears.extensions.ApiSignature;
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ public class ConfigurationResource extends ApiResource {
|
||||||
@Override
|
@Override
|
||||||
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
|
||||||
ApplicationConfiguration config = BridgedApplicationConfiguration.class.cast(context().configuration()).inner();
|
ApplicationConfiguration config = context().configuration();
|
||||||
Resources.marshal(config,resp.getWriter());
|
Resources.marshal(config,resp.getWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import static org.gcube.smartgears.Constants.application_xhtml;
|
||||||
import static org.gcube.smartgears.Constants.frontpage_file_path;
|
import static org.gcube.smartgears.Constants.frontpage_file_path;
|
||||||
import static org.gcube.smartgears.extensions.HttpExtension.Method.GET;
|
import static org.gcube.smartgears.extensions.HttpExtension.Method.GET;
|
||||||
import static org.gcube.smartgears.handlers.application.request.RequestError.application_error;
|
import static org.gcube.smartgears.handlers.application.request.RequestError.application_error;
|
||||||
import static org.gcube.smartgears.provider.ProviderFactory.provider;
|
|
||||||
import static org.gcube.smartgears.utils.Utils.closeSafely;
|
import static org.gcube.smartgears.utils.Utils.closeSafely;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -93,7 +92,7 @@ public class FrontPageResource extends ApiResource {
|
||||||
|
|
||||||
values.put("status", context().lifecycle().state().toString());
|
values.put("status", context().lifecycle().state().toString());
|
||||||
|
|
||||||
values.put("smartgears-version", provider().smartgearsConfiguration().version());
|
//values.put("smartgears-version", provider().smartgearsConfiguration().version());
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@ import java.io.IOException;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
import javax.xml.bind.annotation.XmlValue;
|
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.Resources;
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
import org.gcube.smartgears.extensions.ApiResource;
|
import org.gcube.smartgears.extensions.ApiResource;
|
||||||
|
@ -86,10 +84,8 @@ public class LifecycleResource extends ApiResource {
|
||||||
|
|
||||||
// helper classes
|
// helper classes
|
||||||
|
|
||||||
@XmlRootElement(name="state")
|
|
||||||
public static class State {
|
public static class State {
|
||||||
|
|
||||||
@XmlValue
|
|
||||||
public String value;
|
public String value;
|
||||||
|
|
||||||
State() {
|
State() {
|
||||||
|
|
|
@ -2,8 +2,6 @@ package org.gcube.smartgears.extensions.resource;
|
||||||
|
|
||||||
import static org.gcube.smartgears.Constants.remote_management;
|
import static org.gcube.smartgears.Constants.remote_management;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
import org.gcube.smartgears.Constants;
|
import org.gcube.smartgears.Constants;
|
||||||
import org.gcube.smartgears.extensions.ApiResource;
|
import org.gcube.smartgears.extensions.ApiResource;
|
||||||
import org.gcube.smartgears.extensions.HttpController;
|
import org.gcube.smartgears.extensions.HttpController;
|
||||||
|
@ -14,7 +12,6 @@ import org.gcube.smartgears.extensions.HttpController;
|
||||||
* @author Fabio Simeoni
|
* @author Fabio Simeoni
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = remote_management)
|
|
||||||
public class RemoteResource extends HttpController {
|
public class RemoteResource extends HttpController {
|
||||||
|
|
||||||
private static final String default_mapping = Constants.root_mapping+"/*";
|
private static final String default_mapping = Constants.root_mapping+"/*";
|
||||||
|
|
|
@ -13,9 +13,9 @@ import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||||
import org.gcube.common.security.ContextBean;
|
import org.gcube.common.security.ContextBean;
|
||||||
import org.gcube.common.security.ContextBean.Type;
|
import org.gcube.common.security.ContextBean.Type;
|
||||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.common.security.secrets.AccessTokenSecret;
|
|
||||||
import org.gcube.common.security.secrets.GCubeSecret;
|
import org.gcube.common.security.secrets.GCubeSecret;
|
||||||
import org.gcube.common.security.secrets.Secret;
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.common.security.secrets.UmaTokenSecret;
|
||||||
import org.gcube.smartgears.Constants;
|
import org.gcube.smartgears.Constants;
|
||||||
import org.gcube.smartgears.configuration.Mode;
|
import org.gcube.smartgears.configuration.Mode;
|
||||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||||
|
@ -132,18 +132,18 @@ public class RequestValidator extends RequestHandler {
|
||||||
|
|
||||||
log.info("d4s-user set to {} ", call.request().getHeader("d4s-user"));
|
log.info("d4s-user set to {} ", call.request().getHeader("d4s-user"));
|
||||||
|
|
||||||
String accessToken = null;
|
String umaToken = null;
|
||||||
if (authHeader!=null && !authHeader.isEmpty())
|
if (authHeader!=null && !authHeader.isEmpty())
|
||||||
if (authHeader.startsWith(BEARER_AUTH_PREFIX))
|
if (authHeader.startsWith(BEARER_AUTH_PREFIX))
|
||||||
accessToken = authHeader.substring(BEARER_AUTH_PREFIX.length()).trim();
|
umaToken = authHeader.substring(BEARER_AUTH_PREFIX.length()).trim();
|
||||||
|
|
||||||
Secret secret = null;
|
Secret secret = null;
|
||||||
if (accessToken!=null) {
|
if (umaToken!=null) {
|
||||||
secret = new AccessTokenSecret(accessToken);
|
secret = new UmaTokenSecret(umaToken);
|
||||||
SimpleCredentials credentials = (SimpleCredentials)appContext.authorizationProvider().getCredentials();
|
SimpleCredentials credentials = (SimpleCredentials)appContext.authorizationProvider().getCredentials();
|
||||||
KeycloakClient client = KeycloakClientFactory.newInstance();
|
KeycloakClient client = KeycloakClientFactory.newInstance();
|
||||||
try {
|
try {
|
||||||
if(!client.isAccessTokenVerified(secret.getContext(), credentials.getClientID(), credentials.getSecret(), accessToken))
|
if(!client.isAccessTokenVerified(secret.getContext(), credentials.getClientID(), credentials.getSecret(), umaToken))
|
||||||
RequestError.request_not_authorized_error.fire("access token verification error");
|
RequestError.request_not_authorized_error.fire("access token verification error");
|
||||||
}catch (KeycloakClientException e) {
|
}catch (KeycloakClientException e) {
|
||||||
RequestError.internal_server_error.fire("error contacting keycloak client", e);
|
RequestError.internal_server_error.fire("error contacting keycloak client", e);
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@ -24,7 +23,6 @@ import javax.servlet.ServletContextListener;
|
||||||
import javax.servlet.ServletRegistration;
|
import javax.servlet.ServletRegistration;
|
||||||
|
|
||||||
import org.gcube.common.events.Observes;
|
import org.gcube.common.events.Observes;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
import org.gcube.smartgears.context.container.ContainerContext;
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
|
@ -53,7 +51,7 @@ public class ApplicationManager {
|
||||||
|
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
private ApplicationExtensions extensions;
|
private List<ApplicationExtension> extensions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts application management.
|
* Starts application management.
|
||||||
|
@ -83,9 +81,11 @@ public class ApplicationManager {
|
||||||
|
|
||||||
ApplicationHandlers handlers = provider().handlersFor(context);
|
ApplicationHandlers handlers = provider().handlersFor(context);
|
||||||
|
|
||||||
|
/*
|
||||||
extensions = provider().extensionsFor(context);
|
extensions = provider().extensionsFor(context);
|
||||||
extensions.validate();
|
extensions.validate();
|
||||||
|
*/
|
||||||
|
|
||||||
List<ApplicationLifecycleHandler> lifecycleHandlers = handlers.lifecycleHandlers();
|
List<ApplicationLifecycleHandler> lifecycleHandlers = handlers.lifecycleHandlers();
|
||||||
List<RequestHandler> requestHandlers = handlers.requestHandlers();
|
List<RequestHandler> requestHandlers = handlers.requestHandlers();
|
||||||
|
|
||||||
|
@ -94,11 +94,12 @@ public class ApplicationManager {
|
||||||
log.trace("managing {} requests with {}", context.name(), requestHandlers);
|
log.trace("managing {} requests with {}", context.name(), requestHandlers);
|
||||||
log.trace("extending {} API with {}", context.name(), extensions);
|
log.trace("extending {} API with {}", context.name(), extensions);
|
||||||
|
|
||||||
|
extensions = provider().extensionsFor(context);
|
||||||
// order is important here: first add APIs
|
// order is important here: first add APIs
|
||||||
register(extensions);
|
registerExtension(extensions);
|
||||||
|
|
||||||
// then intercept them all
|
// then intercept them all
|
||||||
register(requestHandlers);
|
registerHandlers(requestHandlers);
|
||||||
|
|
||||||
// start lifecycle management
|
// start lifecycle management
|
||||||
start(lifecycleHandlers);
|
start(lifecycleHandlers);
|
||||||
|
@ -127,7 +128,7 @@ public class ApplicationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveApplicationState() {
|
private void saveApplicationState() {
|
||||||
File file = context.configuration().persistence().file(profile_file_path);
|
File file = context.persistence().file(profile_file_path);
|
||||||
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))){
|
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))){
|
||||||
oos.writeObject(context.id());
|
oos.writeObject(context.id());
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
@ -170,7 +171,7 @@ public class ApplicationManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register(List<RequestHandler> rqHandlers) {
|
private void registerHandlers(List<RequestHandler> rqHandlers) {
|
||||||
|
|
||||||
ServletContext app = context.application();
|
ServletContext app = context.application();
|
||||||
|
|
||||||
|
@ -197,11 +198,11 @@ public class ApplicationManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register(ApplicationExtensions extensions) {
|
private void registerExtension(List<ApplicationExtension> extensions) {
|
||||||
|
|
||||||
ServletContext application = context.application();
|
ServletContext application = context.application();
|
||||||
|
|
||||||
for (ApplicationExtension extension : extensions.extensions())
|
for (ApplicationExtension extension : extensions)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -234,10 +235,9 @@ public class ApplicationManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unregister(ApplicationExtensions extensions) {
|
private void unregister(List<ApplicationExtension> extensions) {
|
||||||
|
|
||||||
for (ApplicationExtension extension : extensions.extensions())
|
|
||||||
|
|
||||||
|
for (ApplicationExtension extension : extensions)
|
||||||
extension.stop();
|
extension.stop();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class ContainerManager {
|
||||||
|
|
||||||
|
|
||||||
private void saveContainerState() {
|
private void saveContainerState() {
|
||||||
File file = context.configuration().persistence().file(container_profile_file_path);
|
File file = context.persistenceWriter().file(container_profile_file_path);
|
||||||
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))){
|
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))){
|
||||||
oos.writeObject(context.id());
|
oos.writeObject(context.id());
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.exception.AuthorizationException;
|
import org.gcube.common.authorization.library.exception.AuthorizationException;
|
||||||
import org.gcube.smartgears.configuration.application.Exclude;
|
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||||
import org.gcube.smartgears.configuration.application.Include;
|
import org.gcube.smartgears.configuration.application.GCubeInclude;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
import org.gcube.smartgears.context.application.DefaultApplicationContext;
|
import org.gcube.smartgears.context.application.DefaultApplicationContext;
|
||||||
import org.gcube.smartgears.handlers.application.ApplicationPipeline;
|
import org.gcube.smartgears.handlers.application.ApplicationPipeline;
|
||||||
|
@ -137,7 +137,7 @@ public class RequestManager implements Filter {
|
||||||
log.debug("check wich handler should be excluded {}", path);
|
log.debug("check wich handler should be excluded {}", path);
|
||||||
|
|
||||||
if (!context.configuration().excludes().isEmpty()) {
|
if (!context.configuration().excludes().isEmpty()) {
|
||||||
for (Exclude exclude : context.configuration().excludes()){
|
for (GCubeExclude exclude : context.configuration().excludes()){
|
||||||
String excludePath= exclude.getPath();
|
String excludePath= exclude.getPath();
|
||||||
log.trace("exclude is {}",exclude);
|
log.trace("exclude is {}",exclude);
|
||||||
if ((WILDCARD).equals(excludePath) ||
|
if ((WILDCARD).equals(excludePath) ||
|
||||||
|
@ -145,7 +145,8 @@ public class RequestManager implements Filter {
|
||||||
excludePath.equals(path) || (path.endsWith("/") && excludePath.equals(path.substring(0, path.length()-1)))
|
excludePath.equals(path) || (path.endsWith("/") && excludePath.equals(path.substring(0, path.length()-1)))
|
||||||
){
|
){
|
||||||
//ALL handler are filtered except for unfiltrable
|
//ALL handler are filtered except for unfiltrable
|
||||||
if (exclude.getHandlers().isEmpty()) return handlersToFilter.stream().filter(RequestHandler::isUnfiltrable).toList();
|
if (exclude.getHandlers().isEmpty()) return handlersToFilter.stream()
|
||||||
|
.filter(RequestHandler::isUnfiltrable).collect(Collectors.toList());
|
||||||
|
|
||||||
List<RequestHandler> filteredHandlers = new ArrayList<>();
|
List<RequestHandler> filteredHandlers = new ArrayList<>();
|
||||||
for (RequestHandler rh : handlersToFilter)
|
for (RequestHandler rh : handlersToFilter)
|
||||||
|
@ -156,7 +157,7 @@ public class RequestManager implements Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!context.configuration().includes().isEmpty()) {
|
} else if (!context.configuration().includes().isEmpty()) {
|
||||||
for (Include include : context.configuration().includes()){
|
for (GCubeInclude include : context.configuration().includes()){
|
||||||
String includePath= include.getPath();
|
String includePath= include.getPath();
|
||||||
log.trace("include is {}",include);
|
log.trace("include is {}",include);
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.gcube.smartgears.persistence;
|
package org.gcube.smartgears.persistence;
|
||||||
|
|
||||||
|
|
||||||
import static org.gcube.smartgears.utils.Utils.fileAt;
|
import static org.gcube.smartgears.utils.Utils.fileAt;
|
||||||
import static org.gcube.smartgears.utils.Utils.notNull;
|
import static org.gcube.smartgears.utils.Utils.notNull;
|
||||||
|
|
||||||
|
@ -8,32 +7,21 @@ import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import org.gcube.smartgears.configuration.ComponentConfiguration;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import org.gcube.smartgears.configuration.ConfiguredWith;
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
import org.gcube.common.validator.annotations.NotEmpty;
|
@ConfiguredWith(LocalWriterConfiguration.class)
|
||||||
import org.gcube.common.validator.annotations.NotNull;
|
public class LocalWriter implements PersistenceWriter {
|
||||||
|
|
||||||
@XmlRootElement(name="persistence")
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
|
||||||
public class LocalPersistence implements PersistenceWriter {
|
|
||||||
|
|
||||||
@XmlAttribute(name="location") @NotNull @NotEmpty
|
|
||||||
private String location;
|
private String location;
|
||||||
|
|
||||||
protected LocalPersistence() {}
|
@Override
|
||||||
|
public void configure(ComponentConfiguration configuration) {
|
||||||
public LocalPersistence(String location) {
|
this.location = ((LocalWriterConfiguration) configuration).getLocation();
|
||||||
|
|
||||||
notNull("persistence location",location);
|
|
||||||
|
|
||||||
this.location=location;
|
|
||||||
|
|
||||||
validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getLocation() {
|
public String getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.gcube.smartgears.persistence;
|
||||||
|
|
||||||
|
import org.gcube.common.validator.annotations.NotEmpty;
|
||||||
|
import org.gcube.common.validator.annotations.NotNull;
|
||||||
|
import org.gcube.smartgears.configuration.ComponentConfiguration;
|
||||||
|
|
||||||
|
public class LocalWriterConfiguration implements ComponentConfiguration{
|
||||||
|
|
||||||
|
@NotEmpty @NotNull
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
protected LocalWriterConfiguration() {}
|
||||||
|
|
||||||
|
public LocalWriterConfiguration(String location) {
|
||||||
|
super();
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -2,8 +2,10 @@ package org.gcube.smartgears.persistence;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public interface PersistenceWriter {
|
import org.gcube.smartgears.configuration.Configurable;
|
||||||
|
|
||||||
|
public interface PersistenceWriter extends Configurable{
|
||||||
|
|
||||||
File file(String path);
|
File file(String path);
|
||||||
|
|
||||||
File writefile(String path);
|
File writefile(String path);
|
||||||
|
|
|
@ -2,22 +2,15 @@ package org.gcube.smartgears.provider;
|
||||||
|
|
||||||
import static org.gcube.smartgears.Constants.configuration_file_path;
|
import static org.gcube.smartgears.Constants.configuration_file_path;
|
||||||
import static org.gcube.smartgears.Constants.container_configuraton_file_path;
|
import static org.gcube.smartgears.Constants.container_configuraton_file_path;
|
||||||
import static org.gcube.smartgears.Constants.container_profile_file_path;
|
|
||||||
import static org.gcube.smartgears.Constants.default_extensions_file_path;
|
|
||||||
import static org.gcube.smartgears.Constants.extensions_file_path;
|
|
||||||
import static org.gcube.smartgears.Constants.ghn_home_env;
|
import static org.gcube.smartgears.Constants.ghn_home_env;
|
||||||
import static org.gcube.smartgears.Constants.ghn_home_property;
|
import static org.gcube.smartgears.Constants.ghn_home_property;
|
||||||
import static org.gcube.smartgears.Constants.library_configuration_file_path;
|
|
||||||
import static org.gcube.smartgears.Constants.profile_file_path;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
@ -27,18 +20,16 @@ import org.gcube.common.events.impl.DefaultHub;
|
||||||
import org.gcube.common.security.credentials.Credentials;
|
import org.gcube.common.security.credentials.Credentials;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfigurationBinder;
|
import org.gcube.smartgears.configuration.application.ApplicationConfigurationBinder;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
||||||
import org.gcube.smartgears.configuration.application.BridgedApplicationConfiguration;
|
|
||||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||||
import org.gcube.smartgears.configuration.container.ContainerConfigurationBinder;
|
import org.gcube.smartgears.configuration.container.ContainerConfigurationBinder;
|
||||||
import org.gcube.smartgears.configuration.library.SmartGearsConfiguration;
|
|
||||||
import org.gcube.smartgears.configuration.library.SmartGearsConfigurationBinder;
|
|
||||||
import org.gcube.smartgears.context.Properties;
|
import org.gcube.smartgears.context.Properties;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
import org.gcube.smartgears.context.application.DefaultApplicationContext;
|
import org.gcube.smartgears.context.application.DefaultApplicationContext;
|
||||||
import org.gcube.smartgears.context.container.ContainerContext;
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
import org.gcube.smartgears.context.container.DefaultContainerContext;
|
import org.gcube.smartgears.context.container.DefaultContainerContext;
|
||||||
|
import org.gcube.smartgears.extensions.ApplicationExtension;
|
||||||
|
import org.gcube.smartgears.extensions.resource.RemoteResource;
|
||||||
import org.gcube.smartgears.handlers.container.ContainerHandler;
|
import org.gcube.smartgears.handlers.container.ContainerHandler;
|
||||||
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
||||||
import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
|
import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
|
||||||
|
@ -88,32 +79,14 @@ public class DefaultProvider implements Provider {
|
||||||
Hub hub = new DefaultHub();
|
Hub hub = new DefaultHub();
|
||||||
|
|
||||||
ContainerLifecycle lifecycle = new ContainerLifecycle(hub);
|
ContainerLifecycle lifecycle = new ContainerLifecycle(hub);
|
||||||
|
|
||||||
File file = configuration.persistence().file(container_profile_file_path);
|
AuthorizationProviderFactory<?> authfactory = configuration.authorizationConfiguration()
|
||||||
|
|
||||||
String id = null;
|
|
||||||
if (file.exists()) {
|
|
||||||
log.info("loading persisted state for container");
|
|
||||||
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
|
|
||||||
id = (String) ois.readObject();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("error loading persisted state, creating new uuid", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (id == null) {
|
|
||||||
id = UUID.randomUUID().toString();
|
|
||||||
log.info("container id created is {}", id);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthorizationProviderFactory<?> authfactory = configuration.getauthorizationConfiguration()
|
|
||||||
.getAuthProviderFactory();
|
.getAuthProviderFactory();
|
||||||
Credentials credentials = configuration.getauthorizationConfiguration().getCredentials();
|
Credentials credentials = configuration.authorizationConfiguration().getCredentials();
|
||||||
|
|
||||||
AuthorizationProvider authProvider = authfactory.connect(credentials);
|
AuthorizationProvider authProvider = authfactory.connect(credentials);
|
||||||
|
|
||||||
containerContext = new DefaultContainerContext(id, configuration, hub, lifecycle, authProvider,
|
containerContext = new DefaultContainerContext(configuration, hub, lifecycle, authProvider,
|
||||||
new Properties());
|
new Properties());
|
||||||
}
|
}
|
||||||
return containerContext;
|
return containerContext;
|
||||||
|
@ -147,63 +120,20 @@ public class DefaultProvider implements Provider {
|
||||||
@Override
|
@Override
|
||||||
public ApplicationContext contextFor(ContainerContext context, ServletContext application) {
|
public ApplicationContext contextFor(ContainerContext context, ServletContext application) {
|
||||||
|
|
||||||
ApplicationConfiguration configuration = null;
|
|
||||||
ApplicationConfiguration embedded = configurationFor(application);
|
ApplicationConfiguration embedded = configurationFor(application);
|
||||||
ApplicationConfiguration external = context.configuration().app(application.getContextPath());
|
|
||||||
|
|
||||||
// shouldn't happen: management shouldn't have started at all
|
// shouldn't happen: management shouldn't have started at all
|
||||||
if (embedded == null && external == null)
|
if (embedded == null)
|
||||||
throw new AssertionError("application @ " + application.getContextPath() + " is not distributed with "
|
throw new AssertionError("application @ " + application.getContextPath() + " is not distributed with "
|
||||||
+ configuration_file_path + " and there is no external configuration for it in "
|
+ configuration_file_path + " and there is no external configuration for it in "
|
||||||
+ container_configuraton_file_path);
|
+ container_configuraton_file_path);
|
||||||
|
|
||||||
// no embedded configuration
|
|
||||||
if (embedded == null) {
|
|
||||||
|
|
||||||
configuration = external;
|
|
||||||
|
|
||||||
log.info("loaded configuration for application " + configuration.name() + " from "
|
|
||||||
+ container_configuraton_file_path);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
configuration = embedded;
|
|
||||||
|
|
||||||
if (external == null)
|
|
||||||
|
|
||||||
log.info("loaded configuration for application " + configuration.name() + " from "
|
|
||||||
+ configuration_file_path);
|
|
||||||
|
|
||||||
else {
|
|
||||||
|
|
||||||
configuration.merge(external);
|
|
||||||
|
|
||||||
log.info("loaded configuration for application " + configuration.name() + " from "
|
|
||||||
+ configuration_file_path + " and " + container_configuraton_file_path);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicationConfiguration bridgedConfiguration = new BridgedApplicationConfiguration(context.configuration(),
|
|
||||||
configuration);
|
|
||||||
|
|
||||||
Hub hub = new DefaultHub();
|
Hub hub = new DefaultHub();
|
||||||
|
|
||||||
ApplicationLifecycle lifecycle = new ApplicationLifecycle(hub, configuration.name());
|
ApplicationLifecycle lifecycle = new ApplicationLifecycle(hub, embedded.name());
|
||||||
|
|
||||||
File file = bridgedConfiguration.persistence().file(profile_file_path);
|
return new DefaultApplicationContext(context, application, embedded, hub, lifecycle,
|
||||||
String id = null;
|
|
||||||
if (file.exists()) {
|
|
||||||
log.info("loading persisted state for application {}", application.getContextPath());
|
|
||||||
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
|
|
||||||
id = (String) ois.readObject();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("error loading persisted state, creating new uuid", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (id == null)
|
|
||||||
id = UUID.randomUUID().toString();
|
|
||||||
|
|
||||||
return new DefaultApplicationContext(id, context, application, bridgedConfiguration, hub, lifecycle,
|
|
||||||
new Properties());
|
new Properties());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,62 +165,8 @@ public class DefaultProvider implements Provider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public List<ApplicationExtension> extensionsFor(ApplicationContext context){
|
||||||
public ApplicationExtensions extensionsFor(ApplicationContext context) {
|
return List.of(new RemoteResource());
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
InputStream config = context.application().getResourceAsStream(extensions_file_path);
|
|
||||||
|
|
||||||
if (config == null) {
|
|
||||||
|
|
||||||
log.trace("{} uses default extensions as it does not include {}", context.name(), extensions_file_path);
|
|
||||||
|
|
||||||
// it's in a library, using
|
|
||||||
config = getClass().getResourceAsStream(default_extensions_file_path);
|
|
||||||
|
|
||||||
if (config == null)
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"invalid distribution: cannot find " + default_extensions_file_path);
|
|
||||||
|
|
||||||
} else
|
|
||||||
log.info("{} uses custom extensions @ {}", context.name(), extensions_file_path);
|
|
||||||
|
|
||||||
ApplicationConfigurationBinder binder = new ApplicationConfigurationBinder();
|
|
||||||
|
|
||||||
return binder.bindExtensions(config);
|
|
||||||
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
|
|
||||||
throw new RuntimeException(
|
|
||||||
"cannot install extensions for application @ " + context.name() + " (see cause) ", e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SmartGearsConfiguration smartgearsConfiguration() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
InputStream config = getClass().getResourceAsStream(library_configuration_file_path);
|
|
||||||
|
|
||||||
if (config == null)
|
|
||||||
throw new IllegalStateException("invalid distribution: cannot find " + library_configuration_file_path);
|
|
||||||
|
|
||||||
SmartGearsConfigurationBinder binder = new SmartGearsConfigurationBinder();
|
|
||||||
|
|
||||||
SmartGearsConfiguration configuration = binder.bind(config);
|
|
||||||
|
|
||||||
configuration.validate();
|
|
||||||
|
|
||||||
return configuration;
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
|
|
||||||
throw new RuntimeException("cannot read library configuration (see cause) ", e);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
|
@ -305,7 +181,7 @@ public class DefaultProvider implements Provider {
|
||||||
|
|
||||||
ApplicationConfigurationBinder binder = new ApplicationConfigurationBinder();
|
ApplicationConfigurationBinder binder = new ApplicationConfigurationBinder();
|
||||||
|
|
||||||
return binder.bind(config);
|
return binder.load(config);
|
||||||
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,10 @@ import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
||||||
import org.gcube.smartgears.configuration.library.SmartGearsConfiguration;
|
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
import org.gcube.smartgears.context.container.ContainerContext;
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
|
import org.gcube.smartgears.extensions.ApplicationExtension;
|
||||||
import org.gcube.smartgears.handlers.container.ContainerHandler;
|
import org.gcube.smartgears.handlers.container.ContainerHandler;
|
||||||
import org.gcube.smartgears.publishing.Publisher;
|
import org.gcube.smartgears.publishing.Publisher;
|
||||||
|
|
||||||
|
@ -25,8 +24,9 @@ public interface Provider {
|
||||||
/**
|
/**
|
||||||
* Returns the runtime properties.
|
* Returns the runtime properties.
|
||||||
* @return the properties.
|
* @return the properties.
|
||||||
*/
|
|
||||||
SmartGearsConfiguration smartgearsConfiguration();
|
SmartGearsConfiguration smartgearsConfiguration();
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assembles and returns the context of the container.
|
* Assembles and returns the context of the container.
|
||||||
|
@ -65,12 +65,7 @@ public interface Provider {
|
||||||
*/
|
*/
|
||||||
ApplicationHandlers handlersFor(ApplicationContext application);
|
ApplicationHandlers handlersFor(ApplicationContext application);
|
||||||
|
|
||||||
/**
|
List<ApplicationExtension> extensionsFor(ApplicationContext application);
|
||||||
* Returns the API extensions associated with a given application.
|
|
||||||
* @param application the context of the application
|
|
||||||
* @return the extensions
|
|
||||||
*/
|
|
||||||
ApplicationExtensions extensionsFor(ApplicationContext application);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ import org.gcube.common.keycloak.model.AccessToken.Access;
|
||||||
import org.gcube.common.keycloak.model.ModelUtils;
|
import org.gcube.common.keycloak.model.ModelUtils;
|
||||||
import org.gcube.common.keycloak.model.TokenResponse;
|
import org.gcube.common.keycloak.model.TokenResponse;
|
||||||
import org.gcube.common.security.ContextBean;
|
import org.gcube.common.security.ContextBean;
|
||||||
import org.gcube.common.security.secrets.AccessTokenSecret;
|
|
||||||
import org.gcube.common.security.secrets.Secret;
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.common.security.secrets.UmaTokenSecret;
|
||||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
import org.gcube.smartgears.security.SimpleCredentials;
|
import org.gcube.smartgears.security.SimpleCredentials;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -61,7 +61,7 @@ public class DefaultAuthorizationProvider implements AuthorizationProvider {
|
||||||
public Secret getSecretForContext(String context) {
|
public Secret getSecretForContext(String context) {
|
||||||
try {
|
try {
|
||||||
TokenResponse response = client.queryUMAToken(new URL(this.endpoint), credentials.getClientID(), credentials.getSecret(), context, null);
|
TokenResponse response = client.queryUMAToken(new URL(this.endpoint), credentials.getClientID(), credentials.getSecret(), context, null);
|
||||||
return new AccessTokenSecret(response.getAccessToken());
|
return new UmaTokenSecret(response.getAccessToken());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("error getting OIDToken from keycloak",e);
|
LOG.error("error getting OIDToken from keycloak",e);
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
||||||
<extensions>
|
|
||||||
<remote-management/>
|
|
||||||
</extensions>
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE xml>
|
|
||||||
<Resource>
|
|
||||||
<ID />
|
|
||||||
<Type>Service</Type>
|
|
||||||
<Profile>
|
|
||||||
<Description>${description}</Description>
|
|
||||||
<Class>${serviceClass}</Class>
|
|
||||||
<Name>common-smartgears</Name>
|
|
||||||
<Version>1.0.0</Version>
|
|
||||||
<Packages>
|
|
||||||
<Software>
|
|
||||||
<Description>${description}</Description>
|
|
||||||
<Name>common-smartgears</Name>
|
|
||||||
<Version>4.0.0-SNAPSHOT</Version>
|
|
||||||
<MavenCoordinates>
|
|
||||||
<groupId>org.gcube.core</groupId>
|
|
||||||
<artifactId>common-smartgears</artifactId>
|
|
||||||
<version>4.0.0-SNAPSHOT</version>
|
|
||||||
</MavenCoordinates>
|
|
||||||
<Type>Library</Type>
|
|
||||||
<Files>
|
|
||||||
<File>common-smartgears-4.0.0-SNAPSHOT.jar</File>
|
|
||||||
</Files>
|
|
||||||
</Software>
|
|
||||||
</Packages>
|
|
||||||
</Profile>
|
|
||||||
</Resource>
|
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
package utils;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||||
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
|
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||||
|
import org.gcube.smartgears.persistence.LocalWriter;
|
||||||
|
import org.gcube.smartgears.persistence.LocalWriterConfiguration;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
public class ConfigurationTest {
|
||||||
|
|
||||||
|
static final String yamlConf = "name: test\n"
|
||||||
|
+ "group: group\n"
|
||||||
|
+ "version: 1.0.0\n"
|
||||||
|
+ "description: pippo\n"
|
||||||
|
+ "proxable: true\n"
|
||||||
|
+ "excludes:\n"
|
||||||
|
+ "- path: /pippo/*\n"
|
||||||
|
+ "- handlers: [H1, H2]\n"
|
||||||
|
+ " path: /trip\n"
|
||||||
|
+ "persistence:\n"
|
||||||
|
+ " implementationClass: org.gcube.smartgears.persistence.LocalWriter\n"
|
||||||
|
+ " writerConfiguration:\n"
|
||||||
|
+ " className: org.gcube.smartgears.persistence.LocalWriterConfiguration\n"
|
||||||
|
+ " location: /tmp";
|
||||||
|
|
||||||
|
static final String yamlConfBase = "name: test\n"
|
||||||
|
+ "group: group\n"
|
||||||
|
+ "version: 1.0.0\n"
|
||||||
|
+ "description: pippo";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deserialize() {
|
||||||
|
Yaml yaml = new Yaml();
|
||||||
|
InputStream inputStream = this.getClass()
|
||||||
|
.getClassLoader()
|
||||||
|
.getResourceAsStream("applicationTest.yaml");
|
||||||
|
ApplicationConfiguration customer = yaml.load(inputStream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void serialize() throws Exception{
|
||||||
|
ApplicationConfiguration configuration =new ApplicationConfiguration();
|
||||||
|
configuration.name("test").serviceClass("group").description("pippo").version("1.0.0").excludes(new GCubeExclude("/pippo/*"), new GCubeExclude(List.of("H1","H2"), "/trip"));
|
||||||
|
configuration.persistenceConfiguration(new PersistenceConfiguration(LocalWriter.class, new LocalWriterConfiguration("/tmp")));
|
||||||
|
/*
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String value = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(configuration);
|
||||||
|
System.out.println(value);
|
||||||
|
Map<String, Object> res = mapper.readValue(value, Map.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Yaml yaml = new Yaml();
|
||||||
|
String yamlValue = yaml.dump(res);
|
||||||
|
System.out.println(yamlValue);
|
||||||
|
*/
|
||||||
|
|
||||||
|
Yaml yaml = new Yaml();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String mapAsString = mapper.writeValueAsString(yaml.load(yamlConf));
|
||||||
|
System.out.println(mapAsString);
|
||||||
|
|
||||||
|
ApplicationConfiguration conf2 = mapper.readValue(mapAsString, ApplicationConfiguration.class);
|
||||||
|
Assert.assertTrue(configuration.equals(conf2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void serializeBase() throws Exception{
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
Yaml yaml = new Yaml();
|
||||||
|
|
||||||
|
String mapAsString = mapper.writeValueAsString(yaml.load(yamlConfBase));
|
||||||
|
System.out.println(mapAsString);
|
||||||
|
|
||||||
|
ApplicationConfiguration conf2 = mapper.readValue(mapAsString, ApplicationConfiguration.class);
|
||||||
|
Assert.assertEquals("test", conf2.name());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||||
|
|
||||||
import org.gcube.common.validator.annotations.IsValid;
|
import org.gcube.common.validator.annotations.IsValid;
|
||||||
import org.gcube.common.validator.annotations.NotNull;
|
import org.gcube.common.validator.annotations.NotNull;
|
||||||
|
import org.gcube.smartgears.configuration.ComponentConfiguration;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||||
|
|
||||||
public class PersistenceWriterTest implements PersistenceWriter{
|
public class PersistenceWriterTest implements PersistenceWriter{
|
||||||
|
@ -33,5 +34,10 @@ public class PersistenceWriterTest implements PersistenceWriter{
|
||||||
public long getFreeSpace() {
|
public long getFreeSpace() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(ComponentConfiguration configuration) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package utils;
|
package utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
||||||
import org.gcube.smartgears.configuration.library.SmartGearsConfiguration;
|
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
import org.gcube.smartgears.context.container.ContainerContext;
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
|
import org.gcube.smartgears.extensions.ApplicationExtension;
|
||||||
import org.gcube.smartgears.provider.DefaultProvider;
|
import org.gcube.smartgears.provider.DefaultProvider;
|
||||||
|
|
||||||
public class TestProvider extends DefaultProvider {
|
public class TestProvider extends DefaultProvider {
|
||||||
|
@ -21,7 +21,7 @@ public class TestProvider extends DefaultProvider {
|
||||||
public ApplicationContext context;
|
public ApplicationContext context;
|
||||||
public ApplicationConfiguration configuration;
|
public ApplicationConfiguration configuration;
|
||||||
public ApplicationHandlers handlers;
|
public ApplicationHandlers handlers;
|
||||||
public ApplicationExtensions extensions;
|
public List<ApplicationExtension> extensions;
|
||||||
|
|
||||||
|
|
||||||
public void use(ApplicationConfiguration configuration) {
|
public void use(ApplicationConfiguration configuration) {
|
||||||
|
@ -32,18 +32,18 @@ public class TestProvider extends DefaultProvider {
|
||||||
this.handlers=handlers;
|
this.handlers=handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void use(ApplicationExtensions extensions) {
|
public void use(List<ApplicationExtension> extensions) {
|
||||||
this.extensions=extensions;
|
this.extensions=extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public SmartGearsConfiguration smartgearsConfiguration() {
|
public SmartGearsConfiguration smartgearsConfiguration() {
|
||||||
SmartGearsConfiguration conf = new SmartGearsConfiguration();
|
SmartGearsConfiguration conf = new SmartGearsConfiguration();
|
||||||
conf.version("0.0.1-TEST");
|
conf.version("0.0.1-TEST");
|
||||||
return conf ;
|
return conf ;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,7 +57,7 @@ public class TestProvider extends DefaultProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApplicationExtensions extensionsFor(ApplicationContext context) {
|
public List<ApplicationExtension> extensionsFor(ApplicationContext context) {
|
||||||
return extensions==null?super.extensionsFor(context):extensions;
|
return extensions==null?super.extensionsFor(context):extensions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,155 +0,0 @@
|
||||||
package utils;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
|
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
|
||||||
import org.gcube.smartgears.configuration.application.DefaultApplicationConfiguration;
|
|
||||||
import org.gcube.smartgears.extensions.ApplicationExtension;
|
|
||||||
import org.gcube.smartgears.handlers.application.ApplicationHandler;
|
|
||||||
|
|
||||||
|
|
||||||
public class TestUtils {
|
|
||||||
|
|
||||||
|
|
||||||
public static String location = "/tmp/ghn-home";
|
|
||||||
public static String context_root = "test-app";
|
|
||||||
public static String context_root_path = "/" + context_root;
|
|
||||||
public static String servlet_name = "test";
|
|
||||||
public static String scope = "/gcube/devsec";
|
|
||||||
|
|
||||||
public static class Box<T> {
|
|
||||||
|
|
||||||
T t;
|
|
||||||
|
|
||||||
public void put(T t) {
|
|
||||||
this.t=t;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T get() {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialises a {@link ApplicationConfiguration} to XML.
|
|
||||||
*
|
|
||||||
* @param config the configuration
|
|
||||||
* @return the serialisation
|
|
||||||
* @throws RuntimeException if the configuration cannot be serialised
|
|
||||||
*/
|
|
||||||
public static String bind(ApplicationConfiguration config) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
//collect handler classes
|
|
||||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
|
||||||
|
|
||||||
classes.add(DefaultApplicationConfiguration.class);
|
|
||||||
if (config.persistence()!=null)
|
|
||||||
classes.add(config.persistence().getClass());
|
|
||||||
|
|
||||||
//serialises configuration
|
|
||||||
|
|
||||||
JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class<?>[0]));
|
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
|
|
||||||
ctx.createMarshaller().marshal(config, writer);
|
|
||||||
|
|
||||||
return writer.toString();
|
|
||||||
|
|
||||||
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
|
|
||||||
throw new RuntimeException("invalid application configuration", e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialises application handlers.
|
|
||||||
*
|
|
||||||
* @param handlers the handlers
|
|
||||||
* @return the serialisation
|
|
||||||
* @throws RuntimeException if the handlers cannot be serialised
|
|
||||||
*/
|
|
||||||
public static String bind(ApplicationHandlers handlers) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
//collect handler classes
|
|
||||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
|
||||||
|
|
||||||
classes.add(ApplicationHandlers.class);
|
|
||||||
|
|
||||||
for (ApplicationHandler<?> h : handlers.lifecycleHandlers())
|
|
||||||
classes.add(h.getClass());
|
|
||||||
|
|
||||||
for (ApplicationHandler<?> h : handlers.requestHandlers())
|
|
||||||
classes.add(h.getClass());
|
|
||||||
|
|
||||||
|
|
||||||
//serialises configuration
|
|
||||||
|
|
||||||
JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class<?>[0]));
|
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
|
|
||||||
ctx.createMarshaller().marshal(handlers, writer);
|
|
||||||
|
|
||||||
return writer.toString();
|
|
||||||
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
|
|
||||||
throw new RuntimeException("invalid handler configuration", e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialises application extensions.
|
|
||||||
*
|
|
||||||
* @param extensions the extensions
|
|
||||||
* @return the serialisation
|
|
||||||
* @throws RuntimeException if the extensions cannot be serialised
|
|
||||||
*/
|
|
||||||
public static String bind(ApplicationExtensions extensions) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
//collect handler classes
|
|
||||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
|
||||||
|
|
||||||
classes.add(ApplicationExtensions.class);
|
|
||||||
|
|
||||||
for (ApplicationExtension h : extensions.extensions())
|
|
||||||
classes.add(h.getClass());
|
|
||||||
|
|
||||||
|
|
||||||
//serialises configuration
|
|
||||||
|
|
||||||
JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class<?>[0]));
|
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
|
|
||||||
ctx.createMarshaller().marshal(extensions, writer);
|
|
||||||
|
|
||||||
return writer.toString();
|
|
||||||
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
|
|
||||||
throw new RuntimeException("invalid handler configuration", e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
name: test
|
||||||
|
group: group
|
||||||
|
version: 1.0.0
|
||||||
|
#not mandatory
|
||||||
|
description: pippo
|
||||||
|
#not mandatory
|
||||||
|
proxable: true
|
||||||
|
#not mandatory
|
||||||
|
excludes:
|
||||||
|
- path: /pippo/*
|
||||||
|
- handlers: [H1, H2]
|
||||||
|
path: /trip
|
||||||
|
#not mandatory
|
||||||
|
persistence:
|
||||||
|
implementationClass: org.gcube.smartgears.persistence.LocalWriter
|
||||||
|
writerConfiguration:
|
||||||
|
className: org.gcube.smartgears.persistence.LocalWriterConfiguration
|
||||||
|
location: /tmp
|
Loading…
Reference in New Issue