This commit is contained in:
Francesco Mangiacrapa 2019-02-19 14:18:19 +00:00
parent a0bcb8321a
commit 528eae3d5e
23 changed files with 619 additions and 113 deletions

34
pom.xml
View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>uri-resolver</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications. </description>
@ -103,7 +103,6 @@
<artifactId>discovery-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
@ -115,34 +114,25 @@
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<!-- jersey -->
<!-- <dependency> -->
<!-- <groupId>org.glassfish.jersey.ext</groupId> -->
<!-- <artifactId>jersey-mvc-jsp</artifactId> -->
<!-- <version>2.13</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>javax.ws.rs</groupId> -->
<!-- <artifactId>javax.ws.rs-api</artifactId> -->
<!-- <version>2.0</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.24.1</version>
<version>${jersey.version}</version>
<scope>compile</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.glassfish.jersey.containers.glassfish</groupId> -->
<!-- <artifactId>jersey-gf-cdi</artifactId> -->
<!-- <version>2.14</version> -->
<!-- </dependency> -->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
<scope>compile</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.sun.jersey</groupId> -->
<!-- <artifactId>jersey-server</artifactId> -->
<!-- <version>1.19.4</version> -->
<!-- </dependency> -->
<!-- weld -->
<dependency>

View File

@ -4,6 +4,7 @@
package org.gcube.datatransfer.resolver;
/**
* The Class ConstantsResolver.
*
@ -24,4 +25,20 @@ public class ConstantsResolver {
public static final String QUERY_PARAM_CONTENT_TYPE = "contentType";
public static final String QUERY_PARAM_FILE_NAME = "fileName";
/*static {
Map<String, String> aMap = new HashMap<String, String>();
aMap.put("smp", "smp");
aMap.put("id", "id");
aMap.put("gis", "gis");
aMap.put("storage", "storage");
aMap.put("ctlg", "ctlg");
aMap.put("catalogue", "catalogue");
aMap.put("geonetwork", "geonetwork");
aMap.put("shub", "shub");
aMap.put("parthenos_registry", "parthenos_registry");
aMap.put("knime", "knime");
aMap = Collections.unmodifiableMap(aMap);
}*/
}

View File

@ -0,0 +1,181 @@
/**
*
*/
package org.gcube.datatransfer.resolver;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
/**
* The Class MultiReadHttpServletRequest.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Apr 26, 2016
*/
public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
private ByteArrayOutputStream cachedBytes;
private final Map<String, String[]> modifiableParameters;
private Map<String, String[]> allParameters = null;
/**
* Instantiates a new multi read http servlet request.
*
* @param request the request
*/
public MultiReadHttpServletRequest(HttpServletRequest request) {
super(request);
modifiableParameters = new TreeMap<String, String[]>();
}
/**
* Create a new request wrapper that will merge additional parameters into
* the request object without prematurely reading parameters from the
* original request.
*
* @param request
* the request
* @param additionalParams
* the additional params
*/
public MultiReadHttpServletRequest(
final HttpServletRequest request,
final Map<String, String[]> additionalParams) {
super(request);
modifiableParameters = new TreeMap<String, String[]>();
modifiableParameters.putAll(additionalParams);
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getInputStream()
*/
@Override
public ServletInputStream getInputStream() throws IOException {
if (cachedBytes == null)
cacheInputStream();
return new CachedServletInputStream();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getReader()
*/
@Override
public BufferedReader getReader() throws IOException {
return new BufferedReader(new InputStreamReader(getInputStream()));
}
/**
* Cache input stream.
*
* @throws IOException Signals that an I/O exception has occurred.
*/
private void cacheInputStream()
throws IOException {
/*
* Cache the inputstream in order to read it multiple times. For
* convenience, I use apache.commons IOUtils
*/
cachedBytes = new ByteArrayOutputStream();
IOUtils.copy(super.getInputStream(), cachedBytes);
}
/* An inputstream which reads the cached request body */
/**
* The Class CachedServletInputStream.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Apr 26, 2016
*/
public class CachedServletInputStream extends ServletInputStream {
private ByteArrayInputStream input;
/**
* Instantiates a new cached servlet input stream.
*/
public CachedServletInputStream() {
/* create a new input stream from the cached request body */
input = new ByteArrayInputStream(cachedBytes.toByteArray());
}
/* (non-Javadoc)
* @see java.io.InputStream#read()
*/
@Override
public int read() throws IOException {
return input.read();
}
}
/*
* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameter(java.lang.String)
*/
@Override
public String getParameter(final String name) {
String[] strings = getParameterMap().get(name);
if (strings != null) {
return strings[0];
}
return super.getParameter(name);
}
/*
* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameterMap()
*/
@Override
public Map<String, String[]> getParameterMap() {
if (allParameters == null) {
allParameters = new TreeMap<String, String[]>();
allParameters.putAll(super.getParameterMap());
allParameters.putAll(modifiableParameters);
}
// Return an unmodifiable collection because we need to uphold the
// interface contract.
return Collections.unmodifiableMap(allParameters);
}
/*
* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameterNames()
*/
@Override
public Enumeration<String> getParameterNames() {
return Collections.enumeration(getParameterMap().keySet());
}
/*
* (non-Javadoc)
* @see
* javax.servlet.ServletRequestWrapper#getParameterValues(java.lang.String)
*/
@Override
public String[] getParameterValues(final String name) {
return getParameterMap().get(name);
}
}

View File

@ -1,5 +1,7 @@
package org.gcube.datatransfer.resolver;
import java.util.List;
import javax.ws.rs.Path;
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
@ -13,11 +15,12 @@ import org.glassfish.jersey.server.ResourceConfig;
@ManagedBy(UriResolverSmartGearManagerInit.class)
public class UriResolver extends ResourceConfig {
private static List<String> listOfResources;
public UriResolver() {
// Register all resources present under the package.
packages(CatalogueResolver.class.getPackage().getName(), TokenSetter.class.getPackage().getName());
packages(DataMinerInvocation.class.getPackage().getName());
}
}

View File

@ -0,0 +1,213 @@
/**
*
*/
package org.gcube.datatransfer.resolver;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.ws.rs.Path;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.server.model.ResourceMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* The Class UriResolverServices.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Feb 19, 2019
*/
public class UriResolverServices {
private static Logger log = LoggerFactory.getLogger(UriResolverServices.class);
private ObjectNode rootResources = null;
private ArrayNode arrayResources = null;
private List<String> listResourcePath = new ArrayList<String>();
private static UriResolverServices INSTANCE;
/**
* Instantiates a new uri resolver services.
*/
private UriResolverServices() {
}
/**
* Gets the single instance of UriResolverServices.
*
* @return single instance of UriResolverServices
*/
public static UriResolverServices getInstance() {
if (INSTANCE == null) {
// synchronized block to remove overhead
synchronized (UriResolverServices.class) {
if (INSTANCE == null) {
// if instance is null, initialize
INSTANCE = new UriResolverServices();
}
}
}
return INSTANCE;
}
/**
* Read resources.
*
* @param applicationClasses the application classes
* @return the list
*/
private List<String> readResources(Set<Class<?>> applicationClasses){
log.info("Read Resources called");
String basePath = "";
rootResources = JsonNodeFactory.instance.objectNode();
arrayResources = JsonNodeFactory.instance.arrayNode();
rootResources.set("resources", arrayResources);
log.info("Checking basePath: {}",basePath);
for (Class<?> aClass : applicationClasses) {
if (isAnnotatedResourceClass(aClass)) {
Resource resource = Resource.builder(aClass).build();
//String uriPrefix = resource.getPath();
log.info("The resource: {} isAnnotatedResource",resource.getNames());
process(basePath, resource);
}
}
if(log.isDebugEnabled()){
for (String path : listResourcePath) {
log.debug("Found path: {}", path);
}
}
return listResourcePath;
}
/**
* Process.
*
* @param uriPrefix the uri prefix
* @param resource the resource
* @return the list
*/
private void process(String uriPrefix, Resource resource) {
String pathPrefix = uriPrefix;
List<Resource> resources = new ArrayList<>();
resources.addAll(resource.getChildResources());
if (resource.getPath() != null) {
pathPrefix+= resource.getPath();
}
for (ResourceMethod method : resource.getAllMethods()) {
if (method.getType().equals(ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR)) {
resources.add(Resource.from(resource.getResourceLocator().getInvocable().getDefinitionMethod().getReturnType()));
}
else {
addTo(uriPrefix, method, pathPrefix);
log.info("Adding path: {} to ListPrefix",pathPrefix);
listResourcePath.add(pathPrefix);
}
}
for (Resource childResource : resources) {
log.debug("SUB RESOURCES adding: {} with path: {}"+childResource.getName(), childResource.getPath());
process(pathPrefix, childResource);
}
}
/**
* Adds the to.
*
* @param uriPrefix the uri prefix
* @param srm the srm
* @param pathPrefix the path prefix
*/
private void addTo(String uriPrefix, ResourceMethod srm, String pathPrefix){
ObjectNode resourceNode = (ObjectNode) arrayResources.get(uriPrefix);
log.debug("The Resource Node with uriPrefix: {} is null: {}", uriPrefix, resourceNode==null);
if (resourceNode == null){
//THE RESOURCE NODE DOES NOT EXIST CREATING IT...
ObjectNode theNode = JsonNodeFactory.instance.objectNode();
ObjectNode inner = JsonNodeFactory.instance.objectNode();
inner.put("path", pathPrefix);
inner.set("verbs", JsonNodeFactory.instance.arrayNode());
theNode.set(uriPrefix, inner);
resourceNode = inner;
//ADDING THE RESOURCE NODE CREATED TO THE LIST OF RESOURCES
arrayResources.add(theNode);
}
//THE RESOURCE ALREADY ADDED SO ADDING ONLY VERB TO IT
((ArrayNode) resourceNode.get("verbs")).add(srm.getHttpMethod());
}
/**
* Checks if is annotated resource class.
*
* @param rc the rc
* @return true, if is annotated resource class
*/
@SuppressWarnings({
"rawtypes", "unchecked"
})
private static boolean isAnnotatedResourceClass(Class rc) {
if (rc.isAnnotationPresent(Path.class)) {
return true;
}
for (Class i : rc.getInterfaces()) {
if (i.isAnnotationPresent(Path.class)) {
return true;
}
}
return false;
}
/**
* Gets the list of resource path.
*
* @param applicationClasses the application classes
* @return the list of resource path
*/
public List<String> getListOfResourcePath(Set<Class<?>> applicationClasses) {
log.trace("The Application Classes are {}", applicationClasses);
if(listResourcePath.isEmpty()){
readResources(applicationClasses);
}
return listResourcePath;
}
/**
* Gets the list of resource node.
*
* @param applicationClasses the application classes
* @return the list of resource node
*/
public ObjectNode getListOfResourceNode(Set<Class<?>> applicationClasses) {
if(rootResources==null){
readResources(applicationClasses);
}
return rootResources;
}
}

View File

@ -51,7 +51,6 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
private static ApplicationProfilePropertyReader geoExplorerProfile;
private static String parthenosVREName;
/* (non-Javadoc)
* @see org.gcube.smartgears.ApplicationManager#onInit()
*/
@ -226,6 +225,4 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
return rootContextScope;
}
}

View File

@ -1,21 +1,35 @@
package org.gcube.datatransfer.resolver.requesthandler;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
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.container.ResourceContext;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.Provider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.MultiReadHttpServletRequest;
import org.gcube.datatransfer.resolver.UriResolverServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class TokenSetter.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Feb 19, 2019
*/
@Provider
public class TokenSetter implements ContainerRequestFilter, ContainerResponseFilter {
@ -27,8 +41,20 @@ public class TokenSetter implements ContainerRequestFilter, ContainerResponseFil
@Context ServletContext context;
@Context
HttpServletRequest webRequest;
@Context
Application application;
@Context
ResourceContext resourceContext;
/* (non-Javadoc)
* @see javax.ws.rs.container.ContainerRequestFilter#filter(javax.ws.rs.container.ContainerRequestContext)
*/
@Override
public void filter(ContainerRequestContext ctx) throws IOException {
public void filter(ContainerRequestContext reqContext) throws IOException {
log.info("TokenSetter Request called");
if(SecurityTokenProvider.instance.get()==null)
@ -36,8 +62,28 @@ public class TokenSetter implements ContainerRequestFilter, ContainerResponseFil
if(ScopeProvider.instance.get()==null)
ScopeProvider.instance.set(context.getInitParameter(ROOT_SCOPE));
MultiReadHttpServletRequest multiReadRequest = new MultiReadHttpServletRequest(webRequest);
String requestURI = multiReadRequest.getRequestURI();
String queryString = multiReadRequest.getQueryString();
log.debug("Request URI: " + requestURI + ", QueryString: " +queryString+ ", Path Info: "+multiReadRequest.getPathInfo());
List<String> listOfPath = UriResolverServices.getInstance().getListOfResourcePath(application.getClasses());
log.info("The resources are: {}", listOfPath);
UriInfo uriInfo = reqContext.getUriInfo();
String prefix = "/redirect";
String path = uriInfo.getRequestUri().getPath();
log.info("The path is: {}", path);
if(requestURI.startsWith("qqqqq")){
URI newRequestURI = uriInfo.getBaseUriBuilder().path("new").build();
reqContext.setRequestUri(newRequestURI);
}
}
/* (non-Javadoc)
* @see javax.ws.rs.container.ContainerResponseFilter#filter(javax.ws.rs.container.ContainerRequestContext, javax.ws.rs.container.ContainerResponseContext)
*/
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {

View File

@ -62,7 +62,7 @@ import org.xml.sax.SAXException;
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 12, 2018
*/
@Path("/analytics")
@Path("analytics")
public class AnalyticsCreateResolver {
/**

View File

@ -29,7 +29,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 13, 2018
*/
@Path("/analytics")
@Path("analytics")
public class AnalyticsGetResolver {
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);

View File

@ -0,0 +1,39 @@
package org.gcube.datatransfer.resolver.services;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class CatalogueResolver.
*
* To Backward compatibility
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 16, 2018
*/
@Path("catalogue")
public class BackCatalogueResolver {
private static Logger logger = LoggerFactory.getLogger(BackCatalogueResolver.class);
@POST
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) throws WebApplicationException{
logger.info(this.getClass().getSimpleName()+" POST starts...");
return new CatalogueResolver().postCatalogue(req, jsonRequest);
}
}

View File

@ -39,7 +39,7 @@ import eu.trentorise.opendata.jackan.model.CkanDataset;
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 16, 2018
*/
@Path("/")
@Path("{entityContext:ctlg(-(o|g|p|d))?}")
public class CatalogueResolver {
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
@ -55,7 +55,7 @@ public class CatalogueResolver {
* @return the response
*/
@GET
@Path("{entityContext:ctlg(-(o|g|p|d))?}/{vreName}/{entityName}")
@Path("/{vreName}/{entityName}")
public Response resolveCatalogue(@Context HttpServletRequest req,
@PathParam("entityName") String entityName,
@PathParam("vreName") String vreName,
@ -101,7 +101,7 @@ public class CatalogueResolver {
* @return the response
*/
@POST
@Path("catalogue")
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) throws WebApplicationException{

View File

@ -111,7 +111,7 @@ public class GeonetworkResolver {
*/
@GET
@Path("{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
@Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
public Response submitGet(@Context HttpServletRequest req,
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode,
@ -229,7 +229,7 @@ public class GeonetworkResolver {
}
@POST
@Path("{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
@Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
public Response submitPost(@Context HttpServletRequest req,
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode,

View File

@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Dec 13, 2018
*/
@Path("/knime")
@Path("knime")
public class KnimeCreateResolver {
private static Logger logger = LoggerFactory.getLogger(KnimeCreateResolver.class);

View File

@ -29,7 +29,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Dec 13, 2018
*/
@Path("/knime")
@Path("knime")
public class KnimeGetResolver {
private static Logger logger = LoggerFactory.getLogger(KnimeGetResolver.class);

View File

@ -107,7 +107,7 @@ public class PartheosRegistryResolver {
* @throws Exception the exception
*/
@POST
@Path("/")
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest) throws WebApplicationException{

View File

@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 22, 2018
*/
@Path("/")
@Path("id")
public class SMPIDResolver {
/**
@ -48,7 +48,7 @@ public class SMPIDResolver {
* @throws WebApplicationException the web application exception
*/
@GET
@Path("id")
@Path("")
public Response getSMPID(@Context HttpServletRequest req,
@QueryParam(SMP_ID) @Nullable String smpId,
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,

View File

@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018
*/
@Path("/")
@Path("smp")
public class SMPResolver {
/**
@ -48,7 +48,7 @@ public class SMPResolver {
* @throws WebApplicationException the web application exception
*/
@GET
@Path("smp")
@Path("")
public Response getSMPURI(@Context HttpServletRequest req,
@QueryParam(SMP_URI) @Nullable
String smpURI,

View File

@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018
*/
@Path("shub/{id}")
@Path("shub")
public class StorageHubResolver {
/**
@ -50,7 +50,7 @@ public class StorageHubResolver {
* @return the metadata
*/
@HEAD
@Path("")
@Path("/{id}")
public Response getMetadata(@Context HttpServletRequest req) {
logger.info(this.getClass().getSimpleName()+" HEAD getMetadata called");
@ -98,7 +98,7 @@ public class StorageHubResolver {
* @return the response
*/
@GET
@Path("")
@Path("/{id}")
public Response download(@Context HttpServletRequest req) {
logger.info(this.getClass().getSimpleName()+" GET download called");
@ -138,60 +138,4 @@ public class StorageHubResolver {
throw (WebApplicationException) e;
}
}
/**
* Download version. NEVER USED
*
* @param req the req
* @param version the version
* @return the response
*/
/*@GET
@Path("{version}")
public Response downloadVersion(@Context HttpServletRequest req, @PathParam("version") String version) {
logger.info(this.getClass().getSimpleName() +" GET downloadVersion called");
try{
InnerMethodName.instance.set("resolveStorageHubPublicLinkWithVersion");
ItemManagerClient client = AbstractPlugin.item().build();
//Checking mandatory parameter id
if(id==null || id.isEmpty()){
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolver.class, help);
}
//Checking mandatory parameter id
if(version==null || version.isEmpty()){
logger.error("Parameter 'version' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter 'version'", StorageHubResolver.class, help);
}
try{
String identifier = String.format("%s%s%s",id, versionPrefix, version);
StreamDescriptor descriptor = client.resolvePublicLink(identifier);
ResponseBuilder response = Response.ok(descriptor.getStream());
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id);
//Adding ETag to version requested
response.header("ETag", version);
return response.build();
}catch(Exception e){
String errorMsg = "Error on getting versioned file with hub id '"+id+ "' and version '"+version+"'";
logger.error(errorMsg, e);
throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolver.class, help);
}
}catch (Exception e) {
if(!(e instanceof WebApplicationException)){
//UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the StorageHub URL with id: "+id+" and version: "+version+". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
}
//ALREADY MANAGED as WebApplicationException
logger.error("Exception:", e);
throw (WebApplicationException) e;
}
}*/
}

View File

@ -62,7 +62,7 @@ public class StorageIDResolver {
* @throws WebApplicationException the web application exception
*/
@GET
@Path("{storage-id}")
@Path("/{storage-id}")
public Response getStorageId(@Context HttpServletRequest req,
@PathParam(STORAGE_ID) String storageId,
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
@ -183,7 +183,7 @@ public class StorageIDResolver {
* @throws WebApplicationException the web application exception
*/
@HEAD
@Path("{storage-id}")
@Path("/{storage-id}")
public Response httpDoHead(@Context HttpServletRequest req,
@PathParam(STORAGE_ID) String storageId,
@QueryParam(ConstantsResolver.HPC) Boolean hproxycheck) throws WebApplicationException {

View File

@ -24,14 +24,14 @@ import org.slf4j.LoggerFactory;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 22, 2018
*/
@Path("/")
@Path("index")
public class UriResolverIndex {
private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class);
@GET
@Produces({MediaType.TEXT_HTML})
@Path("index")
@Path("")
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
String indexFile = "/WEB-INF/jsp/index.jsp";
@ -52,12 +52,5 @@ public class UriResolverIndex {
throw (WebApplicationException) e;
}
}
@GET
@Produces({MediaType.TEXT_HTML})
@Path("info")
public InputStream info(@Context HttpServletRequest req){
return index(req);
}
}

View File

@ -0,0 +1,31 @@
/**
*
*/
package org.gcube.datatransfer.resolver.services;
import java.io.InputStream;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 22, 2018
*/
@Path("info")
public class UriResolverInfo {
@GET
@Produces({MediaType.TEXT_HTML})
@Path("")
public InputStream info(@Context HttpServletRequest req) throws WebApplicationException{
return new UriResolverIndex().index(req);
}
}

View File

@ -0,0 +1,52 @@
/**
*
*/
package org.gcube.datatransfer.resolver.services;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gcube.datatransfer.resolver.UriResolverServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* The Class ResourceListingResource.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Feb 14, 2019
*/
@Path("resources")
@Singleton
public class UriResolverResources {
private static Logger log = LoggerFactory.getLogger(UriResolverResources.class);
/**
* Show all.
*
* @param application the application
* @param request the request
* @return the response
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getServices(@Context Application application, @Context HttpServletRequest request) {
log.info("Get Services called");
ObjectNode rootResources = UriResolverServices.getInstance().getListOfResourceNode(application.getClasses());
return Response.ok().entity(rootResources).build();
}
}

View File

@ -217,9 +217,9 @@ public class TestResolvers {
String entityName = "sarda-sarda";
//String entityContext = "product";
String entityContext = "dataset";
String scope = "/gcube/devNext/NextNext";
String scope = "/gcube/devsec/devVRE";
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,"catalogue");
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,"ctlg");
logger.info("POST Request to URL: "+url);
try {