diff --git a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java
index 5bbe618d4a4..a8d7a85e366 100644
--- a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java
+++ b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java
@@ -13,8 +13,8 @@ import javax.servlet.ServletResponse;
public class ContinuationFilter implements Filter
{
- boolean _faux;
- ServletContext _context;
+ private boolean _faux;
+ private ServletContext _context;
public void init(FilterConfig filterConfig) throws ServletException
{
diff --git a/jetty-embedded-examples/pom.xml b/jetty-embedded-examples/pom.xml
new file mode 100644
index 00000000000..d629d747fd2
--- /dev/null
+++ b/jetty-embedded-examples/pom.xml
@@ -0,0 +1,27 @@
+
+
+ org.eclipse.jetty
+ jetty-project
+ 7.0.0.incubation0-SNAPSHOT
+
+ 4.0.0
+ jetty-embedded
+ Jetty :: Embedded Examples
+ Jetty Embedded Examples
+
+
+
+
+
+
+ org.eclipse.jetty
+ jetty-webapp
+ ${project.version}
+
+
+ org.eclipse.jetty
+ jetty-deploy
+ ${project.version}
+
+
+
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/FileServer.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/FileServer.java
new file mode 100644
index 00000000000..7fc8366ffb3
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/FileServer.java
@@ -0,0 +1,61 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.server.handler.ResourceHandler;
+import org.eclipse.jetty.util.resource.Resource;
+
+/* ------------------------------------------------------------ */
+/** File server
+ * Usage - java org.eclipse.jetty.server.example.FileServer [ port [ docroot ]]
+ * @author gregw
+ *
+ */
+public class FileServer
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server(args.length==0?8080:Integer.parseInt(args[0]));
+
+ ResourceHandler resource_handler=new ResourceHandler()
+ {
+ protected void doDirectory(HttpServletRequest request, HttpServletResponse response, Resource resource) throws IOException
+ {
+ String listing=resource.getListHTML(request.getRequestURI(),request.getPathInfo().lastIndexOf("/")>0);
+ response.setContentType("text/html; charset=UTF-8");
+ response.getWriter().println(listing);
+ }
+ };
+
+ resource_handler.setResourceBase(args.length==2?args[1]:".");
+
+ HandlerList handlers = new HandlerList();
+ handlers.setHandlers(new Handler[]{resource_handler,new DefaultHandler()});
+ server.setHandler(handlers);
+
+ server.start();
+ server.join();
+ }
+
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java
new file mode 100644
index 00000000000..40b125b2070
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java
@@ -0,0 +1,86 @@
+// ========================================================================
+// 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.security.HashLoginService;
+import org.eclipse.jetty.security.LoginService;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.NCSARequestLog;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.deploy.ContextDeployer;
+import org.eclipse.jetty.deploy.WebAppDeployer;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.handler.RequestLogHandler;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
+
+public class LikeJettyXml
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ String jetty_home = System.getProperty("jetty.home",".");
+
+ Server server = new Server();
+
+ QueuedThreadPool threadPool = new QueuedThreadPool();
+ threadPool.setMaxThreads(100);
+ server.setThreadPool(threadPool);
+
+ Connector connector=new SelectChannelConnector();
+ connector.setPort(8080);
+ connector.setMaxIdleTime(30000);
+ server.setConnectors(new Connector[]{connector});
+
+ HandlerCollection handlers = new HandlerCollection();
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ RequestLogHandler requestLogHandler = new RequestLogHandler();
+ handlers.setHandlers(new Handler[]{contexts,new DefaultHandler(),requestLogHandler});
+ server.setHandler(handlers);
+
+ ContextDeployer deployer0 = new ContextDeployer();
+ deployer0.setContexts(contexts);
+ deployer0.setConfigurationDir(jetty_home+"/contexts");
+ deployer0.setScanInterval(1);
+ server.addBean(deployer0);
+
+ WebAppDeployer deployer1 = new WebAppDeployer();
+ deployer1.setContexts(contexts);
+ deployer1.setWebAppDir(jetty_home+"/webapps");
+ deployer1.setParentLoaderPriority(false);
+ deployer1.setExtract(true);
+ deployer1.setAllowDuplicates(false);
+ deployer1.setDefaultsDescriptor(jetty_home+"/etc/webdefault.xml");
+ server.addBean(deployer1);
+
+ HashLoginService login = new HashLoginService();
+ login.setName("Test Realm");
+ login.setConfig(jetty_home+"/etc/realm.properties");
+ server.addBean(login);
+
+ NCSARequestLog requestLog = new NCSARequestLog(jetty_home+"/logs/jetty-yyyy_mm_dd.log");
+ requestLog.setExtended(false);
+ requestLogHandler.setRequestLog(requestLog);
+
+ server.setStopAtShutdown(true);
+ server.setSendServerVersion(true);
+
+ server.start();
+ server.join();
+ }
+
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java
new file mode 100644
index 00000000000..47ad16416d0
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java
@@ -0,0 +1,76 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConnection;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.bio.SocketConnector;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
+
+public class ManyConnectors
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server();
+
+ SelectChannelConnector connector0 = new SelectChannelConnector();
+ connector0.setPort(8080);
+ connector0.setMaxIdleTime(5000);
+ connector0.setName("connector 0");
+
+
+ SelectChannelConnector connector1 = new SelectChannelConnector();
+ connector1.setHost("127.0.0.1");
+ connector1.setPort(8888);
+ connector1.setName("connector 1");
+
+ SocketConnector connector2 = new SocketConnector();
+ connector2.setHost("127.0.0.2");
+ connector2.setPort(8888);
+ connector2.setThreadPool(new QueuedThreadPool());
+ connector2.setName("connector 2");
+
+ server.setConnectors(new Connector[]{connector0,connector1,connector2});
+
+ server.setHandler(new HelloHandler());
+
+ server.start();
+ server.join();
+ }
+
+ public static class HelloHandler extends AbstractHandler
+ {
+ public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("
Hello OneHandler
");
+ response.getWriter().println("from "+((Request)request).getConnection().getConnector().getName());
+
+ ((Request)request).setHandled(true);
+ }
+ }
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java
new file mode 100644
index 00000000000..5b456da32ba
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java
@@ -0,0 +1,81 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConnection;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+
+public class ManyContexts
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server();
+ Connector connector=new SelectChannelConnector();
+ connector.setPort(8080);
+ server.setConnectors(new Connector[]{connector});
+
+ ContextHandler context0 = new ContextHandler();
+ context0.setContextPath("/zero");
+ Handler handler0=new HelloHandler();
+ context0.setHandler(handler0);
+
+ ContextHandler context1 = new ContextHandler();
+ context1.setContextPath("/one");
+ Handler handler1=new HelloHandler();
+ context1.setHandler(handler1);
+
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ contexts.setHandlers(new Handler[]{context0,context1});
+
+ HandlerCollection handlers = new HandlerCollection();
+ handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()});
+
+ server.setHandler(handlers);
+
+ server.start();
+ server.join();
+ }
+
+ public static class HelloHandler extends AbstractHandler
+ {
+ static int h=0;
+ int hello=h++;
+
+ public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
+ base_request.setHandled(true);
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentType("text/html");
+ response.getWriter().println("Hello OneContext "+hello+"
");
+ }
+ }
+
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyHandlers.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyHandlers.java
new file mode 100644
index 00000000000..cfe5fc4fb58
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyHandlers.java
@@ -0,0 +1,71 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConnection;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+
+public class ManyHandlers
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server();
+ Connector connector=new SelectChannelConnector();
+ connector.setPort(8080);
+ server.setConnectors(new Connector[]{connector});
+
+ Handler param=new ParamHandler();
+ Handler hello=new HelloHandler();
+
+ HandlerCollection handlers = new HandlerCollection();
+ handlers.setHandlers(new Handler[]{param,hello});
+ server.setHandler(handlers);
+
+ server.start();
+ server.join();
+ }
+
+ public static class ParamHandler extends AbstractHandler
+ {
+ public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ System.err.println(request.getParameterMap());
+ }
+ }
+
+ public static class HelloHandler extends AbstractHandler
+ {
+ public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
+ base_request.setHandled(true);
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("Hello ManyHandler
");
+ }
+ }
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java
new file mode 100644
index 00000000000..4ee132d2380
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java
@@ -0,0 +1,74 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+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.Server;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.handler.StatisticsHandler;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+public class ManyServletContexts
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server(8080);
+
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ server.setHandler(contexts);
+
+ ServletContextHandler root = new ServletContextHandler(contexts,"/",ServletContextHandler.SESSIONS);
+ root.addServlet(new ServletHolder(new HelloServlet("Ciao")), "/*");
+
+ ServletContextHandler other = new ServletContextHandler(contexts,"/other",ServletContextHandler.SESSIONS);
+ other.addServlet("org.eclipse.jetty.server.example.ManyServletServletContextHandlers$HelloServlet", "/*");
+
+ StatisticsHandler stats = new StatisticsHandler();
+ contexts.addHandler(stats);
+ ServletContextHandler yetanother =new ServletContextHandler(stats,"/yo",ServletContextHandler.SESSIONS);
+ yetanother.addServlet(new ServletHolder(new HelloServlet("YO!")), "/*");
+
+ server.start();
+ server.join();
+ }
+
+ public static class HelloServlet extends HttpServlet
+ {
+ String greeting="Hello";
+ public HelloServlet()
+ {}
+
+ public HelloServlet(String hi)
+ {greeting=hi;}
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println(""+greeting+" SimpleServlet
");
+ response.getWriter().println("session="+request.getSession(true).getId());
+ }
+ }
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java
new file mode 100644
index 00000000000..90240c55c7c
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java
@@ -0,0 +1,56 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.bio.SocketConnector;
+import org.eclipse.jetty.servlet.ServletHandler;
+
+public class MinimalServlets
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server();
+ Connector connector=new SocketConnector();
+ connector.setPort(8080);
+ server.setConnectors(new Connector[]{connector});
+
+ ServletHandler handler=new ServletHandler();
+ server.setHandler(handler);
+
+ handler.addServletWithMapping("org.eclipse.jetty.server.example.MinimalServlets$HelloServlet", "/");
+
+ server.start();
+ server.join();
+ }
+
+ public static class HelloServlet extends HttpServlet
+ {
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("Hello SimpleServlet
");
+ }
+ }
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneContext.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneContext.java
new file mode 100644
index 00000000000..9e750451540
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneContext.java
@@ -0,0 +1,60 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConnection;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+
+public class OneContext
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server(8080);
+
+ ContextHandler context = new ContextHandler();
+ context.setContextPath("/");
+ context.setResourceBase(".");
+ context.setClassLoader(Thread.currentThread().getContextClassLoader());
+ server.setHandler(context);
+
+ context.setHandler(new HelloHandler());
+
+ server.start();
+ server.join();
+ }
+
+ public static class HelloHandler extends AbstractHandler
+ {
+ public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentType("text/html");
+ response.getWriter().println("Hello OneContext
");
+ ((Request)request).setHandled(true);
+ }
+ }
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneHandler.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneHandler.java
new file mode 100644
index 00000000000..5894301cc60
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneHandler.java
@@ -0,0 +1,53 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConnection;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.bio.SocketConnector;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+
+public class OneHandler
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server(8080);
+ server.setHandler(new HelloHandler());
+
+ server.start();
+ server.join();
+ }
+
+ public static class HelloHandler extends AbstractHandler
+ {
+ public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("Hello OneHandler
");
+
+ ((Request)request).setHandled(true);
+ }
+ }
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java
new file mode 100644
index 00000000000..9a7dfea42f5
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java
@@ -0,0 +1,54 @@
+// ========================================================================
+// 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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+public class OneServletContext
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Server server = new Server(8080);
+
+ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ context.setContextPath("/");
+ server.setHandler(context);
+
+ context.addServlet(new ServletHolder(new HelloServlet()), "/*");
+
+ server.start();
+ server.join();
+ }
+
+ public static class HelloServlet extends HttpServlet
+ {
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("Hello SimpleServlet
");
+ response.getWriter().println("session="+request.getSession(true).getId());
+ }
+ }
+}
diff --git a/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
new file mode 100644
index 00000000000..6030dac6cd0
--- /dev/null
+++ b/jetty-embedded-examples/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
@@ -0,0 +1,45 @@
+// ========================================================================
+// 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.Server;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+public class OneWebApp
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ String jetty_default=new java.io.File("./start.jar").exists()?".":"../..";;
+ String jetty_home = System.getProperty("jetty.home",jetty_default);
+
+ Server server = new Server();
+
+ Connector connector=new SelectChannelConnector();
+ connector.setPort(Integer.getInteger("jetty.port",8080).intValue());
+ server.setConnectors(new Connector[]{connector});
+
+ WebAppContext webapp = new WebAppContext();
+ webapp.setContextPath("/");
+ webapp.setWar(jetty_home+"/webapps/test");
+ webapp.setDefaultsDescriptor(jetty_home+"/etc/webdefault.xml");
+
+ server.setHandler(webapp);
+
+ server.start();
+ server.join();
+ }
+}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java
index 73744ccd114..ef63a7998f9 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java
@@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.http.HttpMethods;
+import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
@@ -249,11 +250,14 @@ public class ResourceHandler extends AbstractHandler
response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH));
return;
}
- resource=getWelcome(resource);
-
- if (resource==null || !resource.exists() || resource.isDirectory())
+
+ Resource welcome=getWelcome(resource);
+ if (welcome!=null && welcome.exists())
+ resource=welcome;
+ else
{
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
+ doDirectory(request,response,resource);
+ base_request.setHandled(true);
return;
}
}
@@ -265,7 +269,7 @@ public class ResourceHandler extends AbstractHandler
long if_modified=request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
if (if_modified>0 && last_modified/1000<=if_modified/1000)
{
- response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ response.setStatus(HttpStatus.NOT_MODIFIED_304);
return;
}
}
@@ -297,6 +301,13 @@ public class ResourceHandler extends AbstractHandler
}
}
+ /* ------------------------------------------------------------ */
+ protected void doDirectory(HttpServletRequest request,HttpServletResponse response, Resource resource)
+ throws IOException
+ {
+ response.sendError(HttpStatus.FORBIDDEN_403);
+ }
+
/* ------------------------------------------------------------ */
/** Set the response headers.
* This method is called to set the response headers such as content type and content length.
diff --git a/pom.xml b/pom.xml
index d8aa15a4a72..379533af47d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -117,8 +117,9 @@
jetty-rewrite
jetty-servlet-tester
jetty-start
- jetty-distribution
+ jetty-embedded-examples
jetty-test-webapp
+ jetty-distribution