From fd9a10be6cc967593abbf7817344a7fbfd5343f8 Mon Sep 17 00:00:00 2001
From: "francesco.mangiacrapa"
Date: Thu, 24 Mar 2022 16:38:16 +0100
Subject: [PATCH] fixing paths
---
.../resolver/services/UriResolverDocs.java | 35 +++++++++++++++----
src/main/webapp/WEB-INF/jsp/index.jsp | 2 +-
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java
index bb4efa4..f5aa5a6 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java
@@ -31,18 +31,17 @@ public class UriResolverDocs {
@GET
@Produces({ MediaType.TEXT_HTML })
@Path("/{any: .*}")
- public InputStream index(@Context HttpServletRequest req) throws WebApplicationException {
- logger.info(UriResolverDocs.class.getSimpleName() + " called");
+ public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException {
+ logger.info(UriResolverDocs.class.getSimpleName() + " toDoc called");
String pathInfo = req.getPathInfo();
logger.info("pathInfo {}", pathInfo);
try {
- if (pathInfo.equals("docs"))
- pathInfo += "/index.html";
+ if (pathInfo.equals("/docs/"))
+ pathInfo += "index.html";
logger.info("redirecting to {}", pathInfo);
- logger.info("request URI {}", req.getRequestURI());
String realPath = req.getServletContext().getRealPath(pathInfo);
return new FileInputStream(new File(realPath));
@@ -58,5 +57,29 @@ public class UriResolverDocs {
throw (WebApplicationException) e;
}
}
-
+
+ @GET
+ @Produces({ MediaType.TEXT_HTML })
+ @Path("")
+ public InputStream index(@Context HttpServletRequest req) throws WebApplicationException {
+ logger.info(UriResolverDocs.class.getSimpleName() + " index called");
+
+ String pathInfo = "/docs/index.html";
+ try {
+
+ String realPath = req.getServletContext().getRealPath(pathInfo);
+ return new FileInputStream(new File(realPath));
+ } catch (Exception e) {
+
+ if (!(e instanceof WebApplicationException)) {
+ // UNEXPECTED EXCEPTION managing it as WebApplicationException
+ String error = pathInfo + " not found. Please, contact the support!";
+ throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
+ }
+ // ALREADY MANAGED AS WebApplicationException
+ logger.error("Exception:", e);
+ throw (WebApplicationException) e;
+ }
+ }
+
}
diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp
index df8421c..44d30cd 100644
--- a/src/main/webapp/WEB-INF/jsp/index.jsp
+++ b/src/main/webapp/WEB-INF/jsp/index.jsp
@@ -44,7 +44,7 @@ body {
See API documentation at URI Resolver API