1 package de.halbekunst.juplo.cachecontrol;
3 import java.io.IOException;
5 import javax.servlet.RequestDispatcher;
6 import javax.servlet.ServletException;
7 import javax.servlet.ServletOutputStream;
8 import javax.servlet.http.HttpServlet;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 import org.junit.Ignore;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
20 public class TestServlet extends HttpServlet {
21 private final static Logger log = LoggerFactory.getLogger(TestServlet.class);
23 private static final String FORWARDED = TestServlet.class.getName() + ".FORWARDED";
24 private static final String INCLUDED = TestServlet.class.getName() + ".INCLUDED";
27 protected long getLastModified(HttpServletRequest req) {
29 /** Der Reqeust-Parameter "lm" wird als Wert für Last-Modified zurückgegeben */
30 return Long.parseLong(req.getParameter("l"));
38 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
39 /** Angeforderte Header setzen */
40 Map<String, String[]> map = request.getParameterMap();
41 for (String param : map.keySet()) {
42 if (param.equals("n") || param.equals("l") || param.equals("f") || param.equals("i"))
45 * Alle Request-Parameter außer die Sonder-Parameter "n" und "lm"
46 * werden als Schlüssel/Wert-Paare für die Antwort-Header interpretiert!
48 for (String value : map.get(param))
49 response.setHeader(param, value);
55 * Wenn der Parameter n gesetzt ist, wird ein Antwort-Body erzeugt, der
56 * exakt die Anzahl der geforderten Bytes enthält.
58 n = Integer.parseInt(request.getParameter("n"));
61 log.debug("GET {} bytes: {}", n, request.getRequestURI());
62 ServletOutputStream out = response.getOutputStream();
63 for (int i=0; i<n; i++)
64 out.write(i%2 + 48); /** ASCII-Codes für "0" und "1" */
66 if (request.getParameter("i") != null && request.getAttribute(INCLUDED) == null) {
67 for (String include : request.getParameterValues("i")) {
68 RequestDispatcher dispatcher = request.getRequestDispatcher(include);
69 request.setAttribute(INCLUDED, include);
70 dispatcher.include(request, response);
74 if (request.getParameter("f") != null && request.getAttribute(FORWARDED) == null) {
75 String forward = request.getParameter("f");
76 request.setAttribute(FORWARDED, forward);
77 RequestDispatcher dispatcher = request.getRequestDispatcher(forward);
78 dispatcher.forward(request, response);