Fix Apache Proxy configuration property.

This commit is contained in:
Paulo Gustavo Veiga 2012-11-04 18:17:32 -03:00
parent 5cb2289cbc
commit 37b4298579
14 changed files with 71 additions and 65 deletions

View File

@ -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<String, String> 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<String, String> attributes) {
this.attributes = attributes;
}
}

View File

@ -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 =
"<p>Someone, most likely you, requested a new password for your WiseMapping account. </p>\n" +
"<p><strong>Here is your new password: " + temporalPassword + "</strong></p>\n" +
"<p>You can login clicking <a href=\"" + this.baseUrl + "/c/login\">here</a>. We strongly encourage you to change the password as soon as possible.</p>";
"<p>You can login clicking <a href=\"" + getBaseUrl() + "/c/login\">here</a>. We strongly encourage you to change the password as soon as possible.</p>";
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;
}
}

View File

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

View File

@ -7,9 +7,6 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:property-placeholder location="/WEB-INF/app.properties"/>
<bean id="wiseDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${database.driver}"/>
<property name="url" value="${database.url}"/>

View File

@ -11,8 +11,6 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="/WEB-INF/app.properties"/>
<bean id="encoder"
class="com.wisemapping.security.CustomPasswordEncoder"/>
@ -72,9 +70,4 @@
<property name="userService" ref="userService"/>
<property name="adminUser" value="${admin.user}"/>
</bean>
<beans profile="heroku">
<context:property-placeholder location="/WEB-INF/heroku.properties"/>
</beans>
</beans>

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
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">
<context:property-placeholder location="/WEB-INF/app.properties" ignore-unresolvable="true"/>
<bean id="mailer" class="com.wisemapping.mail.Mailer" scope ="singleton">
<constructor-arg index="0" value="${mail.serverSendEmail}"/>

View File

@ -14,9 +14,7 @@
<context:component-scan base-package="com.wisemapping.ncontroller"/>
<context:annotation-config/>
<mvc:annotation-driven/>
<context:property-placeholder
location="/WEB-INF/app.properties"
/>
<context:property-placeholder location="/WEB-INF/app.properties" ignore-unresolvable="true"/>
<!-- Interceptors Registration -->
<mvc:interceptors>
@ -38,18 +36,8 @@
</set>
</property>
</bean>
<bean id="userLocaleInterceptor" class="com.wisemapping.filter.UserLocaleInterceptor">
</bean>
<bean id="requestInterceptor" class="com.wisemapping.filter.RequestPropertiesInterceptor">
<property name="attributes">
<map>
<entry key="google.analytics.enabled" value="${google.analytics.enabled}"/>
<entry key="google.analytics.account" value="${google.analytics.account}"/>
<entry key="google.ads.enabled" value="${google.ads.enabled}"/>
<entry key="site.homepage" value="${site.homepage}"/>
</map>
</property>
</bean>
<bean id="userLocaleInterceptor" class="com.wisemapping.filter.UserLocaleInterceptor"/>
<bean id="requestInterceptor" class="com.wisemapping.filter.RequestPropertiesInterceptor"/>
</mvc:interceptors>
@ -110,10 +98,4 @@
</list>
</property>
</bean>
<beans profile="heroku">
<context:property-placeholder
location="/WEB-INF/heroku.properties"
/>
</beans>
</beans>

View File

@ -16,7 +16,7 @@
<html>
<head>
<base href="${baseURL}/">
<base href="${requestScope['site.baseurl']}/">
<!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<![endif]-->

View File

@ -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" %>
<c:set var="baseURL" value="${fn:replace(pageContext.request.requestURL, pageContext.request.requestURI, pageContext.request.contextPath)}" />

View File

@ -11,7 +11,7 @@
<%--@elvariable id="mapXml" type="com.wisemapping.model.User"--%>
<html>
<head>
<base href="${baseURL}/">
<base href="${requestScope['site.baseurl']}/">
<title><spring:message code="SITE.TITLE"/> - <c:out value="${mindmap.title}"/></title>
<!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="chrome=1">

View File

@ -11,7 +11,7 @@
<html>
<head>
<base href="${baseURL}/">
<base href="{requestScope['site.baseurl']}/">
<title><spring:message code="SITE.TITLE"/> - ${mindmap.title} </title>
<!--[if lt IE 9]>

View File

@ -5,7 +5,7 @@
<html lang="en">
<head>
<base href="${baseURL}/">
<base href="${requestScope['site.baseurl']}/">
<title><spring:message code="SITE.TITLE"/> - <spring:message code="MY_WISEMAPS"/></title>
<!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="chrome=1">

View File

@ -10,7 +10,7 @@
<html>
<head>
<base href="${baseURL}/">
<base href="${requestScope['site.baseurl']}/">
<title><spring:message code="SITE.TITLE"/> - ${mindmap.title} </title>
<!--[if lt IE 9]>

View File

@ -10,7 +10,7 @@
<html>
<head>
<base href="${baseURL}/">
<base href="${requestScope['site.baseurl']}/">
<title>
<spring:message code="SITE.TITLE"/>-
<c:choose>