From 9f0fe65a9f7298902e56a000d483bc04c4aedf5a Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Mon, 2 May 2022 16:39:50 +0200 Subject: [PATCH] Enunciate integration --- .../common/model/useCaseDescriptor/Field.java | 10 +-- geoportal-service/enunciate.xml | 41 ++++++++++ geoportal-service/pom.xml | 77 ++++++++++++++++++- .../geoportal/service/rest/DocsGenerator.java | 41 ++++++++++ .../src/main/webapp/WEB-INF/gcube-app.xml | 3 + 5 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 geoportal-service/enunciate.xml create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/DocsGenerator.java diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/useCaseDescriptor/Field.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/useCaseDescriptor/Field.java index 580b83e..c994d8a 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/useCaseDescriptor/Field.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/useCaseDescriptor/Field.java @@ -10,11 +10,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -@XmlRootElement -@AllArgsConstructor -@Getter -@Setter -@ToString(callSuper = true) +//@XmlRootElement +//@AllArgsConstructor +//@Getter +//@Setter +//@ToString(callSuper = true) public class Field extends Document { public static final String TYPE="_type"; diff --git a/geoportal-service/enunciate.xml b/geoportal-service/enunciate.xml new file mode 100644 index 0000000..08d43a3 --- /dev/null +++ b/geoportal-service/enunciate.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index 9910686..7b22bb2 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -17,7 +17,7 @@ https://code-repo.d4science.org/gCubeSystem 1.0 - + 2.14.0 @@ -114,6 +114,25 @@ + + + com.webcohesion.enunciate + enunciate-core-annotations + ${enunciate.version} + provided + + + com.webcohesion.enunciate + enunciate-rt-util + ${enunciate.version} + provided + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + @@ -169,4 +188,60 @@ + + + + + + com.webcohesion.enunciate + enunciate-maven-plugin + ${enunciate.version} + + + + + org.gcube.application + geoportal-client + + + + + + assemble + + assemble + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-enunciate-docs + process-resources + + copy-resources + + + target + + + ${project.build.directory}/${project.artifactId}-${project.version}/docs + ${project.build.directory}/docs + true + + + + + + + + + + \ No newline at end of file diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/DocsGenerator.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/DocsGenerator.java new file mode 100644 index 0000000..f9b4d13 --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/DocsGenerator.java @@ -0,0 +1,41 @@ +package org.gcube.application.geoportal.service.rest; +import lombok.extern.slf4j.Slf4j; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +@Path("docs") +@Slf4j +public class DocsGenerator { + + @GET + @Path("/{any: .*}") + public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException { + log.info(DocsGenerator.class.getSimpleName() + " toDoc called"); + + String pathInfo = req.getPathInfo(); + log.debug("pathInfo {}", pathInfo); + try { + + if (pathInfo.endsWith("/docs/")) { + pathInfo += "index.html"; + } + + log.info("going to {}", pathInfo); + + String realPath = req.getServletContext().getRealPath(pathInfo); + return new FileInputStream(new File(realPath)); + + } catch (Exception e) { + log.error("Exception while Docs. Request was {}",req,e); + throw new WebApplicationException("Doc Exception ",e, Response.Status.INTERNAL_SERVER_ERROR); + } + } +} diff --git a/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml b/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml index ced0697..cee5117 100644 --- a/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml +++ b/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml @@ -4,5 +4,8 @@ 1.0.0 REST service for GeoPortal + + +