| /******************************************************************************** |
| * Copyright (c) 2015-2018 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| ********************************************************************************/ |
| |
| package org.eclipse.mdm.application; |
| |
| import java.io.IOException; |
| |
| import javax.servlet.Filter; |
| import javax.servlet.FilterChain; |
| import javax.servlet.FilterConfig; |
| import javax.servlet.ServletException; |
| import javax.servlet.ServletRequest; |
| import javax.servlet.ServletResponse; |
| import javax.servlet.http.HttpServletRequest; |
| import javax.servlet.http.HttpServletResponse; |
| |
| /** |
| * MDMRequestFilter |
| * |
| * @author Sebastian Dirsch, Gigatronik Ingolstadt GmbH |
| * |
| */ |
| public class MDMRequestFilter implements Filter { |
| |
| private static final String SERVLET_NAME_MDMNENUE = "/navigator/"; |
| |
| @Override |
| public void init(FilterConfig filterConfig) throws ServletException { |
| |
| } |
| |
| @Override |
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
| throws IOException, ServletException { |
| if (request instanceof HttpServletRequest) { |
| HttpServletRequest httpRequest = (HttpServletRequest) request; |
| String requestedURL = httpRequest.getRequestURI().toLowerCase(); |
| |
| if (requestedURL.trim().contains(SERVLET_NAME_MDMNENUE)) { |
| if (response instanceof HttpServletResponse) { |
| String location = httpRequest.getContextPath(); |
| ((HttpServletResponse) response).sendRedirect(location); |
| } |
| } else { |
| chain.doFilter(request, response); |
| } |
| } |
| } |
| |
| @Override |
| public void destroy() { |
| } |
| |
| } |