incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r591053 - /incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
Date Thu, 01 Nov 2007 15:30:15 GMT
Author: fmeschbe
Date: Thu Nov  1 08:30:14 2007
New Revision: 591053

URL: http://svn.apache.org/viewvc?rev=591053&view=rev
Log:
SLING-88 Redirect requests to / to the welcome page

Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java?rev=591053&r1=591052&r2=591053&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
Thu Nov  1 08:30:14 2007
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+
 import javax.jcr.Credentials;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -55,6 +56,15 @@
 
     private static final long serialVersionUID = 1L;
 
+    // the name of init-param providing the page to redirect / to
+    private static final String INIT_PARAM_WELCOME_URL = "welcome-url";
+
+    // The default page to redirect / to if not configured in web.xml
+    private static final String DEFAULT_INDEX_PAGE = "index.html";
+
+    // The page to redirect /, configured from welcome-url init-param
+    private String indexPage = DEFAULT_INDEX_PAGE;
+
     private MicroSlingFilterHelper filterChain;
 
     private MicroslingServiceLocator serviceLocator;
@@ -69,6 +79,12 @@
     public void init() throws ServletException {
         super.init();
 
+        // define the indexPage
+        indexPage = getServletConfig().getInitParameter(INIT_PARAM_WELCOME_URL);
+        if (indexPage == null) {
+            indexPage = DEFAULT_INDEX_PAGE;
+        }
+
         // this must be first as services may register later
         initServiceLocator();
 
@@ -137,12 +153,24 @@
     public void service(ServletRequest req, ServletResponse resp)
             throws ServletException, IOException {
 
+        HttpServletRequest hReq = (HttpServletRequest) req;
+        HttpServletResponse hRes = (HttpServletResponse) resp;
+
+        // root redirect
+        if (hReq.getPathInfo() == null) {
+            hRes.sendRedirect(hReq.getRequestURI() + "/" + indexPage);
+            return;
+        } else if ("/".equals(hReq.getPathInfo())) {
+            hRes.sendRedirect(indexPage);
+            return;
+        }
+
         Session session = authenticate(req);
 
         MicroslingSlingHttpServletRequest request = new MicroslingSlingHttpServletRequest(
-            (HttpServletRequest) req, session, serviceLocator);
+            hReq, session, serviceLocator);
         MicroslingSlingHttpServletResponse response = new MicroslingSlingHttpServletResponse(
-            (HttpServletResponse) resp);
+            hRes);
 
         // our filters might need the SlingRequestContext to store info in it
         filterChain.service(request, response);



Mime
View raw message