From 77a7ff3122a456ce8420510cfae871ceedb323b4 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 29 Oct 2012 16:11:03 +1100 Subject: [PATCH] 392237 more embedded examples --- .../eclipse/jetty/embedded/ExampleServer.java | 51 +++++++++++++++++++ .../jetty/embedded/ExampleServerXml.java | 31 +++++++++++ .../src/main/resources/exampleserver.xml | 39 ++++++++++++++ .../src/main/resources/fileserver.xml | 3 +- .../eclipse/jetty/xml/XmlConfiguration.java | 2 +- 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServer.java create mode 100644 examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServerXml.java create mode 100644 examples/embedded/src/main/resources/exampleserver.xml diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServer.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServer.java new file mode 100644 index 00000000000..7bdabf568e3 --- /dev/null +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServer.java @@ -0,0 +1,51 @@ +// +// ======================================================================== +// Copyright (c) 1995-2012 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.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.handler.DefaultHandler; +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.servlet.ServletContextHandler; + +public class ExampleServer +{ + public static void main(String[] args) throws Exception + { + Server server = new Server(); + + ServerConnector connector=new ServerConnector(server); + connector.setPort(8080); + server.setConnectors(new Connector[]{connector}); + + ServletContextHandler context = new ServletContextHandler(); + context.setContextPath("/hello"); + context.addServlet(HelloServlet.class,"/"); + + HandlerCollection handlers = new HandlerCollection(); + handlers.setHandlers(new Handler[]{context,new DefaultHandler()}); + server.setHandler(handlers); + + + server.start(); + server.join(); + } +} diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServerXml.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServerXml.java new file mode 100644 index 00000000000..3f9ec13a557 --- /dev/null +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ExampleServerXml.java @@ -0,0 +1,31 @@ +// +// ======================================================================== +// Copyright (c) 1995-2012 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.util.resource.Resource; +import org.eclipse.jetty.xml.XmlConfiguration; + +public class ExampleServerXml +{ + public static void main(String[] args) throws Exception + { + Resource fileserver_xml = Resource.newSystemResource("exampleserver.xml"); + XmlConfiguration.main(fileserver_xml.getFile().getAbsolutePath()); + } +} diff --git a/examples/embedded/src/main/resources/exampleserver.xml b/examples/embedded/src/main/resources/exampleserver.xml new file mode 100644 index 00000000000..896612e6386 --- /dev/null +++ b/examples/embedded/src/main/resources/exampleserver.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + 8080 + + + + + + + /hello + + org.eclipse.jetty.embedded.HelloServlet + / + + + + + + + + + + + + + + + + + + diff --git a/examples/embedded/src/main/resources/fileserver.xml b/examples/embedded/src/main/resources/fileserver.xml index ac3a76f5ac5..c12e29171e8 100644 --- a/examples/embedded/src/main/resources/fileserver.xml +++ b/examples/embedded/src/main/resources/fileserver.xml @@ -5,7 +5,8 @@ - + + 8080 diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 4eb0dcb2b8d..78776b2a987 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -1125,7 +1125,7 @@ public class XmlConfiguration * array of property and xml configuration filenames or {@link Resource}s. * @throws Exception if the XML configurations cannot be run */ - public static void main(final String[] args) throws Exception + public static void main(final String... args) throws Exception { final AtomicReference exception = new AtomicReference<>();