diff --git a/pom.xml b/pom.xml index b86f958..85a468f 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 2.24.1 + 2.25.1 1.8 1.8 2.14.0 @@ -137,7 +137,12 @@ ${jersey.version} compile - + + org.glassfish.jersey.ext + jersey-mvc-jsp + ${jersey.version} + compile + org.glassfish.jersey.core jersey-server diff --git a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java index 8cc867c..9f30229 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java @@ -9,6 +9,7 @@ import org.gcube.datatransfer.resolver.services.CatalogueResolver; import org.gcube.datatransfer.resolver.services.tobackward.BackCatalogueResolver; import org.gcube.smartgears.annotations.ManagedBy; import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.server.mvc.jsp.JspMvcFeature; @Path("uri-resolver") @ManagedBy(UriResolverSmartGearManagerInit.class) @@ -18,6 +19,8 @@ public class UriResolver extends ResourceConfig { // Register all resources present under the package. packages(CatalogueResolver.class.getPackage().getName(), RequestHandler.class.getPackage().getName(), BackCatalogueResolver.class.getPackage().getName()); packages(DataMinerInvocation.class.getPackage().getName()); + register(JspMvcFeature.class); + property(JspMvcFeature.TEMPLATE_BASE_PATH, "/WEB-INF/jsp"); } } diff --git a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverServletContextListener.java b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverServletContextListener.java index 5e41b19..8318d5f 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverServletContextListener.java +++ b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverServletContextListener.java @@ -35,7 +35,7 @@ public class UriResolverServletContextListener implements ServletContextListener public void contextInitialized(ServletContextEvent event) { servletContext = event.getServletContext(); - log.info("Context Initialized at context path: "+servletContext.getContextPath()); + log.info("Context Initialized at context path: "+servletContext.getContext("/")); } @Override diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/DocsGenerator.java b/src/main/java/org/gcube/datatransfer/resolver/services/DocsGenerator.java index d782da0..7df567e 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/DocsGenerator.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/DocsGenerator.java @@ -14,6 +14,7 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; +import org.glassfish.jersey.server.mvc.Viewable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +39,7 @@ public class DocsGenerator { */ @GET @Path("/{any: .*}") - public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException { + public Viewable toDoc(@Context HttpServletRequest req) throws WebApplicationException { logger.info(DocsGenerator.class.getSimpleName() + " toDoc called"); String pathInfo = req.getPathInfo(); @@ -51,8 +52,10 @@ public class DocsGenerator { logger.info("going to {}", pathInfo); - String realPath = req.getServletContext().getRealPath(pathInfo); - return new FileInputStream(new File(realPath)); + //String realPath = req.getServletContext().getRealPath(pathInfo); + //return new FileInputStream(new File(realPath)); + + return new Viewable(pathInfo); } catch (Exception e) { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java index 81abda1..f0ff0d7 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalExporter.java @@ -29,6 +29,7 @@ import org.gcube.datatransfer.resolver.ConstantsResolver; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException; import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput; +import org.glassfish.jersey.server.mvc.Viewable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -131,6 +132,68 @@ public class GeoportalExporter { } + /** + * Resolve geoportal no app def. + * + * @param req the req + * @param vreName the vre name + * @param exportType the export type + * @param ucdID the ucd ID + * @param projectID the project ID + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path("/export/{type}/view/{usecase_id}/{project_id}") + @Produces({ MediaType.TEXT_HTML }) + public Viewable exportView(@Context HttpServletRequest req, @PathParam(EXPORT_TYPE) String export_type, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID) + throws WebApplicationException { + + String userAgentName = req.getHeader("User-Agent"); + + LOG.info(this.getClass().getSimpleName() + " export view - GET starts..."); + LOG.debug("params are: exportType: {}, ucdID: {}, projectID: {}", export_type, ucdID, projectID); + + checkPathParameterNotNull(req, EXPORT_TYPE, export_type); + checkPathParameterNotNull(req, PATH_USECASE_ID, ucdID); + checkPathParameterNotNull(req, PATH_PROJECT_ID, projectID); + + checkExportType(req, export_type); + + try { + + SecretManager cm = SecretManagerProvider.instance.get(); + String context = cm.getContext(); + if (context == null) { + throw ExceptionManager.forbiddenException(req, "Cannot determine context (the scope)", this.getClass(), + helpURI); + } + org.gcube.common.authorization.utils.user.User user = cm.getUser(); + LOG.info("Identified caller {} in context {}", user.getUsername(), context); + + Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter(); + boolean checked = pdfExporter.checkConfig(); + + if (checked) { + LOG.info("Serving request as User-Agent {}", userAgentName); + //String entity = entityHTMLMessage("Exporting as PDF...", "The project with " + projectID, true); +// return Response.ok(entity).encoding("UTF-8").header(ConstantsResolver.CONTENT_TYPE, "text/html") +// .build(); + return new Viewable("/geoportal_exporter"); + } else { + throw ExceptionManager.notFoundException(req, this.getClass().getSimpleName()+ " not found in the context: "+context, + this.getClass(), helpURI); + } + + } catch (Exception e) { + LOG.error("Error on performing export", e); + throw ExceptionManager.internalErrorException(req, "Sorry, error occurred when exporting the project", + this.getClass(), helpURI); + } + + } + @GET @Path("/export/{type}/healthcheck") @Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN }) 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 286bf1a..fcf88f4 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverIndex.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverIndex.java @@ -16,6 +16,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; +import org.glassfish.jersey.server.mvc.Viewable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,6 +31,8 @@ import org.slf4j.LoggerFactory; public class UriResolverIndex { private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class); + + private String indexFile = "/index"; /** * Index. @@ -41,14 +44,15 @@ public class UriResolverIndex { @GET @Produces({ MediaType.TEXT_HTML }) @Path("") - public InputStream index(@Context HttpServletRequest req) throws WebApplicationException { + public Viewable index(@Context HttpServletRequest req) throws WebApplicationException { - String indexFile = "/WEB-INF/jsp/index.jsp"; + //String indexFile = "/WEB-INF/jsp/index.jsp"; try { logger.info(UriResolverIndex.class.getSimpleName() + " called"); - String realPath = req.getServletContext().getRealPath(indexFile); - return new FileInputStream(new File(realPath)); + //String realPath = req.getServletContext().getRealPath(indexFile); + return new Viewable(indexFile); + //return new FileInputStream(new File(realPath)); } catch (Exception e) { if (!(e instanceof WebApplicationException)) { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverInfo.java b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverInfo.java index d63639a..7c48d01 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverInfo.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverInfo.java @@ -13,6 +13,8 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import org.glassfish.jersey.server.mvc.Viewable; + /** * The UriResolverInfo get index. * @@ -33,7 +35,7 @@ public class UriResolverInfo { @GET @Produces({ MediaType.TEXT_HTML }) @Path("") - public InputStream info(@Context HttpServletRequest req) throws WebApplicationException { + public Viewable info(@Context HttpServletRequest req) throws WebApplicationException { return new UriResolverIndex().index(req); } } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java index 92dae4b..66996f1 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java @@ -32,6 +32,7 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.exceptions.NotFoundException; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.glassfish.jersey.server.mvc.Viewable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -190,14 +191,15 @@ public class WekeoResolver { @GET @Produces({ MediaType.TEXT_HTML }) @Path("") - public InputStream index(@Context HttpServletRequest req) throws WebApplicationException { + public Viewable index(@Context HttpServletRequest req) throws WebApplicationException { String indexFile = "/WEB-INF/jsp/wekeo.jsp"; try { - logger.info(this.getClass().getSimpleName() + " index called"); - String realPath = req.getServletContext().getRealPath(indexFile); - return new FileInputStream(new File(realPath)); +// logger.info(this.getClass().getSimpleName() + " index called"); +// String realPath = req.getServletContext().getRealPath(indexFile); +// return new FileInputStream("/wekeo"); + return new Viewable(indexFile); } catch (Exception e) { if (!(e instanceof WebApplicationException)) { diff --git a/src/main/webapp/WEB-INF/jsp/geoportal_exporter.jsp b/src/main/webapp/WEB-INF/jsp/geoportal_exporter.jsp new file mode 100644 index 0000000..d232f58 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/geoportal_exporter.jsp @@ -0,0 +1,43 @@ + + + + + + +D4Science Geoportal - Action + + + + D4Science Logo +
+
+

Exporting as PDF...

+ D4Science Geoportal Loading...
+
+

The project with 661d2c6f8804530afb90b132

+
+ + \ No newline at end of file