Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 67819 invoked from network); 1 Nov 2007 15:58:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Nov 2007 15:58:11 -0000 Received: (qmail 90834 invoked by uid 500); 1 Nov 2007 15:30:26 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 90805 invoked by uid 500); 1 Nov 2007 15:30:26 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 90795 invoked by uid 99); 1 Nov 2007 15:30:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Nov 2007 08:30:26 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Nov 2007 15:30:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A60FA1A9832; Thu, 1 Nov 2007 08:30:15 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: sling-commits@incubator.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071101153015.A60FA1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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);