This commit is contained in:
Lucio Lelii 2018-10-18 16:24:49 +00:00
parent 582673819a
commit f0ac1a5670
10 changed files with 112 additions and 170 deletions

View File

@ -30,7 +30,6 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>

36
pom.xml
View File

@ -108,7 +108,32 @@
<artifactId>jersey-gf-cdi</artifactId> <artifactId>jersey-gf-cdi</artifactId>
<version>2.13</version> <version>2.13</version>
</dependency> </dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
</dependency>
<!-- weld -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.2.10.Final</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>1.2.2.Final</version>
</dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
@ -124,14 +149,7 @@
</dependency> </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- GIS RESOLVER DEPENDENCIES --> <!-- GIS RESOLVER DEPENDENCIES -->
<dependency> <dependency>
<groupId>org.gcube.spatial.data</groupId> <groupId>org.gcube.spatial.data</groupId>

View File

@ -3,5 +3,4 @@ package org.gcube.datatransfer.resolver;
public class Constants { public class Constants {
public static final String SERVLET_GEONETWORK = "geonetwork"; public static final String SERVLET_GEONETWORK = "geonetwork";
public static final String SERVLET_CATALOGUE = "catalogue";
} }

View File

@ -1,23 +1,16 @@
package org.gcube.datatransfer.resolver; package org.gcube.datatransfer.resolver;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import org.gcube.datatransfer.resolver.services.Catalogue; import org.glassfish.jersey.server.ResourceConfig;
import org.gcube.datatransfer.resolver.services.StorageManager;
@Path("uri-resolver") @Path("uri-resolver")
public class UriResolver extends Application { public class UriResolver extends ResourceConfig {
@Override public UriResolver() {
public Set<Class<?>> getClasses() { // Register all resources present under the package.
final Set<Class<?>> classes = new HashSet<Class<?>>(); packages("org.gcube.datatransfer.resolver.services","org.gcube.datatransfer.resolver.requesthandler");
// register resources and features
classes.add(StorageManager.class);
classes.add(Catalogue.class);
return classes;
} }
} }

View File

@ -83,22 +83,18 @@ public class ApplicationProfileReaderForCatalogueResolver {
*/ */
private void readProfileFromInfrastrucure() { 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<String> client = client();
List<String> appProfile = client.submit(q);
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scope):scope; if (appProfile == null || appProfile.size() == 0)
ScopeProvider.instance.set(discoveryScope); throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", ResourceName: " + resourceName +" is not registered in the scope: "+ScopeProvider.instance.get());
logger.info("Trying to fetch ApplicationProfile in the scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", ResourceName: " + resourceName); else {
Query q = new QueryBox(queryString); try{
DiscoveryClient<String> client = client();
List<String> 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{
String elem = appProfile.get(0); String elem = appProfile.get(0);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = docBuilder.parse(new InputSource(new StringReader(elem))); document = docBuilder.parse(new InputSource(new StringReader(elem)));
@ -110,21 +106,13 @@ public class ApplicationProfileReaderForCatalogueResolver {
logger.info("For scope: "+scopeFound+", found VRE_NAME "+vreName); logger.info("For scope: "+scopeFound+", found VRE_NAME "+vreName);
hashVreNameScope.put(vreName.get(0), scopeFound); hashVreNameScope.put(vreName.get(0), scopeFound);
} }
}catch(Exception e){ }catch(Exception e){
throw new ApplicationProfileNotFoundException("Error during parsing application profile with resource name: "+resourceName + " in the scope: "+scope.toString()); throw new ApplicationProfileNotFoundException("Error during parsing application profile with resource name: "+resourceName + " in the scope: "+scope.toString());
} }
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", 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");
}
} }
} }

View File

@ -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();
}
}

View File

@ -2,7 +2,6 @@ package org.gcube.datatransfer.resolver.services;
import java.net.URL; import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -17,65 +16,32 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.Constants;
import org.gcube.datatransfer.resolver.ResourceCatalogueCodes; import org.gcube.datatransfer.resolver.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest; 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.ApplicationProfileReaderForCatalogueResolver;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader; import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference; import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
import org.gcube.datatransfer.resolver.catalogue.resource.UpdateApplicationProfileCatalogueResolver; import org.gcube.datatransfer.resolver.catalogue.resource.UpdateApplicationProfileCatalogueResolver;
import org.gcube.datatransfer.resolver.scope.ScopeUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.model.CkanDataset; import eu.trentorise.opendata.jackan.model.CkanDataset;
@Path(Constants.SERVLET_CATALOGUE) @Path("/")
public class Catalogue { public class Catalogue {
private static Logger logger = LoggerFactory.getLogger(Catalogue.class); private static Logger logger = LoggerFactory.getLogger(Catalogue.class);
private ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
public static final String ENV_SCOPE = "SCOPE"; //Environment Variable public static final String ENV_SCOPE = "SCOPE"; //Environment Variable
/** The scope to enc decr. */ /** The scope to enc decr. */
private String scopeToEncDecr = null; private String scopeToEncDecr = null;
ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
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;
}
@GET @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) { public Response resolveCatalogue(@PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) {
try { try {
@ -118,7 +84,7 @@ public class Catalogue {
} }
@POST @POST
@Path("") @Path("catalogue")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) { public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) {

View File

@ -2,9 +2,9 @@ package org.gcube.datatransfer.resolver.services;
import java.io.InputStream; import java.io.InputStream;
import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.ResponseBuilder;
@ -19,14 +19,15 @@ import org.gcube.datatransfer.resolver.SingleFileStreamingOutput;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@Path("") @Path("/")
public class StorageManager { public class StorageManager {
private static Logger logger = LoggerFactory.getLogger(StorageManager.class); private static Logger logger = LoggerFactory.getLogger(StorageManager.class);
@GET
@Path("{smpId}") @Path("{smpId}")
@Produces()
public Response getFile(@PathParam("smpId") String smpId) { public Response getFile(@PathParam("smpId") String smpId) {
logger.info("resolve Storage Id called");
StorageClient client = new StorageClient("DataTransfer", "UriResolver", "storageid-resolver", AccessType.PUBLIC); StorageClient client = new StorageClient("DataTransfer", "UriResolver", "storageid-resolver", AccessType.PUBLIC);
IClient iClient = client.getClient(); IClient iClient = client.getClient();
String toSEID = iClient.getId(smpId); //to Storage Encrypted ID String toSEID = iClient.getId(smpId); //to Storage Encrypted ID
@ -50,7 +51,8 @@ public class StorageManager {
}catch (Exception e) { }catch (Exception e) {
logger.warn("Error when getting file metadata from storage, printing this warning and trying to continue..", 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 InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream

View File

@ -3,5 +3,5 @@
<group>DataTransfer</group> <group>DataTransfer</group>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<description>Storage Hub webapp</description> <description>Storage Hub webapp</description>
<local-persistence location='target' /> <exclude handlers='request-validation context-retriever'>/*</exclude>
</application> </application>

View File

@ -1,87 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app> <web-app>
<!-- <context-param>
<display-name>http resolver</display-name> <param-name>root-app-token</param-name>
<param-value>e22a46ac-418c-49f2-ad3f-99a5b9689825-98187548</param-value>
<filter> </context-param>
<filter-name>uriResolverRewriteFilter</filter-name> <context-param>
<filter-class>org.gcube.datatransfer.resolver.UriResolverRewriteFilter</filter-class> <param-name>root-scope</param-name>
</filter> <param-value>/gcube</param-value>
</context-param>
<filter-mapping> root-scope
<filter-name>uriResolverRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>smp</servlet-name>
<display-name>smp</display-name>
<servlet-class>org.gcube.datatransfer.resolver.http.HttpResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>catalogue</servlet-name>
<display-name>catalogue</display-name>
<servlet-class>org.gcube.datatransfer.resolver.catalogue.CatalogueResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>id</servlet-name>
<display-name>id</display-name>
<servlet-class>org.gcube.datatransfer.resolver.http.StorageIDResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>gisResolver</servlet-name>
<display-name>gisResolver</display-name>
<servlet-class>org.gcube.datatransfer.resolver.gis.GisResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>geonetwork</servlet-name>
<display-name>geonetwork</display-name>
<servlet-class>org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>smp</servlet-name>
<url-pattern>/smp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>gisResolver</servlet-name>
<url-pattern>/gis</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalogue</servlet-name>
<url-pattern>/catalogue</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>id</servlet-name>
<url-pattern>/id</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>geonetwork</servlet-name>
<url-pattern>/geonetwork</url-pattern>
</servlet-mapping> -->
<servlet> <servlet>
<servlet-name>org.gcube.data.access.storagehub.StorageHub</servlet-name> <servlet-name>org.gcube.datatransfer.resolver.UriResolver</servlet-name>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>org.gcube.data.access.storagehub.StorageHub</servlet-name> <servlet-name>org.gcube.datatransfer.resolver.UriResolver</servlet-name>
<url-pattern>/workspace/*</url-pattern> <url-pattern>/*</url-pattern>
</servlet-mapping> </servlet-mapping>
</web-app> </web-app>