From ccb578670f4331c24fa2234aee91e60712ff95ed Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Thu, 26 Sep 2024 12:58:08 +0200 Subject: [PATCH 1/3] Added context path runtime property --- .../vitro/webapp/controller/ExportQrCodeController.java | 3 ++- .../freemarker/InstitutionalInternalClassController.java | 5 +++-- .../visualization/ShortURLVisualizationController.java | 3 ++- .../main/java/org/vivoweb/webapp/sitemap/SiteMapServlet.java | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java index 2182342e62..e7b617510a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/ExportQrCodeController.java @@ -15,6 +15,7 @@ import org.apache.jena.query.ResultSet; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.config.ContextPath; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; @@ -132,7 +133,7 @@ private Map generateQrData(Individual individual, VitroRequest v qrData.put("externalUrl", externalUrl); String individualUri = individual.getURI(); - String contextPath = vreq.getContextPath(); + String contextPath = ContextPath.getPath(vreq); qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri)); qrData.put("aboutQrCodesUrl", contextPath + "/about_qrcode"); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java index 4a19317b5b..bebc1ba0a3 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java @@ -23,6 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest; import edu.cornell.mannlib.vitro.webapp.beans.VClass; +import edu.cornell.mannlib.vitro.webapp.config.ContextPath; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.edit.utils.LocalNamespaceClassUtils; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues; @@ -81,8 +82,8 @@ protected ResponseValues processRequest(VitroRequest vreq) { //Check if existing local namespaces - data.put("formUrl", vreq.getContextPath() + EDIT_FORM); - data.put("cancelUrl", vreq.getContextPath() + REDIRECT_PAGE); + data.put("formUrl", ContextPath.getPath(vreq) + EDIT_FORM); + data.put("cancelUrl", ContextPath.getPath(vreq) + REDIRECT_PAGE); //if no local namespaces, then provide message to display //if existing namespace(s), then check diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java index af028535bf..adfb287eea 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java @@ -20,6 +20,7 @@ import org.apache.jena.rdf.model.Model; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest; +import edu.cornell.mannlib.vitro.webapp.config.ContextPath; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; @@ -245,7 +246,7 @@ private VisualizationRequestHandler getVisualizationRequestHandler( private List extractShortURLParameters(VitroRequest vitroRequest) { List matchedGroups = new ArrayList(); - String subURIString = vitroRequest.getRequestURI().substring(vitroRequest.getContextPath().length()+1); + String subURIString = vitroRequest.getRequestURI().substring(ContextPath.getPath(vitroRequest).length()+1); String[] urlParams = StringEscapeUtils.ESCAPE_HTML4.translate(subURIString).split("/"); if (urlParams.length > 1 diff --git a/api/src/main/java/org/vivoweb/webapp/sitemap/SiteMapServlet.java b/api/src/main/java/org/vivoweb/webapp/sitemap/SiteMapServlet.java index 23b536d848..9be3921aa5 100644 --- a/api/src/main/java/org/vivoweb/webapp/sitemap/SiteMapServlet.java +++ b/api/src/main/java/org/vivoweb/webapp/sitemap/SiteMapServlet.java @@ -19,7 +19,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.jena.query.QuerySolution; - +import edu.cornell.mannlib.vitro.webapp.config.ContextPath; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; @@ -41,7 +41,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) if (requestURI != null) { if (requestURI.contains("robots.txt")) { String robotsPath = getServletContext().getRealPath("/robots.txt"); - String contextPath = request.getContextPath(); + String contextPath = ContextPath.getPath(request); StringBuilder builder = new StringBuilder("Sitemap: "); builder.append(getSchemeAndServer(request)); From b353e559336497748dff30fe7b6dce1347aa7480 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Fri, 27 Sep 2024 08:18:27 +0200 Subject: [PATCH 2/3] added commented context.path configuration property to example.runtime.properties --- home/src/main/resources/config/example.runtime.properties | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/home/src/main/resources/config/example.runtime.properties b/home/src/main/resources/config/example.runtime.properties index 8817ce777b..5ee841f3d7 100644 --- a/home/src/main/resources/config/example.runtime.properties +++ b/home/src/main/resources/config/example.runtime.properties @@ -32,6 +32,10 @@ # Vitro.defaultNamespace = http://vivo.mydomain.edu/individual/ +# In case VIVO is behind proxy you might want to avoid redirects by overriding +# context path to empty string or other custom value +# context.path= + # # The email address of the root user for the VIVO application. The password # for this user is initially set to "rootPassword", but you will be asked to From e402232371cb23826b5d88102bd4376b797d09d6 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Fri, 25 Oct 2024 12:54:35 +0200 Subject: [PATCH 3/3] revert change to fix short visualization --- .../visualization/ShortURLVisualizationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java index adfb287eea..0ff70b5e8a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/visualization/ShortURLVisualizationController.java @@ -246,7 +246,7 @@ private VisualizationRequestHandler getVisualizationRequestHandler( private List extractShortURLParameters(VitroRequest vitroRequest) { List matchedGroups = new ArrayList(); - String subURIString = vitroRequest.getRequestURI().substring(ContextPath.getPath(vitroRequest).length()+1); + String subURIString = vitroRequest.getRequestURI().substring(vitroRequest.getContextPath().length()+1); String[] urlParams = StringEscapeUtils.ESCAPE_HTML4.translate(subURIString).split("/"); if (urlParams.length > 1