From 8e399db0b0860812452868e08e20ee82ddf1f528 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 4 Jun 2012 10:38:30 +0200 Subject: [PATCH] =?utf8?q?Test-Beispiele=20=C3=BCberarbeitet=20und=20nach?= =?utf8?q?=20verwendeter=20Technik=20aufgeteilt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- examples/jsp/catalog.xml | 1 + examples/jsp/pom.xml | 2 +- examples/jsp/src/main/resources/config.xml | 12 ---- examples/jsp/src/main/webapp/WEB-INF/c.tld | 6 ++ examples/jsp/src/main/webapp/WEB-INF/web.xml | 48 ------------- examples/jsp/src/main/webapp/index.html | 28 +------- .../jsp/src/main/webapp/page-with-include.jsp | 1 - examples/jsp/src/main/webapp/simple-page.jsp | 5 +- .../examples/{jsp => }/JspTest.java | 9 +-- examples/pom.xml | 6 +- examples/servlet/jetty.sh | 11 +++ examples/servlet/pom.xml | 17 +++++ .../servlet/src/main/resources/config.xml | 41 +++++++++++ examples/servlet/src/main/resources/log4j.xml | 21 ++++++ .../servlet/src/main/webapp/WEB-INF/web.xml | 62 +++++++++++++++++ examples/servlet/src/main/webapp/index.html | 26 +++++++ .../cachecontrol/examples/ServletTest.java | 28 ++++++++ examples/servlet/tomcat.sh | 11 +++ examples/spring/jetty.sh | 11 +++ examples/spring/pom.xml | 17 +++++ examples/spring/src/main/resources/config.xml | 41 +++++++++++ examples/spring/src/main/resources/log4j.xml | 25 +++++++ .../webapp/WEB-INF/views/controller-view.jsp | 43 ++++++++++++ .../src/main/webapp/WEB-INF/views/index.jsp | 32 +++++++++ .../webapp/WEB-INF/views/spring-page.jsp} | 3 +- .../spring/src/main/webapp/WEB-INF/web.xml | 68 +++++++++++++++++++ examples/spring/src/main/webapp/index.jsp | 8 +++ .../cachecontrol/examples/SpringMVCTest.java | 29 ++++++++ examples/spring/tomcat.sh | 11 +++ examples/static/jetty.sh | 11 +++ examples/static/pom.xml | 26 +++++++ examples/static/src/main/resources/config.xml | 29 ++++++++ examples/static/src/main/resources/log4j.xml | 21 ++++++ .../static/src/main/webapp/WEB-INF/web.xml | 63 +++++++++++++++++ examples/static/src/main/webapp/index.html | 15 ++++ .../static/src/main/webapp/static/page.html | 13 ++++ .../src/main/webapp/static/stylesheets.css} | 0 .../cachecontrol/examples/StaticTest.java | 28 ++++++++ .../eclipse/jetty/servlet/DefaultServlet.java | 28 ++++++++ pom.xml | 2 + test/pom.xml | 5 ++ .../LoggingHttpServletResponseWrapper.java | 49 +++++++++++++ 42 files changed, 810 insertions(+), 103 deletions(-) rename examples/jsp/src/test/java/de/halbekunst/cachecontrol/examples/{jsp => }/JspTest.java (79%) create mode 100755 examples/servlet/jetty.sh create mode 100644 examples/servlet/pom.xml create mode 100644 examples/servlet/src/main/resources/config.xml create mode 100644 examples/servlet/src/main/resources/log4j.xml create mode 100644 examples/servlet/src/main/webapp/WEB-INF/web.xml create mode 100644 examples/servlet/src/main/webapp/index.html create mode 100644 examples/servlet/src/test/java/de/halbekunst/cachecontrol/examples/ServletTest.java create mode 100755 examples/servlet/tomcat.sh create mode 100755 examples/spring/jetty.sh create mode 100644 examples/spring/pom.xml create mode 100644 examples/spring/src/main/resources/config.xml create mode 100644 examples/spring/src/main/resources/log4j.xml create mode 100644 examples/spring/src/main/webapp/WEB-INF/views/controller-view.jsp create mode 100644 examples/spring/src/main/webapp/WEB-INF/views/index.jsp rename examples/{jsp/src/main/webapp/WEB-INF/views/simple-page.jsp => spring/src/main/webapp/WEB-INF/views/spring-page.jsp} (73%) create mode 100644 examples/spring/src/main/webapp/WEB-INF/web.xml create mode 100644 examples/spring/src/main/webapp/index.jsp create mode 100644 examples/spring/src/test/java/de/halbekunst/cachecontrol/examples/SpringMVCTest.java create mode 100755 examples/spring/tomcat.sh create mode 100755 examples/static/jetty.sh create mode 100644 examples/static/pom.xml create mode 100644 examples/static/src/main/resources/config.xml create mode 100644 examples/static/src/main/resources/log4j.xml create mode 100644 examples/static/src/main/webapp/WEB-INF/web.xml create mode 100644 examples/static/src/main/webapp/index.html create mode 100644 examples/static/src/main/webapp/static/page.html rename examples/{jsp/src/main/webapp/default.css => static/src/main/webapp/static/stylesheets.css} (100%) create mode 100644 examples/static/src/test/java/de/halbekunst/cachecontrol/examples/StaticTest.java create mode 100644 examples/static/src/test/java/org/eclipse/jetty/servlet/DefaultServlet.java diff --git a/examples/jsp/catalog.xml b/examples/jsp/catalog.xml index 218f47c2..94e80903 100644 --- a/examples/jsp/catalog.xml +++ b/examples/jsp/catalog.xml @@ -1,4 +1,5 @@ + \ No newline at end of file diff --git a/examples/jsp/pom.xml b/examples/jsp/pom.xml index d9f3c6a2..7eaed0bd 100644 --- a/examples/jsp/pom.xml +++ b/examples/jsp/pom.xml @@ -10,7 +10,7 @@ 2.0-SNAPSHOT - ${pom.parent.artifactId}-jsp + juplo-examples-jsp war Juplo - Examples: JSP-Pages diff --git a/examples/jsp/src/main/resources/config.xml b/examples/jsp/src/main/resources/config.xml index b7a4892e..e414ce93 100644 --- a/examples/jsp/src/main/resources/config.xml +++ b/examples/jsp/src/main/resources/config.xml @@ -26,16 +26,4 @@ - - - - - - - - - - - - diff --git a/examples/jsp/src/main/webapp/WEB-INF/c.tld b/examples/jsp/src/main/webapp/WEB-INF/c.tld index 8c447f59..4b85b448 100644 --- a/examples/jsp/src/main/webapp/WEB-INF/c.tld +++ b/examples/jsp/src/main/webapp/WEB-INF/c.tld @@ -1,5 +1,11 @@ + *.jsp - - accelerator - *.html - accelerator *.jsp - - accelerator - *.css - - - accelerator - /test-servlet - - - accelerator - /spring/* - - - - - - - test-servlet - de.halbekunst.juplo.test.TestServlet - - - - dispatcher-servlet - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - - - - 1 - - - - - - - test-servlet - /test-servlet - - - - dispatcher-servlet - /spring/* - diff --git a/examples/jsp/src/main/webapp/index.html b/examples/jsp/src/main/webapp/index.html index cd95f2c5..c8c218d1 100644 --- a/examples/jsp/src/main/webapp/index.html +++ b/examples/jsp/src/main/webapp/index.html @@ -3,38 +3,14 @@ - Static Page - + JSP Examples -

Static Page

-

This page is a static HTML-page

-

At the same time, it gives an overview over all tests...

-

JSP-Pages

+

JSP Examples

-

Static Content

- -

Dynamic Servlet-Answers

- diff --git a/examples/jsp/src/main/webapp/page-with-include.jsp b/examples/jsp/src/main/webapp/page-with-include.jsp index ba581a46..3347af77 100644 --- a/examples/jsp/src/main/webapp/page-with-include.jsp +++ b/examples/jsp/src/main/webapp/page-with-include.jsp @@ -6,7 +6,6 @@ Page with include -

Hello World!

diff --git a/examples/jsp/src/main/webapp/simple-page.jsp b/examples/jsp/src/main/webapp/simple-page.jsp index 880d7611..99d92d73 100644 --- a/examples/jsp/src/main/webapp/simple-page.jsp +++ b/examples/jsp/src/main/webapp/simple-page.jsp @@ -5,10 +5,9 @@ Simple Page - -

Hello World!

-

This is a really simple page...

+

Simple Page

+

This page is a simple jsp-page

diff --git a/examples/jsp/src/test/java/de/halbekunst/cachecontrol/examples/jsp/JspTest.java b/examples/jsp/src/test/java/de/halbekunst/cachecontrol/examples/JspTest.java similarity index 79% rename from examples/jsp/src/test/java/de/halbekunst/cachecontrol/examples/jsp/JspTest.java rename to examples/jsp/src/test/java/de/halbekunst/cachecontrol/examples/JspTest.java index 9861068b..a7331b63 100644 --- a/examples/jsp/src/test/java/de/halbekunst/cachecontrol/examples/jsp/JspTest.java +++ b/examples/jsp/src/test/java/de/halbekunst/cachecontrol/examples/JspTest.java @@ -1,4 +1,4 @@ -package de.halbekunst.cachecontrol.examples.jsp; +package de.halbekunst.cachecontrol.examples; import de.halbekunst.juplo.test.HttpTestCase; import com.meterware.httpunit.WebResponse; @@ -40,11 +40,4 @@ public class JspTest extends HttpTestCase { log.info("Title:\t\t{}", response.getTitle()); log.debug("Text:\t\t{}", response.getText()); } - - @Test - public void testStaticContent() throws Exception { - WebResponse response = executeRequest("http://localhost:8080/default.css"); - log.info("Title:\t\t{}", response.getTitle()); - log.debug("Text:\t\t{}", response.getText()); - } } diff --git a/examples/pom.xml b/examples/pom.xml index 28a64a6b..cf45de55 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -16,6 +16,9 @@ jsp + static + servlet + spring @@ -77,7 +80,6 @@ runtime - ${pom.parent.groupId} @@ -98,7 +100,7 @@ org.mortbay.jetty jetty-maven-plugin - 8.0.1.v20110908 + ${jetty.version} diff --git a/examples/servlet/jetty.sh b/examples/servlet/jetty.sh new file mode 100755 index 00000000..4950796b --- /dev/null +++ b/examples/servlet/jetty.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# + +# OutOfMemoryException beim "mvn jetty:run" umgehen und +# Parameter zum nachträglichen anhängen eines Debuggers +# setzen +export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n" + +rm -v src/main/webapp/WEB-INF/lib/juplo* + +mvn jetty:run diff --git a/examples/servlet/pom.xml b/examples/servlet/pom.xml new file mode 100644 index 00000000..313fe7c1 --- /dev/null +++ b/examples/servlet/pom.xml @@ -0,0 +1,17 @@ + + + + 4.0.0 + + + de.halbekunst + juplo-examples + 2.0-SNAPSHOT + + + juplo-examples-servlet + war + Juplo - Examples: Servlet + + diff --git a/examples/servlet/src/main/resources/config.xml b/examples/servlet/src/main/resources/config.xml new file mode 100644 index 00000000..b7a4892e --- /dev/null +++ b/examples/servlet/src/main/resources/config.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/servlet/src/main/resources/log4j.xml b/examples/servlet/src/main/resources/log4j.xml new file mode 100644 index 00000000..d3414bdb --- /dev/null +++ b/examples/servlet/src/main/resources/log4j.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/servlet/src/main/webapp/WEB-INF/web.xml b/examples/servlet/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..53de033a --- /dev/null +++ b/examples/servlet/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,62 @@ + + + + + + + contextConfigLocation + classpath:/config.xml + + + + + + + org.springframework.web.context.ContextLoaderListener + + + + + + + accelerator + de.halbekunst.juplo.cachecontrol.AcceleratorFilter + + + + logger + de.halbekunst.juplo.test.LoggingHttpServletResponseFilter + + + + + + + logger + /test-servlet + + + + accelerator + /test-servlet + + + + + + + test-servlet + de.halbekunst.juplo.test.TestServlet + + + + + + + test-servlet + /test-servlet + + + diff --git a/examples/servlet/src/main/webapp/index.html b/examples/servlet/src/main/webapp/index.html new file mode 100644 index 00000000..766627b4 --- /dev/null +++ b/examples/servlet/src/main/webapp/index.html @@ -0,0 +1,26 @@ + + + + + + Servlet Examples + + +

Servlet Examples

+

This page is a static HTML-page

+ + + diff --git a/examples/servlet/src/test/java/de/halbekunst/cachecontrol/examples/ServletTest.java b/examples/servlet/src/test/java/de/halbekunst/cachecontrol/examples/ServletTest.java new file mode 100644 index 00000000..32b13e11 --- /dev/null +++ b/examples/servlet/src/test/java/de/halbekunst/cachecontrol/examples/ServletTest.java @@ -0,0 +1,28 @@ +package de.halbekunst.cachecontrol.examples; + +import de.halbekunst.juplo.test.HttpTestCase; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author kai + */ +public class ServletTest extends HttpTestCase { + + private static final Logger log = LoggerFactory.getLogger(ServletTest.class); + + + public ServletTest() { + super("src/main/webapp/WEB-INF/web.xml"); + } + + + @Test + public void test() throws Exception { +// WebResponse response = executeRequest("http://localhost:8080/simple-page.jsp"); +// log.info("Title:\t\t{}", response.getTitle()); +// log.debug("Text:\t\t{}", response.getText()); + } +} diff --git a/examples/servlet/tomcat.sh b/examples/servlet/tomcat.sh new file mode 100755 index 00000000..4378a128 --- /dev/null +++ b/examples/servlet/tomcat.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# + +# OutOfMemoryException beim "mvn jetty:run" umgehen und +# Parameter zum nachträglichen anhängen eines Debuggers +# setzen +export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n" + +rm -v src/main/webapp/WEB-INF/lib/juplo* + +mvn tomcat:run-war diff --git a/examples/spring/jetty.sh b/examples/spring/jetty.sh new file mode 100755 index 00000000..4950796b --- /dev/null +++ b/examples/spring/jetty.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# + +# OutOfMemoryException beim "mvn jetty:run" umgehen und +# Parameter zum nachträglichen anhängen eines Debuggers +# setzen +export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n" + +rm -v src/main/webapp/WEB-INF/lib/juplo* + +mvn jetty:run diff --git a/examples/spring/pom.xml b/examples/spring/pom.xml new file mode 100644 index 00000000..90010cce --- /dev/null +++ b/examples/spring/pom.xml @@ -0,0 +1,17 @@ + + + + 4.0.0 + + + de.halbekunst + juplo-examples + 2.0-SNAPSHOT + + + juplo-examples-spring + war + Juplo - Examples: Spring-MVC + + diff --git a/examples/spring/src/main/resources/config.xml b/examples/spring/src/main/resources/config.xml new file mode 100644 index 00000000..b7a4892e --- /dev/null +++ b/examples/spring/src/main/resources/config.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/spring/src/main/resources/log4j.xml b/examples/spring/src/main/resources/log4j.xml new file mode 100644 index 00000000..13ec197b --- /dev/null +++ b/examples/spring/src/main/resources/log4j.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/spring/src/main/webapp/WEB-INF/views/controller-view.jsp b/examples/spring/src/main/webapp/WEB-INF/views/controller-view.jsp new file mode 100644 index 00000000..26abdbdb --- /dev/null +++ b/examples/spring/src/main/webapp/WEB-INF/views/controller-view.jsp @@ -0,0 +1,43 @@ +<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %> +<%@page import="java.util.Map" %> +<%@page import="java.util.Date"%> + + + + + + Page, that is handled by a controller + + + <% Map requests = (Map)request.getAttribute("requests"); + if (requests == null) { %> +

This page associated with a controller and should be viewed as such!

+

Go to: /spring-controller.html

+ <% } else { %> +

Controlled Page

+
+ + <%= request.getParameter("max-age") %><% } %>" /> +
+
+

(Uncached) requests so far:

+
    + <% for(Map.Entry entry : requests.entrySet()) { %> +
  1. + <%= entry.getKey() %>: + <% if (entry.getValue().equals("")) { %> + No parameters... + <% } else { %> + + <% for (String parameter : entry.getValue().split("&")) { %> + <%= parameter %> + <% } %> + + <% } %> +
  2. + <% } %> +
+ <% } %> +

This page was delivered via SPRING!

+ + diff --git a/examples/spring/src/main/webapp/WEB-INF/views/index.jsp b/examples/spring/src/main/webapp/WEB-INF/views/index.jsp new file mode 100644 index 00000000..020f6ee7 --- /dev/null +++ b/examples/spring/src/main/webapp/WEB-INF/views/index.jsp @@ -0,0 +1,32 @@ + + + + + + Simple Spring-MVC Examples + + +

Simple Spring-MVC Examples

+ +

This page was delivered via SPRING!

+

Note:

+

+ Since the org.springframework.web.servlet.DispatcherServlet + ist configured to handle all *.html-requests, the path + /index.html points to a view. +

+

+ Therefore, this page must be stored under + /WEB-INF/views/index.jsp in order to be served as + /index.html +

+

+ Additionatly, a file /index.jsp in the root-directory of + the webappliction is needed, to forward unqualified requests + (like http://HOSTNAME/) to the welcome-page served by + the Spring-Dispatcher-Servlet. +

+ + diff --git a/examples/jsp/src/main/webapp/WEB-INF/views/simple-page.jsp b/examples/spring/src/main/webapp/WEB-INF/views/spring-page.jsp similarity index 73% rename from examples/jsp/src/main/webapp/WEB-INF/views/simple-page.jsp rename to examples/spring/src/main/webapp/WEB-INF/views/spring-page.jsp index 194cac5b..892bf1a6 100644 --- a/examples/jsp/src/main/webapp/WEB-INF/views/simple-page.jsp +++ b/examples/spring/src/main/webapp/WEB-INF/views/spring-page.jsp @@ -5,11 +5,10 @@ Simple Page -

Hello World!

This is a really simple page...

-

This version of a really simple page was delivered via SPRING!

+

This page was delivered via SPRING!

diff --git a/examples/spring/src/main/webapp/WEB-INF/web.xml b/examples/spring/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..4f26f015 --- /dev/null +++ b/examples/spring/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,68 @@ + + + + + + + contextConfigLocation + classpath:/config.xml + + + + + + + org.springframework.web.context.ContextLoaderListener + + + + + + + accelerator + de.halbekunst.juplo.cachecontrol.AcceleratorFilter + + + + logger + de.halbekunst.juplo.test.LoggingHttpServletResponseFilter + + + + + + + logger + *.html + + + + accelerator + *.html + + + + + + + dispatcher-servlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + + + + 1 + + + + + + + dispatcher-servlet + *.html + + + diff --git a/examples/spring/src/main/webapp/index.jsp b/examples/spring/src/main/webapp/index.jsp new file mode 100644 index 00000000..90820004 --- /dev/null +++ b/examples/spring/src/main/webapp/index.jsp @@ -0,0 +1,8 @@ +<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" session="false" %> + +<%-- + +Unfortionatly, the welcome-mechanism in web.xml does not work with a page +served by a servlet... + +--%> diff --git a/examples/spring/src/test/java/de/halbekunst/cachecontrol/examples/SpringMVCTest.java b/examples/spring/src/test/java/de/halbekunst/cachecontrol/examples/SpringMVCTest.java new file mode 100644 index 00000000..f90d16e6 --- /dev/null +++ b/examples/spring/src/test/java/de/halbekunst/cachecontrol/examples/SpringMVCTest.java @@ -0,0 +1,29 @@ +package de.halbekunst.cachecontrol.examples; + +import de.halbekunst.juplo.test.HttpTestCase; +import com.meterware.httpunit.WebResponse; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author kai + */ +public class SpringMVCTest extends HttpTestCase { + + private static final Logger log = LoggerFactory.getLogger(SpringMVCTest.class); + + + public SpringMVCTest() { + super("src/main/webapp/WEB-INF/web.xml"); + } + + + @Test + public void testSpringPage() throws Exception { + WebResponse response = executeRequest("http://localhost:8080/spring-page.html"); + log.info("Title:\t\t{}", response.getTitle()); + log.debug("Text:\t\t{}", response.getText()); + } +} diff --git a/examples/spring/tomcat.sh b/examples/spring/tomcat.sh new file mode 100755 index 00000000..4378a128 --- /dev/null +++ b/examples/spring/tomcat.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# + +# OutOfMemoryException beim "mvn jetty:run" umgehen und +# Parameter zum nachträglichen anhängen eines Debuggers +# setzen +export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n" + +rm -v src/main/webapp/WEB-INF/lib/juplo* + +mvn tomcat:run-war diff --git a/examples/static/jetty.sh b/examples/static/jetty.sh new file mode 100755 index 00000000..4950796b --- /dev/null +++ b/examples/static/jetty.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# + +# OutOfMemoryException beim "mvn jetty:run" umgehen und +# Parameter zum nachträglichen anhängen eines Debuggers +# setzen +export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n" + +rm -v src/main/webapp/WEB-INF/lib/juplo* + +mvn jetty:run diff --git a/examples/static/pom.xml b/examples/static/pom.xml new file mode 100644 index 00000000..5cf0634f --- /dev/null +++ b/examples/static/pom.xml @@ -0,0 +1,26 @@ + + + + 4.0.0 + + + de.halbekunst + juplo-examples + 2.0-SNAPSHOT + + + juplo-examples-static + war + Juplo - Examples: Static Content + + + + org.apache.commons + commons-io + ${commons-io.version} + test + + + + diff --git a/examples/static/src/main/resources/config.xml b/examples/static/src/main/resources/config.xml new file mode 100644 index 00000000..e414ce93 --- /dev/null +++ b/examples/static/src/main/resources/config.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/static/src/main/resources/log4j.xml b/examples/static/src/main/resources/log4j.xml new file mode 100644 index 00000000..d3414bdb --- /dev/null +++ b/examples/static/src/main/resources/log4j.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/static/src/main/webapp/WEB-INF/web.xml b/examples/static/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..2df85a54 --- /dev/null +++ b/examples/static/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,63 @@ + + + + + + + contextConfigLocation + classpath:/config.xml + + + + + + + org.springframework.web.context.ContextLoaderListener + + + + + + + accelerator + de.halbekunst.juplo.cachecontrol.AcceleratorFilter + + + + logger + de.halbekunst.juplo.test.LoggingHttpServletResponseFilter + + + + + + + logger + /static/* + + + + accelerator + /static/* + + + + + + + default + org.eclipse.jetty.servlet.DefaultServlet + + + + + + + default + / + + + + diff --git a/examples/static/src/main/webapp/index.html b/examples/static/src/main/webapp/index.html new file mode 100644 index 00000000..22c61d08 --- /dev/null +++ b/examples/static/src/main/webapp/index.html @@ -0,0 +1,15 @@ + + + + + + Examples for Static Content + + +

Examples for Static Content

+ + + diff --git a/examples/static/src/main/webapp/static/page.html b/examples/static/src/main/webapp/static/page.html new file mode 100644 index 00000000..f8517959 --- /dev/null +++ b/examples/static/src/main/webapp/static/page.html @@ -0,0 +1,13 @@ + + + + + + A Static Page + + + +

A Static Page

+

This page is a static HTML-page

+ + diff --git a/examples/jsp/src/main/webapp/default.css b/examples/static/src/main/webapp/static/stylesheets.css similarity index 100% rename from examples/jsp/src/main/webapp/default.css rename to examples/static/src/main/webapp/static/stylesheets.css diff --git a/examples/static/src/test/java/de/halbekunst/cachecontrol/examples/StaticTest.java b/examples/static/src/test/java/de/halbekunst/cachecontrol/examples/StaticTest.java new file mode 100644 index 00000000..e66a5087 --- /dev/null +++ b/examples/static/src/test/java/de/halbekunst/cachecontrol/examples/StaticTest.java @@ -0,0 +1,28 @@ +package de.halbekunst.cachecontrol.examples; + +import de.halbekunst.juplo.test.HttpTestCase; +import com.meterware.httpunit.WebResponse; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author kai + */ +public class StaticTest extends HttpTestCase { + + private static final Logger log = LoggerFactory.getLogger(StaticTest.class); + + + public StaticTest() { + super("src/main/webapp/WEB-INF/web.xml"); + } + + @Test + public void testStaticContent() throws Exception { + WebResponse response = executeRequest("http://localhost:8080/static/page.html"); + log.info("Title:\t\t{}", response.getTitle()); + log.debug("Text:\t\t{}", response.getText()); + } +} diff --git a/examples/static/src/test/java/org/eclipse/jetty/servlet/DefaultServlet.java b/examples/static/src/test/java/org/eclipse/jetty/servlet/DefaultServlet.java new file mode 100644 index 00000000..0173a1fc --- /dev/null +++ b/examples/static/src/test/java/org/eclipse/jetty/servlet/DefaultServlet.java @@ -0,0 +1,28 @@ +package org.eclipse.jetty.servlet; + +import java.io.FileInputStream; +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.IOUtils; + +/** + * Möglichst simple Fake-Implementierung für die Ausführung des Testfalls + * + * @author kai + */ +public class DefaultServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String path = getServletContext().getRealPath(request.getRequestURI()); + if (path == null) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } + response.setContentType("text/html"); + IOUtils.copy(new FileInputStream(path), response.getOutputStream()); + } +} diff --git a/pom.xml b/pom.xml index 97cb6a2e..8c63f411 100644 --- a/pom.xml +++ b/pom.xml @@ -36,8 +36,10 @@ 1.6.11 + 1.3.2 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/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