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 a274692..9cf1e1c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/UriResolverDocs.java @@ -48,16 +48,35 @@ public class UriResolverDocs { public Response toDoc(@Context HttpServletRequest req) throws WebApplicationException { logger.info(UriResolverDocs.class.getSimpleName() + " toDoc called"); - String pathInfo = req.getPathInfo(); - logger.info("pathInfo {}", pathInfo); + StringBuilder newURL = null; try { + String scheme = req.getScheme(); // http + String serverName = req.getServerName(); // hostname.com + int serverPort = req.getServerPort(); + String pathInfo = req.getPathInfo(); + String queryString = req.getQueryString(); + + // Reconstruct original requesting URL + newURL = new StringBuilder(); + newURL.append(scheme).append("://").append(serverName); + +// if (serverPort != 80 && serverPort != 443) { +// url.append(":").append(serverPort); +// } + + logger.info("pathInfo {}", pathInfo); if (pathInfo.equals("/docs/")) pathInfo += "index.html"; - - ServletContext context = req.getServletContext(); - String realPath = context.getRealPath(pathInfo); - UriBuilder builder = UriBuilder.fromPath(realPath); + + if (pathInfo != null) { + newURL.append(pathInfo); + } + if (queryString != null) { + newURL.append("?").append(queryString); + } + + UriBuilder builder = UriBuilder.fromPath(newURL.toString()); // builder.path(pathInfo); URI redirectTo = builder.build(); @@ -67,7 +86,7 @@ public class UriResolverDocs { if (!(e instanceof WebApplicationException)) { // UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = pathInfo + " not found. Please, contact the support!"; + String error = newURL + " not found. Please, contact the support!"; throw ExceptionManager.internalErrorException(req, error, this.getClass(), null); } // ALREADY MANAGED AS WebApplicationException