redirect rebuild

This commit is contained in:
Francesco Mangiacrapa 2022-03-28 15:02:54 +02:00
parent 5fb758e1d9
commit b0dcc5f0a8
1 changed files with 26 additions and 7 deletions

View File

@ -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