001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019
020package org.apache.isis.core.webapp.routing;
021
022import java.io.IOException;
023
024import javax.servlet.Filter;
025import javax.servlet.FilterChain;
026import javax.servlet.FilterConfig;
027import javax.servlet.ServletException;
028import javax.servlet.ServletRequest;
029import javax.servlet.ServletResponse;
030import javax.servlet.http.HttpServletRequest;
031import javax.servlet.http.HttpServletResponse;
032
033import org.apache.isis.core.commons.lang.StringExtensions;
034
035public class RedirectFilter implements Filter {
036
037    private String redirectTo;
038
039    protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
040
041    }
042
043    @Override
044    public void init(final FilterConfig filterConfig) throws ServletException {
045        redirectTo = filterConfig.getInitParameter("redirectTo");
046    }
047
048    @Override
049    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
050        final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
051        final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
052
053        httpServletResponse.sendRedirect(StringExtensions.combinePath(httpServletRequest.getContextPath(), redirectTo));
054    }
055
056    @Override
057    public void destroy() {
058
059    }
060
061}