Author: ghuber
Date: Mon Jan 27 14:15:26 2014
New Revision: 1561686
URL: http://svn.apache.org/r1561686
Log:
See ROL-1795, sync with previous mods for ssl switching
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/InitFilter.java
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/InitFilter.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/InitFilter.java?rev=1561686&r1=1561685&r2=1561686&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/InitFilter.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/InitFilter.java
Mon Jan 27 14:15:26 2014
@@ -19,6 +19,7 @@
package org.apache.roller.weblogger.ui.core.filters;
import java.io.IOException;
+
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -26,56 +27,56 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
-
/**
- * A special initialization filter which ensures that we have an opportunity
- * to extract a few pieces of information about the environment we are running
- * in when the first request is sent.
- *
+ * A special initialization filter which ensures that we have an opportunity to
+ * extract a few pieces of information about the environment we are running in
+ * when the first request is sent.
+ *
* @web.filter name="InitFilter"
*/
public class InitFilter implements Filter {
-
+
private static Log log = LogFactory.getLog(InitFilter.class);
-
+
private boolean initialized = false;
-
-
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain
chain)
- throws IOException, ServletException {
-
- if(!initialized) {
+
+ public void doFilter(ServletRequest req, ServletResponse res,
+ FilterChain chain) throws IOException, ServletException {
+
+ if (!initialized) {
+
// first request, lets do our initialization
HttpServletRequest request = (HttpServletRequest) req;
- HttpServletResponse response = (HttpServletResponse) res;
-
+ // HttpServletResponse response = (HttpServletResponse) res;
+
// determine absolute and relative url paths to the app
String relPath = request.getContextPath();
String absPath = this.getAbsoluteUrl(request);
-
+
// set them in our config
WebloggerRuntimeConfig.setAbsoluteContextURL(absPath);
WebloggerRuntimeConfig.setRelativeContextURL(relPath);
-
- log.debug("relPath = "+relPath);
- log.debug("absPath = "+absPath);
-
+
+ if (log.isDebugEnabled()) {
+ log.debug("relPath = " + relPath);
+ log.debug("absPath = " + absPath);
+ }
+
this.initialized = true;
}
-
+
chain.doFilter(req, res);
}
-
-
+
private String getAbsoluteUrl(HttpServletRequest request) {
-
+
String url = null;
-
+
String fullUrl = null;
if (!request.isSecure()) {
@@ -84,33 +85,41 @@ public class InitFilter implements Filte
fullUrl = "http://" + request.getServerName()
+ request.getContextPath();
}
-
+
// if the uri is only "/" then we are basically done
- if("/".equals(request.getRequestURI())) {
- log.info(fullUrl.substring(0, fullUrl.length()-1));
- return fullUrl.substring(0, fullUrl.length()-1);
+ if ("/".equals(request.getRequestURI())) {
+ if (log.isDebugEnabled()) {
+ log.debug(fullUrl.substring(0, fullUrl.length() - 1));
+ }
+ return fullUrl.substring(0, fullUrl.length() - 1);
}
-
+
// find first "/" starting after hostname is specified
- int index = fullUrl.indexOf('/',
fullUrl.indexOf(request.getServerName()));
-
- // extract just the part leading up to uri
- url = fullUrl.substring(0, index);
-
+ int index = fullUrl.indexOf('/',
+ fullUrl.indexOf(request.getServerName()));
+
+ if (index != -1) {
+ // extract just the part leading up to uri
+ url = fullUrl.substring(0, index);
+ } else {
+ url = fullUrl.trim();
+ }
+
// then just add on the context path
url += request.getContextPath();
-
+
// make certain that we don't end with a /
- if(url.endsWith("/")) {
- url = url.substring(0, url.length()-1);
+ if (url.endsWith("/")) {
+ url = url.substring(0, url.length() - 1);
}
-
+
return url;
}
-
-
- public void init(FilterConfig filterConfig) throws ServletException {}
-
- public void destroy() {}
-
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void destroy() {
+ }
+
}