diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java new file mode 100644 index 00000000000..e69f5890aa8 --- /dev/null +++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java @@ -0,0 +1,66 @@ +// ======================================================================== +// Copyright (c) 2006-2009 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.embedded; + +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.SelectChannelConnector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.server.handler.ContextHandlerCollection; +import org.eclipse.jetty.server.handler.ResourceHandler; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.util.resource.Resource; + +/* ------------------------------------------------------------ */ +/** + * A {@link ContextHandlerCollection} handler may be used to direct a request to + * a specific Context. The URI path prefix and optional virtual host is used to + * select the context. + * + */ +public class SplitFileServer +{ + + public static void main(String[] args) throws Exception + { + Server server = new Server(); + SelectChannelConnector connector = new SelectChannelConnector(server); + connector.setPort(8090); + server.setConnectors(new Connector[] + { connector }); + + ContextHandler context0 = new ContextHandler(); + context0.setContextPath("/"); + ResourceHandler rh0 = new ResourceHandler(); + rh0.setBaseResource( Resource.newResource(MavenTestingUtils.getTestResourceDir("dir0"))); + context0.setHandler(rh0); + + ContextHandler context1 = new ContextHandler(); + context1.setContextPath("/"); + ResourceHandler rh1 = new ResourceHandler(); + rh1.setBaseResource( Resource.newResource(MavenTestingUtils.getTestResourceDir("dir1"))); + context1.setHandler(rh1); + + ContextHandlerCollection contexts = new ContextHandlerCollection(); + contexts.setHandlers(new Handler[] + { context0, context1 }); + + server.setHandler(contexts); + + server.start(); + System.err.println(server.dump()); + server.join(); + } +} diff --git a/example-jetty-embedded/src/test/resources/dir0/test0.txt b/example-jetty-embedded/src/test/resources/dir0/test0.txt new file mode 100644 index 00000000000..a39c44cc614 --- /dev/null +++ b/example-jetty-embedded/src/test/resources/dir0/test0.txt @@ -0,0 +1 @@ +test0 \ No newline at end of file diff --git a/example-jetty-embedded/src/test/resources/dir1/test1.txt b/example-jetty-embedded/src/test/resources/dir1/test1.txt new file mode 100644 index 00000000000..f079749c42f --- /dev/null +++ b/example-jetty-embedded/src/test/resources/dir1/test1.txt @@ -0,0 +1 @@ +test1 \ No newline at end of file