JSP-Seite und Servlet ergänzt, die eine Exception werfen
authorKai Moritz <kai@coolibri.de>
Thu, 2 Aug 2012 07:53:33 +0000 (09:53 +0200)
committerKai Moritz <kai@coolibri.de>
Thu, 23 Aug 2012 19:47:16 +0000 (21:47 +0200)
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 [new file with mode: 0644]
examples/jsp/src/main/webapp/index.html
examples/servlet/src/main/java/de/halbekunst/cachecontrol/examples/FaultyServlet.java [new file with mode: 0644]
examples/servlet/src/main/webapp/WEB-INF/web.xml
examples/servlet/src/main/webapp/index.html
examples/spring/src/main/java/de/halbekunst/juplo/examples/spring/FaultyController.java [new file with mode: 0644]
examples/spring/src/main/webapp/WEB-INF/views/faulty-page.jsp [new file with mode: 0644]
examples/spring/src/main/webapp/WEB-INF/views/index.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 (file)
index 0000000..e40c213
--- /dev/null
@@ -0,0 +1,21 @@
+<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %>
+<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>Faulty Page</title>
+  </head>
+  <body>
+    <h1>Faulty Page</h1>
+    <p>
+      This page will raise an error<c:forEach begin="1" end="${param['n']}" step="1">.</c:forEach>
+      after a while!
+    </p>
+    <p>
+      <strong>Ecactly, NOW:</strong>
+      <% if (true) throw new RuntimeException("Oh no!"); %>
+    </p>
+  </body>
+</html>
index c8c218d..2246263 100644 (file)
@@ -11,6 +11,7 @@
       <li><a href="/simple-page.jsp">A really simple JSP-page</a></li>
       <li><a href="/page-with-include.jsp">A JSP-page with several includes</a></li>
       <li><a href="/page-with-forward.jsp">A JSP-page with a forward to /simple-page.jsp</a></li>
+      <li><a href="/faulty-page.jsp?n=8822">A JSP-page with raises an error</a></li>
     </ul>
   </body>
 </html>
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 (file)
index 0000000..bc382db
--- /dev/null
@@ -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; i<n; i++)
+      out.write(i%2 + 48); /** ASCII-Codes für "0" und "1" */
+    log.debug("Failing.... NOW:");
+    throw new RuntimeException("Oh, no!");
+  }
+}
index 53de033..dc503d0 100644 (file)
     <filter-name>logger</filter-name>
     <url-pattern>/test-servlet</url-pattern>
   </filter-mapping>
+  <filter-mapping>
+    <filter-name>logger</filter-name>
+    <url-pattern>/faulty-servlet</url-pattern>
+  </filter-mapping>
 
   <filter-mapping>
     <filter-name>accelerator</filter-name>
     <url-pattern>/test-servlet</url-pattern>
   </filter-mapping>
+  <filter-mapping>
+    <filter-name>accelerator</filter-name>
+    <url-pattern>/faulty-servlet</url-pattern>
+  </filter-mapping>
 
 
   <!-- Servlet-Definitions -->
     <servlet-name>test-servlet</servlet-name>
     <servlet-class>de.halbekunst.juplo.test.TestServlet</servlet-class>
   </servlet>
+  <servlet>
+    <servlet-name>faulty-servlet</servlet-name>
+    <servlet-class>de.halbekunst.cachecontrol.examples.FaultyServlet</servlet-class>
+  </servlet>
 
 
   <!-- Servlet-Mappings -->
@@ -58,5 +70,9 @@
     <servlet-name>test-servlet</servlet-name>
     <url-pattern>/test-servlet</url-pattern>
   </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>faulty-servlet</servlet-name>
+    <url-pattern>/faulty-servlet</url-pattern>
+  </servlet-mapping>
 
 </web-app>
index 766627b..c08ba7c 100644 (file)
       <li><a href="/test-servlet?n=8192">8192-Bytes-Answer</a></li>
       <li><a href="/test-servlet?n=16384">16384-Bytes-Answer</a></li>
     </ul>
+    <ul>
+      <li><a href="/faulty-servlet">Empty Faulty Answer</a></li>
+      <li><a href="/faulty-servlet?n=16">Error after 16 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=32">Error after 32 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=64">Error after 64 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=128">Error after 128 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=256">Error after 256 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=512">Error after 512 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=1024">Error after 1024 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=2048">Error after 2048 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=4096">Error after 4096 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=8192">Error after 8192 Bytes</a></li>
+      <li><a href="/faulty-servlet?n=16384">Error after 16384 Bytes</a></li>
+    </ul>
   </body>
 </html>
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 (file)
index 0000000..21ec823
--- /dev/null
@@ -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 (file)
index 0000000..8718f54
--- /dev/null
@@ -0,0 +1,17 @@
+<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>Simple Page</title>
+  </head>
+  <body>
+    <h1>Faulty Page</h1>
+    <p>This page will raise an error!</p>
+    <p>
+      <strong>Ecactly, NOW:</strong>
+      <% if (true) throw new RuntimeException("Oh no!"); %>
+    </p>
+  </body>
+</html>
index f86ca57..a329acd 100644 (file)
@@ -10,6 +10,8 @@
     <ul>
       <li><a href="/spring-page.html">Simple Spring-View</a></li>
       <li><a href="/spring-controller.html">Simple Spring-Controller</a></li>
+      <li><a href="/faulty-page.html">Spring-View, which will raise an error</a></li>
+      <li><a href="/faulty-controller.html">Spring-Controller, which will raise an error</a></li>
     </ul>
     <p>This page was delivered via SPRING!</p>
     <h2>Note:</h2>