From c77b91a0713762b3aaba08fefd01f424d5ca80ce Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 12 Jun 2012 00:31:50 +0200 Subject: [PATCH] WIP: Versuch den StaticTest zu reparieren... --- examples/pom.xml | 2 +- .../static/src/main/webapp/WEB-INF/web.xml | 16 ++++++ pom.xml | 1 + test/pom.xml | 5 ++ .../halbekunst/juplo/test/HttpTestCase.java | 2 + .../LoggingHttpServletResponseWrapper.java | 49 +++++++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/examples/pom.xml b/examples/pom.xml index 2dd33ce4..cf45de55 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -100,7 +100,7 @@ org.mortbay.jetty jetty-maven-plugin - 8.0.1.v20110908 + ${jetty.version} diff --git a/examples/static/src/main/webapp/WEB-INF/web.xml b/examples/static/src/main/webapp/WEB-INF/web.xml index 9e0b5040..288754d4 100644 --- a/examples/static/src/main/webapp/WEB-INF/web.xml +++ b/examples/static/src/main/webapp/WEB-INF/web.xml @@ -43,4 +43,20 @@ /static + + + + + default + org.eclipse.jetty.servlet.DefaultServlet + + + + + + + default + / + + diff --git a/pom.xml b/pom.xml index 97cb6a2e..cc305ec0 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ 1.6.11 1.7.1 6.0.29 + 8.1.4.v20120524 1.0 1.2 4.8.1 diff --git a/test/pom.xml b/test/pom.xml index d13cdbf4..7c3a4b48 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -42,6 +42,11 @@ ${springframework.version} provided + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + diff --git a/test/src/main/java/de/halbekunst/juplo/test/HttpTestCase.java b/test/src/main/java/de/halbekunst/juplo/test/HttpTestCase.java index 76c46468..cbf99461 100644 --- a/test/src/main/java/de/halbekunst/juplo/test/HttpTestCase.java +++ b/test/src/main/java/de/halbekunst/juplo/test/HttpTestCase.java @@ -8,6 +8,7 @@ import java.io.File; import java.util.Enumeration; import javax.servlet.http.HttpServletRequest; import org.junit.Before; +import org.eclipse.jetty.servlet.DefaultServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +39,7 @@ public abstract class HttpTestCase { @Before public void init() throws Exception { sr = new ServletRunner(config, ""); // Dies ist der einzige Konstruktor, der die Context-Root der Webapp im Testfall korrekt initialisiert :/ + sr.registerServlet("default", DefaultServlet.class.getName()); client = sr.newClient(); } diff --git a/test/src/main/java/de/halbekunst/juplo/test/LoggingHttpServletResponseWrapper.java b/test/src/main/java/de/halbekunst/juplo/test/LoggingHttpServletResponseWrapper.java index f654f2a7..075e6a79 100644 --- a/test/src/main/java/de/halbekunst/juplo/test/LoggingHttpServletResponseWrapper.java +++ b/test/src/main/java/de/halbekunst/juplo/test/LoggingHttpServletResponseWrapper.java @@ -3,6 +3,7 @@ package de.halbekunst.juplo.test; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.util.Collection; import java.util.Date; import java.util.Locale; import javax.servlet.ServletOutputStream; @@ -283,6 +284,54 @@ public class LoggingHttpServletResponseWrapper implements HttpServletResponse { return locale; } + @Override + public int getStatus() { + Integer status = response.getStatus(); + log.trace("{} -- status: {}", no, status); + return status; + } + + @Override + public String getHeader(String name) { + String value = response.getHeader(name); + log.trace("{} -- header \"{}\": {}", new Object[] { no, name, value }); + return value; + } + + @Override + public Collection getHeaders(String name) { + Collection values = response.getHeaders(name); + if (log.isTraceEnabled()) { + StringBuilder builder = new StringBuilder(); + builder.append(no); + builder.append(" -- headers \""); + builder.append(name); + builder.append("\":"); + for (String value : values) { + builder.append(' '); + builder.append(value); + } + log.trace(builder.toString()); + } + return values; + } + + @Override + public Collection getHeaderNames() { + Collection values = response.getHeaderNames(); + if (log.isTraceEnabled()) { + StringBuilder builder = new StringBuilder(); + builder.append(no); + builder.append(" -- header-names:"); + for (String value : values) { + builder.append(' '); + builder.append(value); + } + log.trace(builder.toString()); + } + return values; + } + class CountingServletOutputStream extends ServletOutputStream { -- 2.20.1