commit | author | age
|
f4a79c
|
1 |
/*
|
U |
2 |
* To change this license header, choose License Headers in Project Properties.
|
|
3 |
* To change this template file, choose Tools | Templates
|
|
4 |
* and open the template in the editor.
|
|
5 |
*/
|
|
6 |
package de.uhilger.um.web;
|
|
7 |
|
|
8 |
import java.io.IOException;
|
|
9 |
import javax.servlet.Filter;
|
|
10 |
import javax.servlet.FilterChain;
|
|
11 |
import javax.servlet.FilterConfig;
|
|
12 |
import javax.servlet.ServletException;
|
|
13 |
import javax.servlet.ServletRequest;
|
|
14 |
import javax.servlet.ServletResponse;
|
|
15 |
import javax.servlet.http.HttpServletRequest;
|
|
16 |
|
|
17 |
/**
|
|
18 |
*
|
|
19 |
* @author hilgeru
|
|
20 |
*/
|
|
21 |
public class NiceFilter implements Filter {
|
a89f86
|
22 |
|
U |
23 |
private static final String ZIEL = "../api?c=de.uhilger.um.api.UserMgr&m=";
|
f4a79c
|
24 |
|
U |
25 |
@Override
|
|
26 |
public void init(FilterConfig filterConfig) throws ServletException {
|
|
27 |
// ...
|
|
28 |
}
|
|
29 |
|
a89f86
|
30 |
/*
|
U |
31 |
hier wird ein URL wie z.B.
|
725d10
|
32 |
http]://example.com/um/svc/testmethode
|
a89f86
|
33 |
umgesetzt auf
|
725d10
|
34 |
http]://example,com/um/api?c=de.uhilger.um.api.UserMgr&m=testmethode
|
a89f86
|
35 |
|
U |
36 |
der Teil 'svc' ist im Filter Mapping des Deployment Descriptor
|
725d10
|
37 |
deklariert. Der Teil 'api' zeigt mit Hilfe eines Servlet
|
U |
38 |
Mappings im Deployment Descriptor auf das Transit-Servlet.
|
a89f86
|
39 |
|
U |
40 |
der statische Teil des Ziel-URL ist hier hart kodiert, das kann man
|
725d10
|
41 |
freilich je nach Bedarf noch dynamisch gestalten
|
a89f86
|
42 |
*/
|
725d10
|
43 |
|
f4a79c
|
44 |
@Override
|
U |
45 |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
|
46 |
if(request instanceof HttpServletRequest) {
|
|
47 |
HttpServletRequest hr = (HttpServletRequest) request;
|
|
48 |
String servletPath = hr.getServletPath();
|
|
49 |
String[] path = servletPath.split("/");
|
a89f86
|
50 |
request.getRequestDispatcher(ZIEL + path[2]).forward(request, response);
|
f4a79c
|
51 |
}
|
U |
52 |
}
|
|
53 |
|
|
54 |
@Override
|
|
55 |
public void destroy() {
|
|
56 |
// ...
|
|
57 |
}
|
|
58 |
|
|
59 |
}
|