ulrich
2017-02-11 6fda23559babb8f0f752cc55b3ba488f1ea7513d
commit | author | age
f4a79c 1 /*
51c9e3 2  *  Nutzerverwaltung - User and role management in your browser
U 3  *  Copyright (C) 2011-2016 Ulrich Hilger, http://uhilger.de
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see http://www.gnu.org/licenses/
f4a79c 17  */
51c9e3 18
f4a79c 19 package de.uhilger.um.web;
U 20
21 import java.io.IOException;
22 import javax.servlet.Filter;
23 import javax.servlet.FilterChain;
24 import javax.servlet.FilterConfig;
25 import javax.servlet.ServletException;
26 import javax.servlet.ServletRequest;
27 import javax.servlet.ServletResponse;
28 import javax.servlet.http.HttpServletRequest;
29
30 /**
61cf48 31  * Filter zum Verkuerzen von URLs
f4a79c 32  *
61cf48 33  * @author Copyright (c) Ulrich Hilger, http://uhilger.de
U 34  * @author Published under the terms and conditions of the
35  * <a href="http://www.gnu.org/licenses/agpl-3.0" target="_blank">GNU Affero
36  * General Public License</a>
37  *
38  * @version 2, February 1, 2017
f4a79c 39  */
U 40 public class NiceFilter implements Filter {
a89f86 41   
U 42   private static final String ZIEL = "../api?c=de.uhilger.um.api.UserMgr&m=";
f4a79c 43
U 44   @Override
45   public void init(FilterConfig filterConfig) throws ServletException {
46     // ...
47   }
48
a89f86 49   /*
U 50     hier wird ein URL wie z.B. 
725d10 51     http]://example.com/um/svc/testmethode
a89f86 52     umgesetzt auf
51c9e3 53     http]://example.com/um/api?c=de.uhilger.um.api.UserMgr&m=testmethode
a89f86 54   
U 55     der Teil 'svc' ist im Filter Mapping des Deployment Descriptor 
725d10 56     deklariert. Der Teil 'api' zeigt mit Hilfe eines Servlet 
U 57     Mappings im Deployment Descriptor auf das Transit-Servlet.
a89f86 58   
U 59     der statische Teil des Ziel-URL ist hier hart kodiert, das kann man 
725d10 60     freilich je nach Bedarf noch dynamisch gestalten
a89f86 61   */
725d10 62   
f4a79c 63   @Override
U 64   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
65     if(request instanceof HttpServletRequest) {
66       HttpServletRequest hr = (HttpServletRequest) request;
67       String servletPath = hr.getServletPath();
68       String[] path = servletPath.split("/");
a89f86 69       request.getRequestDispatcher(ZIEL + path[2]).forward(request, response);
f4a79c 70     }
U 71   }
72
73   @Override
74   public void destroy() {
75     // ...
76   }
77   
78 }