fixing paths

This commit is contained in:
Francesco Mangiacrapa 2022-03-24 16:38:16 +01:00
parent 2683d601b0
commit fd9a10be6c
2 changed files with 30 additions and 7 deletions

View File

@ -31,18 +31,17 @@ public class UriResolverDocs {
@GET @GET
@Produces({ MediaType.TEXT_HTML }) @Produces({ MediaType.TEXT_HTML })
@Path("/{any: .*}") @Path("/{any: .*}")
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException { public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException {
logger.info(UriResolverDocs.class.getSimpleName() + " called"); logger.info(UriResolverDocs.class.getSimpleName() + " toDoc called");
String pathInfo = req.getPathInfo(); String pathInfo = req.getPathInfo();
logger.info("pathInfo {}", pathInfo); logger.info("pathInfo {}", pathInfo);
try { try {
if (pathInfo.equals("docs")) if (pathInfo.equals("/docs/"))
pathInfo += "/index.html"; pathInfo += "index.html";
logger.info("redirecting to {}", pathInfo); logger.info("redirecting to {}", pathInfo);
logger.info("request URI {}", req.getRequestURI());
String realPath = req.getServletContext().getRealPath(pathInfo); String realPath = req.getServletContext().getRealPath(pathInfo);
return new FileInputStream(new File(realPath)); return new FileInputStream(new File(realPath));
@ -58,5 +57,29 @@ public class UriResolverDocs {
throw (WebApplicationException) e; 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;
}
}
} }

View File

@ -44,7 +44,7 @@ body {
</p> </p>
<p> <p>
See API documentation at <a See API documentation at <a
href="docs" href="docs/index.html"
target="_blank">URI Resolver API</a> target="_blank">URI Resolver API</a>
</p> </p>
</div> </div>