From 5d90578261abb35e4c85162f411b6d63df043f6d Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 2 Aug 2012 09:53:33 +0200 Subject: [PATCH] =?utf8?q?JSP-Seite=20und=20Servlet=20erg=C3=A4nzt,=20die?= =?utf8?q?=20eine=20Exception=20werfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Wenn es zu einer Exception kommt, nachdem die ersten Bytes der Antwort gesendet wurden, dekodiert Jetty die Antwort offensichtlich falsch, da es die Fehlermeldung an dem geöffneten Stream vorbei ergänzt. Unter Tomcat hingegen, greifen die Mechanismen wie gewohnt und die Fehler-Antwort ist korrekt GZIP-enkodiert (falls gewünscht). TODO: Es ist noch nicht klar, ob hier ein Fehlverhalten von Jetty vorliegt, oder von Juplo! Das Verhalten von Tomcat wird auch zweideutig, wenn man die länge der zu erzeugenden Nachrricht extrem verlängert: der Client erhält dann eine unvollständige Antwort zurück, in der weder die Daten enthalten sind, die vor der Exception eigentlich übertragen worden sein sollten, noch die Fehlermeldung, die Tomcat nach der Exception anhängen sollte! --- examples/jsp/src/main/webapp/faulty-page.jsp | 21 +++++++++ examples/jsp/src/main/webapp/index.html | 1 + .../cachecontrol/examples/FaultyServlet.java | 43 ++++++++++++++++++ .../servlet/src/main/webapp/WEB-INF/web.xml | 16 +++++++ examples/servlet/src/main/webapp/index.html | 14 ++++++ .../examples/spring/FaultyController.java | 44 +++++++++++++++++++ .../main/webapp/WEB-INF/views/faulty-page.jsp | 17 +++++++ .../src/main/webapp/WEB-INF/views/index.jsp | 2 + 8 files changed, 158 insertions(+) create mode 100644 examples/jsp/src/main/webapp/faulty-page.jsp create mode 100644 examples/servlet/src/main/java/de/halbekunst/cachecontrol/examples/FaultyServlet.java create mode 100644 examples/spring/src/main/java/de/halbekunst/juplo/examples/spring/FaultyController.java create mode 100644 examples/spring/src/main/webapp/WEB-INF/views/faulty-page.jsp diff --git a/examples/jsp/src/main/webapp/faulty-page.jsp b/examples/jsp/src/main/webapp/faulty-page.jsp new file mode 100644 index 00000000..e40c2130 --- /dev/null +++ b/examples/jsp/src/main/webapp/faulty-page.jsp @@ -0,0 +1,21 @@ +<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %> +<%@taglib uri="/WEB-INF/c.tld" prefix="c"%> + + + + + + Faulty Page + + +

Faulty Page

+

+ This page will raise an error. + after a while! +

+

+ Ecactly, NOW: + <% if (true) throw new RuntimeException("Oh no!"); %> +

+ + diff --git a/examples/jsp/src/main/webapp/index.html b/examples/jsp/src/main/webapp/index.html index c8c218d1..2246263f 100644 --- a/examples/jsp/src/main/webapp/index.html +++ b/examples/jsp/src/main/webapp/index.html @@ -11,6 +11,7 @@
  • A really simple JSP-page
  • A JSP-page with several includes
  • A JSP-page with a forward to /simple-page.jsp
  • +
  • A JSP-page with raises an error
  • diff --git a/examples/servlet/src/main/java/de/halbekunst/cachecontrol/examples/FaultyServlet.java b/examples/servlet/src/main/java/de/halbekunst/cachecontrol/examples/FaultyServlet.java new file mode 100644 index 00000000..bc382db9 --- /dev/null +++ b/examples/servlet/src/main/java/de/halbekunst/cachecontrol/examples/FaultyServlet.java @@ -0,0 +1,43 @@ +package de.halbekunst.cachecontrol.examples; + +import java.io.IOException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author kai + */ +public class FaultyServlet extends HttpServlet { + private final static Logger log = LoggerFactory.getLogger(FaultyServlet.class); + private final static long lastModified = System.currentTimeMillis(); + + + @Override + protected long getLastModified(HttpServletRequest req) { + return lastModified; + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + int n = 0; + try { + /** + * Wenn der Parameter n gesetzt ist, wird ein Antwort-Body erzeugt, der + * exakt die Anzahl der geforderten Bytes enthält. + */ + n = Integer.parseInt(request.getParameter("n")); + } + catch(Exception e) {} + log.debug("Error will be risen after {} bytes: {}", n, request.getRequestURI()); + ServletOutputStream out = response.getOutputStream(); + for (int i=0; ilogger /test-servlet + + logger + /faulty-servlet + accelerator /test-servlet + + accelerator + /faulty-servlet + @@ -50,6 +58,10 @@ test-servlet de.halbekunst.juplo.test.TestServlet + + faulty-servlet + de.halbekunst.cachecontrol.examples.FaultyServlet + @@ -58,5 +70,9 @@ test-servlet /test-servlet + + faulty-servlet + /faulty-servlet + diff --git a/examples/servlet/src/main/webapp/index.html b/examples/servlet/src/main/webapp/index.html index 766627b4..c08ba7c0 100644 --- a/examples/servlet/src/main/webapp/index.html +++ b/examples/servlet/src/main/webapp/index.html @@ -22,5 +22,19 @@
  • 8192-Bytes-Answer
  • 16384-Bytes-Answer
  • + diff --git a/examples/spring/src/main/java/de/halbekunst/juplo/examples/spring/FaultyController.java b/examples/spring/src/main/java/de/halbekunst/juplo/examples/spring/FaultyController.java new file mode 100644 index 00000000..21ec8236 --- /dev/null +++ b/examples/spring/src/main/java/de/halbekunst/juplo/examples/spring/FaultyController.java @@ -0,0 +1,44 @@ +package de.halbekunst.juplo.examples.spring; + +import de.halbekunst.juplo.cachecontrol.annotations.CacheSeconds; +import de.halbekunst.juplo.cachecontrol.annotations.Cacheable; +import de.halbekunst.juplo.cachecontrol.annotations.LastModified; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import javax.servlet.http.HttpServletRequest; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + + +/** + * Simple Spring-MVC Controller + * @author kai + */ +@Controller +@Cacheable(eager=true) +public class FaultyController +{ + public static final String ACCESS_TIME = FaultyController.class.getCanonicalName() + ".ACCESS_TIME"; + public static final Integer DEFAULT_MAX_AGE = 60; + + private final static long lastModified = System.currentTimeMillis(); + + @CacheSeconds + public int cacheSeconds(HttpServletRequest request) { + return DEFAULT_MAX_AGE; + } + + @LastModified + public long lastModified(HttpServletRequest request) { + return lastModified; + } + + @RequestMapping("/faulty-controller.html") + public ModelAndView process(HttpServletRequest request) + { + throw new RuntimeException("Oh, no!"); + } +} \ No newline at end of file diff --git a/examples/spring/src/main/webapp/WEB-INF/views/faulty-page.jsp b/examples/spring/src/main/webapp/WEB-INF/views/faulty-page.jsp new file mode 100644 index 00000000..8718f54f --- /dev/null +++ b/examples/spring/src/main/webapp/WEB-INF/views/faulty-page.jsp @@ -0,0 +1,17 @@ +<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %> + + + + + + Simple Page + + +

    Faulty Page

    +

    This page will raise an error!

    +

    + Ecactly, NOW: + <% if (true) throw new RuntimeException("Oh no!"); %> +

    + + diff --git a/examples/spring/src/main/webapp/WEB-INF/views/index.jsp b/examples/spring/src/main/webapp/WEB-INF/views/index.jsp index f86ca57f..a329acd3 100644 --- a/examples/spring/src/main/webapp/WEB-INF/views/index.jsp +++ b/examples/spring/src/main/webapp/WEB-INF/views/index.jsp @@ -10,6 +10,8 @@

    This page was delivered via SPRING!

    Note:

    -- 2.20.1