From 50c822904e510dfb5180a41641c6ed57dbd6bd79 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 24 Mar 2022 15:59:07 +0100 Subject: [PATCH] fixing UriResolverDocs --- .../resolver/services/UriResolverDocs.java | 67 +++++++++++-------- 1 file changed, 40 insertions(+), 27 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 1118ae2..dcca55b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java @@ -21,44 +21,57 @@ import org.slf4j.LoggerFactory; /** * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Oct 22, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 22, 2018 */ -@Path("docs/*") +@Path("docs") public class UriResolverDocs { private static Logger logger = LoggerFactory.getLogger(UriResolverDocs.class); @GET - @Produces({MediaType.TEXT_HTML}) - @Path("") - public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{ - logger.info(UriResolverDocs.class.getSimpleName() +" called"); - - String requestURI = req.getRequestURI(); - try{ - - - if(requestURI == null) - requestURI = "/index.html"; - - String pathInfo = req.getPathInfo(); - logger.info("pathInfo {}",pathInfo); - logger.info("request URI {}", requestURI); - - String realPath = req.getServletContext().getRealPath("/docs/"+requestURI); - return new FileInputStream(new File(realPath)); - }catch (Exception e) { + @Produces({ MediaType.TEXT_HTML }) + @Path("/") + public InputStream index(@Context HttpServletRequest req) throws WebApplicationException { + logger.info(UriResolverDocs.class.getSimpleName() + " called"); - if(!(e instanceof WebApplicationException)){ - //UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = requestURI+" not found. Please, contact the support!"; + String requestURI = req.getRequestURI(); + try { + + if (requestURI == null) + requestURI = "/index.html"; + + String pathInfo = req.getPathInfo(); + logger.info("pathInfo {}", pathInfo); + logger.info("request URI {}", requestURI); + + String realPath = req.getServletContext().getRealPath("/docs/" + requestURI); + return new FileInputStream(new File(realPath)); + } catch (Exception e) { + + if (!(e instanceof WebApplicationException)) { + // UNEXPECTED EXCEPTION managing it as WebApplicationException + String error = requestURI + " not found. Please, contact the support!"; throw ExceptionManager.internalErrorException(req, error, this.getClass(), null); } - //ALREADY MANAGED AS WebApplicationException + // ALREADY MANAGED AS WebApplicationException logger.error("Exception:", e); throw (WebApplicationException) e; } } -} + @GET + @Produces({ MediaType.TEXT_HTML }) + @Path("*") + public InputStream toDoc1(@Context HttpServletRequest req) throws WebApplicationException { + logger.info(UriResolverDocs.class.getSimpleName() + " toDoc1 called"); + return index(req); + } + + @GET + @Produces({ MediaType.TEXT_HTML }) + @Path("/*") + public InputStream toDoc2(@Context HttpServletRequest req) throws WebApplicationException { + logger.info(UriResolverDocs.class.getSimpleName() + " toDoc2 called"); + return index(req); + } +}