jetty embedded examples
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@593 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
c0a92fa463
commit
847142e536
|
@ -18,23 +18,28 @@ 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.log.Log;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* File server
|
||||
* 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(8080);
|
||||
Server server = new Server(args.length == 0?8080:Integer.parseInt(args[0]));
|
||||
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
resource_handler.setDirectoriesListed(true);
|
||||
resource_handler.setWelcomeFiles(new String[]{ "index.html" });
|
||||
|
||||
resource_handler.setResourceBase(".");
|
||||
resource_handler.setResourceBase(args.length == 2?args[1]:".");
|
||||
Log.info("serving " + resource_handler.getBaseResource());
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||
|
|
|
@ -47,13 +47,11 @@ public class HelloHandler extends AbstractHandler
|
|||
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
baseRequest.setHandled(true);
|
||||
|
||||
response.getWriter().println("<h1>"+_greeting+"</h1>");
|
||||
response.getWriter().println("from " + ((Request)request).getConnection().getConnector().getName());
|
||||
response.getWriter().println("<br/>");
|
||||
if (_body!=null)
|
||||
response.getWriter().println(_body);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,6 @@ public class ManyConnectors
|
|||
ssl_connector.setKeystore(jetty_home + "/etc/keystore");
|
||||
ssl_connector.setPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
|
||||
ssl_connector.setKeyPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
|
||||
ssl_connector.setTruststore(jetty_home + "/etc/keystore");
|
||||
ssl_connector.setTrustPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
|
||||
server.addConnector(ssl_connector);
|
||||
|
||||
server.setConnectors(new Connector[]
|
||||
|
|
|
@ -13,17 +13,9 @@
|
|||
|
||||
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.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.nio.SelectChannelConnector;
|
||||
|
|
|
@ -13,15 +13,7 @@
|
|||
|
||||
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.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -13,13 +13,6 @@
|
|||
|
||||
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;
|
||||
|
@ -35,6 +28,8 @@ public class OneServletContext
|
|||
server.setHandler(context);
|
||||
|
||||
context.addServlet(new ServletHolder(new HelloServlet()),"/*");
|
||||
context.addServlet(new ServletHolder(new HelloServlet("Buongiorno Mondo")),"/it/*");
|
||||
context.addServlet(new ServletHolder(new HelloServlet("Bonjour le Monde")),"/fr/*");
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
|
|
|
@ -19,15 +19,32 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** A Jetty Server Handler.
|
||||
*
|
||||
* A Handler instance is required by a {@link Server} to handle incoming
|
||||
* HTTP requests. A Handler may: <ul>
|
||||
* <li>Completely generate the HTTP Response</li>
|
||||
* <li>Examine/modify the request and call another Handler (see {@link HandlerWrapper}).
|
||||
* <li>Pass the request to one or more other Handlers (see {@link HandlerCollection}).
|
||||
* </ul>
|
||||
*
|
||||
* Handlers are passed the servlet API request and response object, but are
|
||||
* not Servlets. The servlet container is implemented by handlers for
|
||||
* context, security, session and servlet that modify the request object
|
||||
* before passing it to the next stage of handling.
|
||||
*
|
||||
*/
|
||||
public interface Handler extends LifeCycle
|
||||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Handle a request.
|
||||
* @param target The target of the request - either a URI or a name.
|
||||
* @param baseRequest TODO
|
||||
* @param baseRequest The original unwrapped request object.
|
||||
* @param request The request either as the {@link Request}
|
||||
* object or a wrapper of that request. The {@link HttpConnection#getCurrentConnection()}
|
||||
* method can be used access the Request object if required.
|
||||
|
|
Loading…
Reference in New Issue