aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2013-09-19 05:31:48 (EDT)
committerThomas Becker2013-09-19 05:36:32 (EDT)
commitad5624f00016ce202f06db60e12e45bed0045007 (patch)
tree3859681fd68e2650f90e7e1eaacf2ce739121d19
parentc9c54ef4d126ea603aed5aaaddbf8d42e35aabd2 (diff)
downloadorg.eclipse.jetty.project-ad5624f00016ce202f06db60e12e45bed0045007.zip
org.eclipse.jetty.project-ad5624f00016ce202f06db60e12e45bed0045007.tar.gz
org.eclipse.jetty.project-ad5624f00016ce202f06db60e12e45bed0045007.tar.bz2
416453 Add comments to embedded SplitFileServer example
-rw-r--r--examples/embedded/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java6
-rw-r--r--examples/embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java14
2 files changed, 17 insertions, 3 deletions
diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java
index 28f68af..5532784 100644
--- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java
+++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java
@@ -46,12 +46,14 @@ public class MinimalServlets
// on a given context path.
// !! This is a raw Servlet, not a servlet that has been configured through a web.xml or anything like that !!
- handler.addServletWithMapping(HelloServlet.class,"/*");
+ handler.addServletWithMapping(HelloServlet.class, "/*");
+ // Start things up! By using the server.join() the server thread will join with the current thread.
+ // See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
server.start();
server.join();
}
-
+
@SuppressWarnings("serial")
public static class HelloServlet extends HttpServlet
{
diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java
index 347c30c..704561b 100644
--- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java
+++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java
@@ -40,30 +40,42 @@ public class SplitFileServer
public static void main(String[] args) throws Exception
{
+ // Create the Server object and a corresponding ServerConnector and then set the port for the connector. In
+ // this example the server will listen on port 8090. If you set this to port 0 then when the server has been
+ // started you can called connector.getLocalPort() to programmatically get the port the server started on.
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8090);
server.setConnectors(new Connector[]
{ connector });
+ // Create a Context Handler and ResourceHandler. The ContextHandler is getting set to "/" path but this could
+ // be anything you like for builing out your url. Note how we are setting the ResourceBase using our jetty
+ // maven testing utilities to get the proper resource directory, you needn't use these,
+ // you simply need to supply the paths you are looking to serve content from.
ContextHandler context0 = new ContextHandler();
context0.setContextPath("/");
ResourceHandler rh0 = new ResourceHandler();
rh0.setBaseResource( Resource.newResource(MavenTestingUtils.getTestResourceDir("dir0")));
context0.setHandler(rh0);
+ // Rinse and repeat the previous item, only specifying a different resource base.
ContextHandler context1 = new ContextHandler();
context1.setContextPath("/");
ResourceHandler rh1 = new ResourceHandler();
rh1.setBaseResource( Resource.newResource(MavenTestingUtils.getTestResourceDir("dir1")));
context1.setHandler(rh1);
-
+
+ // Create a ContextHandlerCollection and set the context handlers to it. This will let jetty process urls
+ // against the declared contexts in order to match up content.
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[]
{ context0, context1 });
server.setHandler(contexts);
+ // Start things up! By using the server.join() the server thread will join with the current thread.
+ // See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
server.start();
System.err.println(server.dump());
server.join();