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 |
/**
|
|
31 |
*
|
|
32 |
* @author hilgeru
|
|
33 |
*/
|
|
34 |
public class NiceFilter implements Filter {
|
a89f86
|
35 |
|
U |
36 |
private static final String ZIEL = "../api?c=de.uhilger.um.api.UserMgr&m=";
|
f4a79c
|
37 |
|
U |
38 |
@Override
|
|
39 |
public void init(FilterConfig filterConfig) throws ServletException {
|
|
40 |
// ...
|
|
41 |
}
|
|
42 |
|
a89f86
|
43 |
/*
|
U |
44 |
hier wird ein URL wie z.B.
|
725d10
|
45 |
http]://example.com/um/svc/testmethode
|
a89f86
|
46 |
umgesetzt auf
|
51c9e3
|
47 |
http]://example.com/um/api?c=de.uhilger.um.api.UserMgr&m=testmethode
|
a89f86
|
48 |
|
U |
49 |
der Teil 'svc' ist im Filter Mapping des Deployment Descriptor
|
725d10
|
50 |
deklariert. Der Teil 'api' zeigt mit Hilfe eines Servlet
|
U |
51 |
Mappings im Deployment Descriptor auf das Transit-Servlet.
|
a89f86
|
52 |
|
U |
53 |
der statische Teil des Ziel-URL ist hier hart kodiert, das kann man
|
725d10
|
54 |
freilich je nach Bedarf noch dynamisch gestalten
|
a89f86
|
55 |
*/
|
725d10
|
56 |
|
f4a79c
|
57 |
@Override
|
U |
58 |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
|
59 |
if(request instanceof HttpServletRequest) {
|
|
60 |
HttpServletRequest hr = (HttpServletRequest) request;
|
|
61 |
String servletPath = hr.getServletPath();
|
|
62 |
String[] path = servletPath.split("/");
|
a89f86
|
63 |
request.getRequestDispatcher(ZIEL + path[2]).forward(request, response);
|
f4a79c
|
64 |
}
|
U |
65 |
}
|
|
66 |
|
|
67 |
@Override
|
|
68 |
public void destroy() {
|
|
69 |
// ...
|
|
70 |
}
|
|
71 |
|
|
72 |
}
|