/*******************************************************************************
 * Copyright (c) 2016 IBM Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.ibm.liberty.starter.filter;

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns={"/*"})
public class FilterServlet extends HttpServlet {
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
        resp.setHeader("Location", "/start/");
    }


}

@@ -814,16 +814,83 @@
 eption;%0A
+import java.io.PrintWriter;%0A%0Aimport javax.servlet.ServletException;
 %0Aimport 
@@ -1086,17 +1086,16 @@
 erns=%7B%22/
-*
 %22%7D)%0Apubl
@@ -1251,19 +1251,225 @@
 xception
- %7B%0A
+, ServletException %7B%0A        System.out.println(%22FilterServlet caught request %22 + req.getRequestURI());%0A        if (%22/%22.equals(req.getRequestURI())) %7B%0A            System.out.println(%22Forwarding request%22);%0A    
         
@@ -1526,32 +1526,36 @@
 ENTLY);%0A        
+ 
+   
 resp.setHeader(%22
@@ -1573,22 +1573,546 @@
 %22/start/%22);%0A
+        %7D else %7B%0A            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);%0A            PrintWriter writer = resp.getWriter();%0A            StringBuffer urlBuffer = req.getRequestURL();%0A            String appLocation = urlBuffer.toString();%0A            String appUrl = appLocation.substring(0, appLocation.indexOf(req.getRequestURI())) + %22/start/%22;%0A            writer.println(%22%3Chtml%3E%3Cbody%3EResource not found, the Liberty app accelerator can be found %3Ca href=%5C%22%22 + appUrl  + %22%5C%22%3Ehere%3C/a%3E.%3C/body%3E%3C/head%3E%3C/html%3E%22);%0A        %7D%0A
     %7D%0A%0A%0A%7D%0A

Update filter to only redirect if accessed at root, otherwise produce 404 with link to actual page.