commit | author | age
|
bc9f6a
|
1 |
/* |
U |
2 |
WebBox - Dein Server. |
|
3 |
Copyright (C) 2017 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 Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (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 Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.wbx.web; |
|
19 |
|
|
20 |
import java.io.IOException; |
|
21 |
import java.io.OutputStream; |
|
22 |
import java.util.logging.Logger; |
|
23 |
import javax.servlet.FilterChain; |
|
24 |
import javax.servlet.ServletException; |
|
25 |
import javax.servlet.ServletRequest; |
|
26 |
import javax.servlet.ServletResponse; |
|
27 |
import javax.servlet.http.HttpServletRequest; |
|
28 |
import javax.servlet.http.HttpServletResponse; |
|
29 |
|
|
30 |
/** |
|
31 |
* Dieser Filter ist dem Beispiel auf |
|
32 |
* http://otndnld.oracle.co.jp/document/products/as10g/101300/B25221_03/web.1013/b14426/filters.htm#BCFIAAAH |
|
33 |
* entnommen und kann zum Testen von Filter-Konfigurationen oder als Ausgangsbasis |
|
34 |
* fuer komplexere Filter-Funktionen verwendet werden. |
|
35 |
* |
|
36 |
* Das Beispiel umschliesst eine beliebige Antwort vom Server mit |
|
37 |
* <HR>PRE</HR> <HR>POST</HR> |
|
38 |
* |
|
39 |
* @author ulrich |
|
40 |
*/ |
|
41 |
public class PrePostFilter extends MyGenericFilter { |
|
42 |
|
|
43 |
private static final Logger logger = Logger.getLogger(PrePostFilter.class.getName()); |
|
44 |
|
|
45 |
public void doFilter(final ServletRequest request, |
|
46 |
final ServletResponse response, |
|
47 |
FilterChain chain) |
|
48 |
throws IOException, ServletException { |
|
49 |
HttpServletRequest hr = (HttpServletRequest) request; |
|
50 |
logger.info("requestURL: " + hr.getRequestURL().toString()); |
|
51 |
logger.info("ContextPath: " + hr.getContextPath()); |
|
52 |
logger.info("ServletPath: " + hr.getServletPath()); |
|
53 |
logger.info("PathInfo: " + hr.getPathInfo()); |
|
54 |
OutputStream out = response.getOutputStream(); |
|
55 |
out.write(new String("<HR>PRE<HR>").getBytes()); |
|
56 |
GenericResponseWrapper wrapper = |
|
57 |
new GenericResponseWrapper((HttpServletResponse) response); |
|
58 |
chain.doFilter(request,wrapper); |
|
59 |
out.write(wrapper.getData()); |
|
60 |
out.write(new String("<HR>POST<HR>").getBytes()); |
|
61 |
out.close(); |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
/* |
|
66 |
|
|
67 |
MarkdownProcessor p = new MarkdownProcessor(); |
|
68 |
response.getWriter().write(p.markdown(responseContent)); |
|
69 |
|
|
70 |
*/ |
|
71 |
} |