From 37b4298579bb693b34b82af07536d729af9d3dee Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 4 Nov 2012 18:17:32 -0300 Subject: [PATCH] Fix Apache Proxy configuration property. --- .../filter/RequestPropertiesInterceptor.java | 46 ++++++++++++++----- .../wisemapping/mail/NotificationService.java | 30 ++++++++---- .../src/main/webapp/WEB-INF/app.properties | 6 ++- .../main/webapp/WEB-INF/wisemapping-dao.xml | 3 -- .../webapp/WEB-INF/wisemapping-security.xml | 7 --- .../webapp/WEB-INF/wisemapping-service.xml | 5 +- .../webapp/WEB-INF/wisemapping-servlet.xml | 24 ++-------- .../main/webapp/jsp/dialogFullTemplate.jsp | 2 +- wise-webapp/src/main/webapp/jsp/init.jsp | 3 -- .../src/main/webapp/jsp/mindmapEditor.jsp | 2 +- .../src/main/webapp/jsp/mindmapEmbed.jsp | 2 +- .../src/main/webapp/jsp/mindmapList.jsp | 2 +- .../src/main/webapp/jsp/mindmapPrint.jsp | 2 +- wise-webapp/src/main/webapp/jsp/template.jsp | 2 +- 14 files changed, 71 insertions(+), 65 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/filter/RequestPropertiesInterceptor.java b/wise-webapp/src/main/java/com/wisemapping/filter/RequestPropertiesInterceptor.java index a187e920..36362821 100644 --- a/wise-webapp/src/main/java/com/wisemapping/filter/RequestPropertiesInterceptor.java +++ b/wise-webapp/src/main/java/com/wisemapping/filter/RequestPropertiesInterceptor.java @@ -18,29 +18,51 @@ package com.wisemapping.filter; -import com.wisemapping.exceptions.GoogleChromeFrameRequiredException; -import com.wisemapping.exceptions.UnsupportedBrowserException; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.util.HashMap; import java.util.Map; -import java.util.Set; +import java.util.regex.Pattern; + public class RequestPropertiesInterceptor extends HandlerInterceptorAdapter { - private Map attributes; + @Value("${google.analytics.enabled}") + private Boolean analyticsEnabled; + + @Value("${google.analytics.account}") + private String analyticsAccount; + + @Value("${google.ads.enabled}") + private Boolean adsEnabled; + + @Value("${site.homepage}") + private String siteHomepage; + + @Autowired + Environment env; public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, Object object) throws Exception { - for (String key : attributes.keySet()) { - request.setAttribute(key, attributes.get(key)); + + request.setAttribute("google.analytics.enabled", analyticsEnabled); + request.setAttribute("google.analytics.account", analyticsAccount); + request.setAttribute("google.ads.enabled", adsEnabled); + request.setAttribute("site.homepage", siteHomepage); + + final String baseUrl; + if (env.containsProperty("site.baseurl")) { + baseUrl = env.getProperty("site.baseurl"); + } else { + baseUrl = request.getRequestURL().toString().replace(request.getRequestURI(), request.getContextPath()); } + request.setAttribute("site.baseurl", baseUrl); return true; } - - public void setAttributes(Map attributes) { - this.attributes = attributes; - } } diff --git a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java index c047d657..8c97954c 100644 --- a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java +++ b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java @@ -27,6 +27,7 @@ import org.apache.commons.lang.StringEscapeUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import javax.servlet.http.HttpServletRequest; import java.io.PrintWriter; @@ -37,12 +38,14 @@ import java.util.Map; final public class NotificationService { - + public static final String DEFAULT_WISE_URL = "http://localhost:8080/wisemapping"; @Autowired private Mailer mailer; - private String baseUrl; + private NotifierFilter notificationFilter; + private String baseUrl; + public NotificationService() { this.notificationFilter = new NotifierFilter(); } @@ -64,8 +67,8 @@ final public class NotificationService { model.put("mindmap", mindmap); model.put("message", "message"); model.put("ownerName", user.getFirstname()); - model.put("mapEditUrl", baseUrl + "/c/maps/" + mindmap.getId() + "/edit"); - model.put("baseUrl", baseUrl); + model.put("mapEditUrl", getBaseUrl() + "/c/maps/" + mindmap.getId() + "/edit"); + model.put("baseUrl", getBaseUrl()); model.put("senderMail", user.getEmail()); model.put("message", message); model.put("supportEmail", mailer.getSupportEmail()); @@ -83,7 +86,7 @@ final public class NotificationService { final String messageBody = "

Someone, most likely you, requested a new password for your WiseMapping account.

\n" + "

Here is your new password: " + temporalPassword + "

\n" + - "

You can login clicking here. We strongly encourage you to change the password as soon as possible.

"; + "

You can login clicking here. We strongly encourage you to change the password as soon as possible.

"; sendTemplateMail(user, mailSubject, messageTitle, messageBody); } @@ -112,7 +115,7 @@ final public class NotificationService { model.put("firstName", user.getFirstname()); model.put("messageTitle", messageTitle); model.put("messageBody", messageBody); - model.put("baseUrl", this.baseUrl); + model.put("baseUrl", getBaseUrl()); model.put("supportEmail", mailer.getSupportEmail()); mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), mailSubject, model, "baseLayout.vm"); @@ -127,10 +130,6 @@ final public class NotificationService { } - public void setBaseUrl(String baseUrl) { - this.baseUrl = baseUrl; - } - public void setMailer(Mailer mailer) { this.mailer = mailer; } @@ -227,6 +226,17 @@ final public class NotificationService { return retValue; } + public String getBaseUrl() { + if ("${site.baseurl}".equals(baseUrl)) { + baseUrl = DEFAULT_WISE_URL; + System.err.println("Warning: site.baseurl has not being configured. Mail site references could be not properly sent. Using :" + baseUrl); + } + return baseUrl; + } + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } } diff --git a/wise-webapp/src/main/webapp/WEB-INF/app.properties b/wise-webapp/src/main/webapp/WEB-INF/app.properties index 9d9189e3..f0aa2f30 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/app.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/app.properties @@ -80,8 +80,10 @@ google.recaptcha.publicKey = 6LeQ4tISAAAAALzCGKNgRv8UqsDx7Cb0vq4wbJBr # etc. admin.user = admin@wisemapping.org -# Site URL. This url will be used during sharing emails and public views. -site.baseurl = http://localhost:8080/wisemapping +# Base URL where WiseMapping is deployed. By default, It will be automatically inferred. +# If you are planning to put wisemapping behind an Apache using an Apache Proxy setup, you must enable this property. +# site.baseurl = http:///example.com:8080/wisemapping + # Site Homepage URL. This will be used as URL for homepage location. site.homepage = c/home diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml index 1f690e87..c8017226 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml @@ -7,9 +7,6 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> - - - diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml index 92352c2d..a84c5a99 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml @@ -11,8 +11,6 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> - - @@ -72,9 +70,4 @@ - - - - - \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml index bbd9fcf5..8ebbd33f 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml @@ -1,8 +1,11 @@ + http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> + + diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml index 215414ce..76584ef5 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml @@ -14,9 +14,7 @@ - + @@ -38,18 +36,8 @@ - - - - - - - - - - - - + + @@ -110,10 +98,4 @@ - - - - diff --git a/wise-webapp/src/main/webapp/jsp/dialogFullTemplate.jsp b/wise-webapp/src/main/webapp/jsp/dialogFullTemplate.jsp index 5abb179d..b7cc410d 100644 --- a/wise-webapp/src/main/webapp/jsp/dialogFullTemplate.jsp +++ b/wise-webapp/src/main/webapp/jsp/dialogFullTemplate.jsp @@ -16,7 +16,7 @@ - + diff --git a/wise-webapp/src/main/webapp/jsp/init.jsp b/wise-webapp/src/main/webapp/jsp/init.jsp index 040b1cf2..91b72cbb 100644 --- a/wise-webapp/src/main/webapp/jsp/init.jsp +++ b/wise-webapp/src/main/webapp/jsp/init.jsp @@ -2,6 +2,3 @@ <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> - - - diff --git a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp index 5c857efa..ae22ee1b 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp @@ -11,7 +11,7 @@ <%--@elvariable id="mapXml" type="com.wisemapping.model.User"--%> - + <spring:message code="SITE.TITLE"/> - <c:out value="${mindmap.title}"/>