Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-server')
-rw-r--r--jetty-server/src/main/config/etc/jetty-debuglog.xml32
-rw-r--r--jetty-server/src/main/config/etc/jetty-gzip.xml94
-rw-r--r--jetty-server/src/main/config/etc/jetty-ipaccess.xml41
-rw-r--r--jetty-server/src/main/config/etc/jetty-stats.xml12
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java2
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java10
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java19
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/handler/HandlerTest.java342
8 files changed, 458 insertions, 94 deletions
diff --git a/jetty-server/src/main/config/etc/jetty-debuglog.xml b/jetty-server/src/main/config/etc/jetty-debuglog.xml
index adbb10a5d4..0a082ce11f 100644
--- a/jetty-server/src/main/config/etc/jetty-debuglog.xml
+++ b/jetty-server/src/main/config/etc/jetty-debuglog.xml
@@ -6,20 +6,20 @@
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
- <Get id="oldhandler" name="handler"/>
- <Set name="handler">
- <New id="DebugHandler" class="org.eclipse.jetty.server.handler.DebugHandler">
- <Set name="handler"><Ref refid="oldhandler"/></Set>
- <Set name="outputStream">
- <New class="org.eclipse.jetty.util.RolloverFileOutputStream">
- <Arg type="String"><Property name="jetty.debuglog.dir" deprecated="jetty.logs" default="./logs"/>/yyyy_mm_dd.debug.log</Arg>
- <Arg type="boolean"><Property name="jetty.debuglog.append" default="true"/></Arg>
- <Arg type="int"><Property name="jetty.debuglog.retainDays" default="90"/></Arg>
- <Arg>
- <Call class="java.util.TimeZone" name="getTimeZone"><Arg><Property name="jetty.debuglog.timezone" default="GMT"/></Arg></Call>
- </Arg>
- </New>
- </Set>
- </New>
- </Set>
+ <Call name="insertHandler">
+ <Arg>
+ <New id="DebugHandler" class="org.eclipse.jetty.server.handler.DebugHandler">
+ <Set name="outputStream">
+ <New class="org.eclipse.jetty.util.RolloverFileOutputStream">
+ <Arg type="String"><Property name="jetty.debuglog.dir" deprecated="jetty.logs" default="./logs"/>/yyyy_mm_dd.debug.log</Arg>
+ <Arg type="boolean"><Property name="jetty.debuglog.append" default="true"/></Arg>
+ <Arg type="int"><Property name="jetty.debuglog.retainDays" default="90"/></Arg>
+ <Arg>
+ <Call class="java.util.TimeZone" name="getTimeZone"><Arg><Property name="jetty.debuglog.timezone" default="GMT"/></Arg></Call>
+ </Arg>
+ </New>
+ </Set>
+ </New>
+ </Arg>
+ </Call>
</Configure>
diff --git a/jetty-server/src/main/config/etc/jetty-gzip.xml b/jetty-server/src/main/config/etc/jetty-gzip.xml
index f26ef0b5a1..93b41fd639 100644
--- a/jetty-server/src/main/config/etc/jetty-gzip.xml
+++ b/jetty-server/src/main/config/etc/jetty-gzip.xml
@@ -9,59 +9,59 @@
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
- <Get id="next" name="handler" />
- <Set name="handler">
- <New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
- <Set name="handler"><Ref refid="next" /></Set>
- <Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set>
- <Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/></Set>
- <Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel" default="-1"/></Set>
- <Set name="excludedAgentPatterns">
- <Array type="String">
- <Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
- </Array>
- </Set>
+ <Call name="insertHandler">
+ <Arg>
+ <New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
+ <Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set>
+ <Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/></Set>
+ <Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel" default="-1"/></Set>
+ <Set name="excludedAgentPatterns">
+ <Array type="String">
+ <Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
+ </Array>
+ </Set>
- <Set name="includedMethods">
- <Array type="String">
- <Item>GET</Item>
- </Array>
- </Set>
+ <Set name="includedMethods">
+ <Array type="String">
+ <Item>GET</Item>
+ </Array>
+ </Set>
- <!--
- <Set name="includedPaths">
- <Array type="String">
- <Item>/*</Item>
- </Array>
- </Set>
- -->
+ <!--
+ <Set name="includedPaths">
+ <Array type="String">
+ <Item>/*</Item>
+ </Array>
+ </Set>
+ -->
- <!--
- <Set name="excludedPaths">
- <Array type="String">
- <Item>*.gz</Item>
- </Array>
- </Set>
- -->
+ <!--
+ <Set name="excludedPaths">
+ <Array type="String">
+ <Item>*.gz</Item>
+ </Array>
+ </Set>
+ -->
- <!--
- <Call name="addIncludedMimeTypes">
- <Arg><Array type="String">
- <Item>some/type</Item>
- </Array></Arg>
- </Call>
- -->
+ <!--
+ <Call name="addIncludedMimeTypes">
+ <Arg><Array type="String">
+ <Item>some/type</Item>
+ </Array></Arg>
+ </Call>
+ -->
- <!--
- <Call name="addExcludedMimeTypes">
- <Arg><Array type="String">
- <Item>some/type</Item>
- </Array></Arg>
- </Call>
- -->
+ <!--
+ <Call name="addExcludedMimeTypes">
+ <Arg><Array type="String">
+ <Item>some/type</Item>
+ </Array></Arg>
+ </Call>
+ -->
- </New>
- </Set>
+ </New>
+ </Arg>
+ </Call>
</Configure>
diff --git a/jetty-server/src/main/config/etc/jetty-ipaccess.xml b/jetty-server/src/main/config/etc/jetty-ipaccess.xml
index d8236a99a0..832565c5ad 100644
--- a/jetty-server/src/main/config/etc/jetty-ipaccess.xml
+++ b/jetty-server/src/main/config/etc/jetty-ipaccess.xml
@@ -6,26 +6,23 @@
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
-
- <Get id="oldhandler" name="handler"/>
-
- <Set name="handler">
- <New id="IPAccessHandler" class="org.eclipse.jetty.server.handler.IPAccessHandler">
- <Set name="handler"><Ref refid="oldhandler"/></Set>
- <Set name="white">
- <Array type="String">
- <Item>127.0.0.1</Item>
- <Item>127.0.0.2/*.html</Item>
- </Array>
- </Set>
- <Set name="black">
- <Array type="String">
- <Item>127.0.0.1/blacklisted</Item>
- <Item>127.0.0.2/black.html</Item>
- </Array>
- </Set>
- <Set name="whiteListByPath">false</Set>
- </New>
- </Set>
-
+ <Call name="insertHandler">
+ <Arg>
+ <New id="IPAccessHandler" class="org.eclipse.jetty.server.handler.IPAccessHandler">
+ <Set name="white">
+ <Array type="String">
+ <Item>127.0.0.1</Item>
+ <Item>127.0.0.2/*.html</Item>
+ </Array>
+ </Set>
+ <Set name="black">
+ <Array type="String">
+ <Item>127.0.0.1/blacklisted</Item>
+ <Item>127.0.0.2/black.html</Item>
+ </Array>
+ </Set>
+ <Set name="whiteListByPath">false</Set>
+ </New>
+ </Arg>
+ </Call>
</Configure>
diff --git a/jetty-server/src/main/config/etc/jetty-stats.xml b/jetty-server/src/main/config/etc/jetty-stats.xml
index 4e014906a5..445ae6a8a4 100644
--- a/jetty-server/src/main/config/etc/jetty-stats.xml
+++ b/jetty-server/src/main/config/etc/jetty-stats.xml
@@ -6,12 +6,12 @@
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
- <Get id="oldhandler" name="handler" />
- <Set name="handler">
- <New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler">
- <Set name="handler"><Ref refid="oldhandler" /></Set>
- </New>
- </Set>
+ <Call name="insertHandler">
+ <Arg>
+ <New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler">
+ </New>
+ </Arg>
+ </Call>
<Call class="org.eclipse.jetty.server.ConnectorStatistics" name="addToAllConnectors">
<Arg><Ref refid="Server"/></Arg>
</Call>
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
index 15429f88c6..745d56c9e6 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
@@ -100,7 +100,7 @@ import org.eclipse.jetty.util.resource.Resource;
* The maximum size of a form that can be processed by this context is controlled by the system properties org.eclipse.jetty.server.Request.maxFormKeys
* and org.eclipse.jetty.server.Request.maxFormContentSize. These can also be configured with {@link #setMaxFormContentSize(int)} and {@link #setMaxFormKeys(int)}
* <p>
- * This servers executore is made available via a context attributed "org.eclipse.jetty.server.Executor".
+ * This servers executor is made available via a context attributed "org.eclipse.jetty.server.Executor".
* <p>
* By default, the context is created with alias checkers for {@link AllowSymLinkAliasChecker} (unix only) and {@link ApproveNonExistentDirectoryAliases}.
* If these alias checkers are not required, then {@link #clearAliasChecks()} or {@link #setAliasChecks(List)} should be called.
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java
index e8ebe86dc5..ba5fae7d4f 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ArrayUtil;
@@ -82,9 +83,18 @@ public class HandlerCollection extends AbstractHandlerContainer
throw new IllegalStateException(STARTED);
if (handlers!=null)
+ {
+ // check for loops
+ for (Handler handler:handlers)
+ if (handler == this || (handler instanceof HandlerContainer &&
+ Arrays.asList(((HandlerContainer)handler).getChildHandlers()).contains(this)))
+ throw new IllegalStateException("setHandler loop");
+
+ // Set server
for (Handler handler:handlers)
if (handler.getServer()!=getServer())
handler.setServer(getServer());
+ }
Handler[] old=_handlers;;
_handlers = handlers;
updateBeans(old, handlers);
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java
index f567f4ba80..e7e57c5556 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.server.handler;
import java.io.IOException;
+import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletException;
@@ -27,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
@@ -82,6 +84,11 @@ public class HandlerWrapper extends AbstractHandlerContainer
if (isStarted())
throw new IllegalStateException(STARTED);
+ // check for loops
+ if (handler==this || (handler instanceof HandlerContainer &&
+ Arrays.asList(((HandlerContainer)handler).getChildHandlers()).contains(this)))
+ throw new IllegalStateException("setHandler loop");
+
if (handler!=null)
handler.setServer(getServer());
@@ -104,10 +111,18 @@ public class HandlerWrapper extends AbstractHandlerContainer
*/
public void insertHandler(HandlerWrapper wrapper)
{
- if (wrapper==null || wrapper.getHandler()!=null)
+ if (wrapper==null)
throw new IllegalArgumentException();
- wrapper.setHandler(getHandler());
+
+ HandlerWrapper tail = wrapper;
+ while(tail.getHandler() instanceof HandlerWrapper)
+ tail=(HandlerWrapper)tail.getHandler();
+ if (tail.getHandler()!=null)
+ throw new IllegalArgumentException("bad tail of inserted wrapper chain");
+
+ Handler next=getHandler();
setHandler(wrapper);
+ tail.setHandler(next);
}
/* ------------------------------------------------------------ */
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/HandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/HandlerTest.java
new file mode 100644
index 0000000000..c09e4037ba
--- /dev/null
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/HandlerTest.java
@@ -0,0 +1,342 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.server.handler;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.handler.HandlerWrapper;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+public class HandlerTest
+{
+
+ @Test
+ public void testWrapperSetServer()
+ {
+ Server s=new Server();
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+ HandlerWrapper c = new HandlerWrapper();
+ a.setHandler(b);
+ b.setHandler(c);
+
+ a.setServer(s);
+ assertThat(b.getServer(),equalTo(s));
+ assertThat(c.getServer(),equalTo(s));
+ }
+
+ @Test
+ public void testWrapperServerSet()
+ {
+ Server s=new Server();
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+ HandlerWrapper c = new HandlerWrapper();
+ a.setServer(s);
+ b.setHandler(c);
+ a.setHandler(b);
+
+ assertThat(b.getServer(),equalTo(s));
+ assertThat(c.getServer(),equalTo(s));
+ }
+
+ @Test
+ public void testWrapperThisLoop()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+
+ try
+ {
+ a.setHandler(a);
+ fail();
+ }
+ catch(IllegalStateException e)
+ {
+ assertThat(e.getMessage(),containsString("loop"));
+ }
+ }
+
+ @Test
+ public void testWrapperSimpleLoop()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+
+ a.setHandler(b);
+
+ try
+ {
+ b.setHandler(a);
+ fail();
+ }
+ catch(IllegalStateException e)
+ {
+ assertThat(e.getMessage(),containsString("loop"));
+ }
+ }
+
+ @Test
+ public void testWrapperDeepLoop()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+ HandlerWrapper c = new HandlerWrapper();
+
+ a.setHandler(b);
+ b.setHandler(c);
+
+ try
+ {
+ c.setHandler(a);
+ fail();
+ }
+ catch(IllegalStateException e)
+ {
+ assertThat(e.getMessage(),containsString("loop"));
+ }
+ }
+
+ @Test
+ public void testWrapperChainLoop()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+ HandlerWrapper c = new HandlerWrapper();
+
+ a.setHandler(b);
+ c.setHandler(a);
+
+ try
+ {
+ b.setHandler(c);
+ fail();
+ }
+ catch(IllegalStateException e)
+ {
+ assertThat(e.getMessage(),containsString("loop"));
+ }
+ }
+
+
+ @Test
+ public void testCollectionSetServer()
+ {
+ Server s=new Server();
+ HandlerCollection a = new HandlerCollection();
+ HandlerCollection b = new HandlerCollection();
+ HandlerCollection b1 = new HandlerCollection();
+ HandlerCollection b2 = new HandlerCollection();
+ HandlerCollection c = new HandlerCollection();
+ HandlerCollection c1 = new HandlerCollection();
+ HandlerCollection c2 = new HandlerCollection();
+
+ a.addHandler(b);
+ a.addHandler(c);
+ b.setHandlers(new Handler[]{b1,b2});
+ c.setHandlers(new Handler[]{c1,c2});
+ a.setServer(s);
+
+ assertThat(b.getServer(),equalTo(s));
+ assertThat(c.getServer(),equalTo(s));
+ assertThat(b1.getServer(),equalTo(s));
+ assertThat(b2.getServer(),equalTo(s));
+ assertThat(c1.getServer(),equalTo(s));
+ assertThat(c2.getServer(),equalTo(s));
+ }
+
+ @Test
+ public void testCollectionServerSet()
+ {
+ Server s=new Server();
+ HandlerCollection a = new HandlerCollection();
+ HandlerCollection b = new HandlerCollection();
+ HandlerCollection b1 = new HandlerCollection();
+ HandlerCollection b2 = new HandlerCollection();
+ HandlerCollection c = new HandlerCollection();
+ HandlerCollection c1 = new HandlerCollection();
+ HandlerCollection c2 = new HandlerCollection();
+
+ a.setServer(s);
+ a.addHandler(b);
+ a.addHandler(c);
+ b.setHandlers(new Handler[]{b1,b2});
+ c.setHandlers(new Handler[]{c1,c2});
+
+ assertThat(b.getServer(),equalTo(s));
+ assertThat(c.getServer(),equalTo(s));
+ assertThat(b1.getServer(),equalTo(s));
+ assertThat(b2.getServer(),equalTo(s));
+ assertThat(c1.getServer(),equalTo(s));
+ assertThat(c2.getServer(),equalTo(s));
+ }
+
+ @Test
+ public void testCollectionThisLoop()
+ {
+ HandlerCollection a = new HandlerCollection();
+
+ try
+ {
+ a.addHandler(a);
+ fail();
+ }
+ catch(IllegalStateException e)
+ {
+ assertThat(e.getMessage(),containsString("loop"));
+ }
+ }
+
+ @Test
+ public void testCollectionDeepLoop()
+ {
+ HandlerCollection a = new HandlerCollection();
+ HandlerCollection b = new HandlerCollection();
+ HandlerCollection b1 = new HandlerCollection();
+ HandlerCollection b2 = new HandlerCollection();
+ HandlerCollection c = new HandlerCollection();
+ HandlerCollection c1 = new HandlerCollection();
+ HandlerCollection c2 = new HandlerCollection();
+
+ a.addHandler(b);
+ a.addHandler(c);
+ b.setHandlers(new Handler[]{b1,b2});
+ c.setHandlers(new Handler[]{c1,c2});
+
+ try
+ {
+ b2.addHandler(a);
+ fail();
+ }
+ catch(IllegalStateException e)
+ {
+ assertThat(e.getMessage(),containsString("loop"));
+ }
+ }
+
+ @Test
+ public void testCollectionChainLoop()
+ {
+ HandlerCollection a = new HandlerCollection();
+ HandlerCollection b = new HandlerCollection();
+ HandlerCollection b1 = new HandlerCollection();
+ HandlerCollection b2 = new HandlerCollection();
+ HandlerCollection c = new HandlerCollection();
+ HandlerCollection c1 = new HandlerCollection();
+ HandlerCollection c2 = new HandlerCollection();
+
+ a.addHandler(c);
+ b.setHandlers(new Handler[]{b1,b2});
+ c.setHandlers(new Handler[]{c1,c2});
+ b2.addHandler(a);
+
+ try
+ {
+ a.addHandler(b);
+ fail();
+ }
+ catch(IllegalStateException e)
+ {
+ assertThat(e.getMessage(),containsString("loop"));
+ }
+ }
+
+ @Test
+ public void testInsertWrapperTail()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+
+ a.insertHandler(b);
+ assertThat(a.getHandler(),equalTo(b));
+ assertThat(b.getHandler(),nullValue());
+ }
+
+ @Test
+ public void testInsertWrapper()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+ HandlerWrapper c = new HandlerWrapper();
+
+ a.insertHandler(c);
+ a.insertHandler(b);
+ assertThat(a.getHandler(),equalTo(b));
+ assertThat(b.getHandler(),equalTo(c));
+ assertThat(c.getHandler(),nullValue());
+ }
+
+ @Test
+ public void testInsertWrapperChain()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+ HandlerWrapper c = new HandlerWrapper();
+ HandlerWrapper d = new HandlerWrapper();
+
+ a.insertHandler(d);
+ b.insertHandler(c);
+ a.insertHandler(b);
+ assertThat(a.getHandler(),equalTo(b));
+ assertThat(b.getHandler(),equalTo(c));
+ assertThat(c.getHandler(),equalTo(d));
+ assertThat(d.getHandler(),nullValue());
+ }
+
+ @Test
+ public void testInsertWrapperBadChain()
+ {
+ HandlerWrapper a = new HandlerWrapper();
+ HandlerWrapper b = new HandlerWrapper();
+ HandlerWrapper c = new HandlerWrapper();
+ HandlerWrapper d = new HandlerWrapper();
+
+ a.insertHandler(d);
+ b.insertHandler(c);
+ c.setHandler(new AbstractHandler()
+ {
+ @Override
+ public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ }
+ });
+
+ try
+ {
+ a.insertHandler(b);
+ fail();
+ }
+ catch(IllegalArgumentException e)
+ {
+ assertThat(e.getMessage(),containsString("bad tail"));
+ }
+ }
+}

Back to the top