Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2016-02-03 09:54:39 +0000
committerGreg Wilkins2016-02-03 09:54:39 +0000
commit6c9a444b6c5b872f69bc452e84e76bce1426697a (patch)
treee94d4c54377be2883e05d75804ba5aa4f3af9a0c /jetty-server/src/main
parent79a7863ac857c60f51961f5ff1b8ccdc59fd6d45 (diff)
downloadorg.eclipse.jetty.project-6c9a444b6c5b872f69bc452e84e76bce1426697a.tar.gz
org.eclipse.jetty.project-6c9a444b6c5b872f69bc452e84e76bce1426697a.tar.xz
org.eclipse.jetty.project-6c9a444b6c5b872f69bc452e84e76bce1426697a.zip
486530 - Handler added to WebAppContext prevents ServletContext initialization
Added warnings for loops and inappropriate handlers. Used insertHandler in more XML files
Diffstat (limited to 'jetty-server/src/main')
-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
7 files changed, 116 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);
}
/* ------------------------------------------------------------ */

Back to the top