diff --git a/.classpath b/.classpath
index bbf76ce..caaae5e 100644
--- a/.classpath
+++ b/.classpath
@@ -30,7 +30,6 @@
-
diff --git a/pom.xml b/pom.xml
index 3649229..0d2f845 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,7 +108,32 @@
jersey-gf-cdi
2.13
-
+
+
+ javax.transaction
+ javax.transaction-api
+ 1.2
+
+
+
+
+
+ javax.enterprise
+ cdi-api
+ 1.1
+
+
+ org.jboss.weld.servlet
+ weld-servlet
+ 2.2.10.Final
+
+
+
+ org.jboss
+ jandex
+ 1.2.2.Final
+
+
javax.servlet
javax.servlet-api
@@ -124,14 +149,7 @@
-
- javax.servlet
- javax.servlet-api
- 3.0.1
- provided
-
-
-
+
org.gcube.spatial.data
diff --git a/src/main/java/org/gcube/datatransfer/resolver/Constants.java b/src/main/java/org/gcube/datatransfer/resolver/Constants.java
index 70d0d29..46f7df1 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/Constants.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/Constants.java
@@ -3,5 +3,4 @@ package org.gcube.datatransfer.resolver;
public class Constants {
public static final String SERVLET_GEONETWORK = "geonetwork";
- public static final String SERVLET_CATALOGUE = "catalogue";
}
diff --git a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java
index 5571d8a..4531b7e 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java
@@ -1,23 +1,16 @@
package org.gcube.datatransfer.resolver;
-import java.util.HashSet;
-import java.util.Set;
-
import javax.ws.rs.Path;
-import javax.ws.rs.core.Application;
-import org.gcube.datatransfer.resolver.services.Catalogue;
-import org.gcube.datatransfer.resolver.services.StorageManager;
+import org.glassfish.jersey.server.ResourceConfig;
@Path("uri-resolver")
-public class UriResolver extends Application {
+public class UriResolver extends ResourceConfig {
- @Override
- public Set> getClasses() {
- final Set> classes = new HashSet>();
- // register resources and features
- classes.add(StorageManager.class);
- classes.add(Catalogue.class);
- return classes;
+ public UriResolver() {
+ // Register all resources present under the package.
+ packages("org.gcube.datatransfer.resolver.services","org.gcube.datatransfer.resolver.requesthandler");
+
}
}
+
diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/ApplicationProfileReaderForCatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/ApplicationProfileReaderForCatalogueResolver.java
index 70debd7..fdc9be2 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/ApplicationProfileReaderForCatalogueResolver.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/ApplicationProfileReaderForCatalogueResolver.java
@@ -83,22 +83,18 @@ public class ApplicationProfileReaderForCatalogueResolver {
*/
private void readProfileFromInfrastrucure() {
- String originalScope = ScopeProvider.instance.get();
- String queryString = GcubeQuery.getGcubeGenericResource(secondaryType, FIELD_TYPE.RESOURCE_NAME, resourceName);
+ String queryString = GcubeQuery.getGcubeGenericResource(secondaryType, FIELD_TYPE.RESOURCE_NAME, resourceName);
- try {
+ try {
+ logger.info("Trying to fetch ApplicationProfile in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType + ", ResourceName: " + resourceName);
+ Query q = new QueryBox(queryString);
+ DiscoveryClient client = client();
+ List appProfile = client.submit(q);
- String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scope):scope;
- ScopeProvider.instance.set(discoveryScope);
- logger.info("Trying to fetch ApplicationProfile in the scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", ResourceName: " + resourceName);
- Query q = new QueryBox(queryString);
- DiscoveryClient client = client();
- List appProfile = client.submit(q);
-
- if (appProfile == null || appProfile.size() == 0)
- throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", ResourceName: " + resourceName +" is not registered in the scope: "+discoveryScope);
- else {
- try{
+ if (appProfile == null || appProfile.size() == 0)
+ throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", ResourceName: " + resourceName +" is not registered in the scope: "+ScopeProvider.instance.get());
+ else {
+ try{
String elem = appProfile.get(0);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = docBuilder.parse(new InputSource(new StringReader(elem)));
@@ -110,21 +106,13 @@ public class ApplicationProfileReaderForCatalogueResolver {
logger.info("For scope: "+scopeFound+", found VRE_NAME "+vreName);
hashVreNameScope.put(vreName.get(0), scopeFound);
}
- }catch(Exception e){
- throw new ApplicationProfileNotFoundException("Error during parsing application profile with resource name: "+resourceName + " in the scope: "+scope.toString());
- }
+ }catch(Exception e){
+ throw new ApplicationProfileNotFoundException("Error during parsing application profile with resource name: "+resourceName + " in the scope: "+scope.toString());
+ }
}
} catch (Exception e) {
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
- }finally{
- if(originalScope!=null && !originalScope.isEmpty()){
- ScopeProvider.instance.set(originalScope);
- logger.info("scope provider setted to orginal scope: "+originalScope);
- }else{
- ScopeProvider.instance.reset();
- logger.info("scope provider reset");
- }
}
}
diff --git a/src/main/java/org/gcube/datatransfer/resolver/requesthandler/TokenSetter.java b/src/main/java/org/gcube/datatransfer/resolver/requesthandler/TokenSetter.java
new file mode 100644
index 0000000..2a6077f
--- /dev/null
+++ b/src/main/java/org/gcube/datatransfer/resolver/requesthandler/TokenSetter.java
@@ -0,0 +1,41 @@
+package org.gcube.datatransfer.resolver.requesthandler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+
+import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
+import org.gcube.common.scope.api.ScopeProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@Provider
+public class TokenSetter implements ContainerRequestFilter, ContainerResponseFilter {
+
+ private static final Logger log = LoggerFactory.getLogger(TokenSetter.class);
+
+ @Context ServletContext context;
+
+ @Override
+ public void filter(ContainerRequestContext ctx) throws IOException {
+ log.info("TokenSetter Request called");
+ SecurityTokenProvider.instance.set(context.getInitParameter("root-app-token"));
+ ScopeProvider.instance.set(context.getInitParameter("root-scope"));
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
+ throws IOException {
+ log.info("TokenSetter Response called");
+ SecurityTokenProvider.instance.reset();
+ ScopeProvider.instance.reset();
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java b/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java
index af36581..b11a7a3 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java
@@ -2,7 +2,6 @@ package org.gcube.datatransfer.resolver.services;
import java.net.URL;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -17,65 +16,32 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.gcube.common.scope.api.ScopeProvider;
-import org.gcube.datatransfer.resolver.Constants;
import org.gcube.datatransfer.resolver.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
-import org.gcube.datatransfer.resolver.catalogue.CatalogueResolver;
import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
import org.gcube.datatransfer.resolver.catalogue.resource.UpdateApplicationProfileCatalogueResolver;
-import org.gcube.datatransfer.resolver.scope.ScopeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.model.CkanDataset;
-@Path(Constants.SERVLET_CATALOGUE)
+@Path("/")
public class Catalogue {
private static Logger logger = LoggerFactory.getLogger(Catalogue.class);
- private ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
-
public static final String ENV_SCOPE = "SCOPE"; //Environment Variable
-
+
/** The scope to enc decr. */
private String scopeToEncDecr = null;
-
- public void init() throws ServletException {
- initScopeFromEnv();
- }
-
-
- /**
- * Inits the scope from env.
- *
- * @return the string
- * @throws ServletException the servlet exception
- */
- private String initScopeFromEnv() throws ServletException{
-
- if(scopeToEncDecr!=null)
- return scopeToEncDecr;
-
- try{
- scopeToEncDecr = ScopeUtil.getScopeFromEnvironment();
- }catch(ServletException e){
- logger.error("I cannot encrypt/descrypt: ", e);
- throw new ServletException(CatalogueResolver.class.getName() +" cannot work without set the Environment Variable: "+ENV_SCOPE);
- }
-
- appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToEncDecr, true);
- logger.info("Resource read for CatalogueResolver: "+appPrCatResolver);
- return scopeToEncDecr;
- }
-
+ ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
@GET
- @Path("{ctlg(-(o|g|p|g))?}/{vreName}/{entityName}")
+ @Path("{entityContext:ctlg(-(o|g|p|d)?}/{vreName}/{entityName}")
public Response resolveCatalogue(@PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) {
try {
@@ -118,7 +84,7 @@ public class Catalogue {
}
@POST
- @Path("")
+ @Path("catalogue")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) {
diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java
index dfeab9e..f461c7a 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java
@@ -2,9 +2,9 @@ package org.gcube.datatransfer.resolver.services;
import java.io.InputStream;
+import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@@ -19,14 +19,15 @@ import org.gcube.datatransfer.resolver.SingleFileStreamingOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Path("")
+@Path("/")
public class StorageManager {
private static Logger logger = LoggerFactory.getLogger(StorageManager.class);
+ @GET
@Path("{smpId}")
- @Produces()
public Response getFile(@PathParam("smpId") String smpId) {
+ logger.info("resolve Storage Id called");
StorageClient client = new StorageClient("DataTransfer", "UriResolver", "storageid-resolver", AccessType.PUBLIC);
IClient iClient = client.getClient();
String toSEID = iClient.getId(smpId); //to Storage Encrypted ID
@@ -50,7 +51,8 @@ public class StorageManager {
}catch (Exception e) {
logger.warn("Error when getting file metadata from storage, printing this warning and trying to continue..", e);
}
-
+
+ logger.info("filename retrieved is {}",fileName);
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream
diff --git a/src/main/webapp/WEB-INF/gcube-app.xml b/src/main/webapp/WEB-INF/gcube-app.xml
index b6455fc..094b2d5 100644
--- a/src/main/webapp/WEB-INF/gcube-app.xml
+++ b/src/main/webapp/WEB-INF/gcube-app.xml
@@ -3,5 +3,5 @@
DataTransfer
1.0.0-SNAPSHOT
Storage Hub webapp
-
+ /*
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index be5ca7e..e137d44 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -1,87 +1,23 @@
-
-
+
+ root-app-token
+ e22a46ac-418c-49f2-ad3f-99a5b9689825-98187548
+
+
+ root-scope
+ /gcube
+
+ root-scope
- org.gcube.data.access.storagehub.StorageHub
+ org.gcube.datatransfer.resolver.UriResolver
- org.gcube.data.access.storagehub.StorageHub
- /workspace/*
+ org.gcube.datatransfer.resolver.UriResolver
+ /*