diff --git a/pom.xml b/pom.xml index 3b11a87..5626931 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.gcube.data.transfer uri-resolver - 2.0.0-SNAPSHOT + 2.1.0-SNAPSHOT war 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. @@ -103,7 +103,6 @@ discovery-client - org.gcube.common authorization-client @@ -115,34 +114,25 @@ [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) - - - - - - - - - - - org.glassfish.jersey.containers jersey-container-servlet - 2.24.1 + ${jersey.version} + compile - - - - - - javax.transaction - javax.transaction-api - 1.2 + org.glassfish.jersey.core + jersey-server + ${jersey.version} + compile + + + + + diff --git a/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java b/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java index 597690d..b8f7be5 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java @@ -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 aMap = new HashMap(); + 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); + }*/ + } diff --git a/src/main/java/org/gcube/datatransfer/resolver/MultiReadHttpServletRequest.java b/src/main/java/org/gcube/datatransfer/resolver/MultiReadHttpServletRequest.java new file mode 100644 index 0000000..1eb0a2a --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/MultiReadHttpServletRequest.java @@ -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 modifiableParameters; + private Map allParameters = null; + + /** + * Instantiates a new multi read http servlet request. + * + * @param request the request + */ + public MultiReadHttpServletRequest(HttpServletRequest request) { + super(request); + modifiableParameters = new TreeMap(); + } + + /** + * 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 additionalParams) { + + super(request); + modifiableParameters = new TreeMap(); + 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 getParameterMap() { + + if (allParameters == null) { + allParameters = new TreeMap(); + 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 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); + } +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java index 209e3ac..c90e4ba 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java @@ -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 listOfResources; + public UriResolver() { // Register all resources present under the package. packages(CatalogueResolver.class.getPackage().getName(), TokenSetter.class.getPackage().getName()); packages(DataMinerInvocation.class.getPackage().getName()); - } } diff --git a/src/main/java/org/gcube/datatransfer/resolver/UriResolverServices.java b/src/main/java/org/gcube/datatransfer/resolver/UriResolverServices.java new file mode 100644 index 0000000..9a29f88 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/UriResolverServices.java @@ -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 listResourcePath = new ArrayList(); + + 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 readResources(Set> 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 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 getListOfResourcePath(Set> 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> applicationClasses) { + + if(rootResources==null){ + readResources(applicationClasses); + } + + return rootResources; + } +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java index 074ae25..76a64b8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java +++ b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java @@ -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; } - - } diff --git a/src/main/java/org/gcube/datatransfer/resolver/requesthandler/TokenSetter.java b/src/main/java/org/gcube/datatransfer/resolver/requesthandler/TokenSetter.java index 8526590..d654a27 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/requesthandler/TokenSetter.java +++ b/src/main/java/org/gcube/datatransfer/resolver/requesthandler/TokenSetter.java @@ -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 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 { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java index 11cd807..199c113 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java @@ -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 { /** diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java index 5220ea3..abe473d 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java @@ -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); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/BackCatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/BackCatalogueResolver.java new file mode 100644 index 0000000..a02e08a --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/services/BackCatalogueResolver.java @@ -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); + + } +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java index 167859a..6847401 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -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{ diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java index d177d31..d99589f 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java @@ -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, diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java index 8fca4f2..6d21ae4 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java @@ -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); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java index b2886d4..0cf42f8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java @@ -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); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java index 909ece1..96d0dda 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java @@ -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{ diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java index 9ec8dca..60fa8e5 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java @@ -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, diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java index 045f6c5..2a36a64 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java @@ -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, diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java index c71206d..ca0453d 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java @@ -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; - } - }*/ } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index 6bccdb0..71cfcd8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -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 { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverIndex.java b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverIndex.java index 44cc1c5..b5835e2 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverIndex.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverIndex.java @@ -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); - } } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverInfo.java b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverInfo.java new file mode 100644 index 0000000..4ec9625 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverInfo.java @@ -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); + } +} + diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverResources.java b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverResources.java new file mode 100644 index 0000000..cab6298 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverResources.java @@ -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(); + } + +} diff --git a/src/test/java/rest/TestResolvers.java b/src/test/java/rest/TestResolvers.java index 0a03b13..baf0ea1 100644 --- a/src/test/java/rest/TestResolvers.java +++ b/src/test/java/rest/TestResolvers.java @@ -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 {