diff --git a/embedded/ee10-webapp-context/pom.xml b/embedded/ee10-webapp-context/pom.xml new file mode 100644 index 0000000..ebbe99c --- /dev/null +++ b/embedded/ee10-webapp-context/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + org.eclipse.jetty.examples.embedded + jetty-embedded-examples + 12.0.x + + ee10-webapp-context + 12.0.x + jar + Jetty Examples :: Jetty 12.0.x :: Embedded :: EE10 WebApp Context + + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + + org.eclipse.jetty.ee10 + jetty-ee10-webapp + ${jetty.version} + + + + org.eclipse.jetty.examples.webapps + hello-servlet-5 + ${project.version} + war + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.6.1 + + + copy-wars + + copy-dependencies + + generate-resources + + hello-servlet-3 + runtime + war + true + true + true + ${project.build.directory}/webapps + + + + + + + diff --git a/webapps/hello/src/main/java/examples/HelloServlet.java b/embedded/ee10-webapp-context/src/main/java/examples/HelloServlet.java similarity index 99% rename from webapps/hello/src/main/java/examples/HelloServlet.java rename to embedded/ee10-webapp-context/src/main/java/examples/HelloServlet.java index ac1d5e7..c5e5173 100644 --- a/webapps/hello/src/main/java/examples/HelloServlet.java +++ b/embedded/ee10-webapp-context/src/main/java/examples/HelloServlet.java @@ -14,6 +14,7 @@ package examples; import java.io.IOException; + import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; diff --git a/embedded/webapp-context/src/main/java/examples/WebAppContextFromClasspath.java b/embedded/ee10-webapp-context/src/main/java/examples/WebAppContextFromClasspath.java similarity index 100% rename from embedded/webapp-context/src/main/java/examples/WebAppContextFromClasspath.java rename to embedded/ee10-webapp-context/src/main/java/examples/WebAppContextFromClasspath.java index 3980b9a..0e22ac1 100644 --- a/embedded/webapp-context/src/main/java/examples/WebAppContextFromClasspath.java +++ b/embedded/ee10-webapp-context/src/main/java/examples/WebAppContextFromClasspath.java @@ -16,8 +16,8 @@ import java.net.URI; import java.net.URL; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.ee10.webapp.WebAppContext; +import org.eclipse.jetty.server.Server; public class WebAppContextFromClasspath { diff --git a/embedded/webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java b/embedded/ee10-webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java similarity index 93% rename from embedded/webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java rename to embedded/ee10-webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java index 26fb71e..95a9d54 100644 --- a/embedded/webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java +++ b/embedded/ee10-webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java @@ -17,8 +17,8 @@ import java.nio.file.Path; import java.nio.file.Paths; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.ee10.webapp.WebAppContext; +import org.eclipse.jetty.server.Server; public class WebAppContextFromFileSystem { @@ -26,7 +26,7 @@ public static void main(String[] args) throws Exception { Server server = new Server(8080); - Path warPath = Paths.get("../../webapps/hello/target/hello.war").toAbsolutePath().normalize(); + Path warPath = Paths.get("target/webapps/hello-servlet-5.war").toAbsolutePath().normalize(); if (!Files.isRegularFile(warPath)) { System.err.println("Unable to find " + warPath + ". Please build the entire project once first (`mvn clean install` from top of repo)"); diff --git a/embedded/webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml b/embedded/ee10-webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml similarity index 100% rename from embedded/webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml rename to embedded/ee10-webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml diff --git a/embedded/webapp-context/src/main/resources/hello-webapp/hello.html b/embedded/ee10-webapp-context/src/main/resources/hello-webapp/hello.html similarity index 100% rename from embedded/webapp-context/src/main/resources/hello-webapp/hello.html rename to embedded/ee10-webapp-context/src/main/resources/hello-webapp/hello.html diff --git a/embedded/ee8-webapp-context/pom.xml b/embedded/ee8-webapp-context/pom.xml new file mode 100644 index 0000000..3fd3d3a --- /dev/null +++ b/embedded/ee8-webapp-context/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + org.eclipse.jetty.examples.embedded + jetty-embedded-examples + 12.0.x + + ee8-webapp-context + 12.0.x + jar + Jetty Examples :: Jetty 12.0.x :: Embedded :: EE8 WebApp Context + + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + + org.eclipse.jetty + jetty-slf4j-impl + ${jetty.version} + + + + org.eclipse.jetty.ee8 + jetty-ee8-webapp + ${jetty.version} + + + + org.eclipse.jetty.examples.webapps + hello-servlet-3 + ${project.version} + war + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.6.1 + + + copy-wars + + copy-dependencies + + generate-resources + + hello-servlet-3 + runtime + war + true + true + true + ${project.build.directory}/webapps + + + + + + + diff --git a/embedded/ee8-webapp-context/src/main/java/examples/HelloServlet.java b/embedded/ee8-webapp-context/src/main/java/examples/HelloServlet.java new file mode 100644 index 0000000..e79e4fa --- /dev/null +++ b/embedded/ee8-webapp-context/src/main/java/examples/HelloServlet.java @@ -0,0 +1,45 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package examples; + +import java.io.IOException; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class HelloServlet extends HttpServlet +{ + private String msg; + + @Override + public void init(ServletConfig config) throws ServletException + { + super.init(config); + + msg = config.getInitParameter("message"); + if (msg == null) + { + msg = "User"; + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException + { + response.setContentType("text/plain"); + response.getWriter().printf("%s%n", msg); + } +} diff --git a/embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromClasspath.java b/embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromClasspath.java new file mode 100644 index 0000000..f627838 --- /dev/null +++ b/embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromClasspath.java @@ -0,0 +1,52 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package examples; + +import java.net.URI; +import java.net.URL; + +import org.eclipse.jetty.ee8.webapp.WebAppContext; +import org.eclipse.jetty.server.Server; + +public class WebAppContextFromClasspath +{ + public static void main(String[] args) throws Exception + { + Server server = new Server(8080); + + // Figure out what path to serve content from + ClassLoader cl = WebAppContextFromClasspath.class.getClassLoader(); + // We look for a file, as ClassLoader.getResource() is not + // designed to look for directories (we resolve the directory later) + URL f = cl.getResource("hello-webapp/hello.html"); + if (f == null) + { + throw new RuntimeException("Unable to find resource directory"); + } + + // Resolve file to directory + URI webRootUri = f.toURI().resolve("./").normalize(); + System.err.println("WebRoot is " + webRootUri); + + WebAppContext webapp = new WebAppContext(); + webapp.setContextPath("/"); + webapp.setWar(webRootUri.toASCIIString()); + webapp.setParentLoaderPriority(true); + + server.setHandler(webapp); + + server.start(); + server.join(); + } +} diff --git a/embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java b/embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java new file mode 100644 index 0000000..e22cfe9 --- /dev/null +++ b/embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java @@ -0,0 +1,62 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package examples; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.eclipse.jetty.ee8.webapp.WebAppContext; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.InetAccessHandler; + +public class WebAppContextFromFileSystem +{ + public static void main(String[] args) throws Exception + { + Server server = new Server(8080); + + Path warPath = Paths.get("target/webapps/hello-servlet-3.war").toAbsolutePath().normalize(); + if (!Files.isRegularFile(warPath)) + { + System.err.println("Unable to find " + warPath + ". Please build the entire project once first (`mvn clean install` from top of repo)"); + System.exit(-1); + } + + System.out.println("WAR File is " + warPath); + + InetAccessHandler inetAccessHandler = new InetAccessHandler(); + // allow only http clients from localhost IPv4 or IPv6 + inetAccessHandler.include("127.0.0.1", "::1"); + server.setHandler(inetAccessHandler); + + Handler.Sequence handlers = new Handler.Sequence(); + inetAccessHandler.setHandler(handlers); + + WebAppContext webapp = new WebAppContext(); + webapp.setContextPath("/"); + webapp.setWar(warPath.toUri().toASCIIString()); + + handlers.addHandler(webapp); + + // we should now have a handler tree like ... + // server.handler = InetAccessHandler + // wrapping -> Handler.Sequence + // contains -> WebAppContext + + server.start(); + server.join(); + } +} diff --git a/embedded/ee8-webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml b/embedded/ee8-webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml new file mode 100644 index 0000000..7ffc963 --- /dev/null +++ b/embedded/ee8-webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + hello webapp + + hello + examples.HelloServlet + + message + Hello from web.xml + + + + + hello + /hello + + + + hello.html + + \ No newline at end of file diff --git a/webapps/hello/src/main/webapp/hello.html b/embedded/ee8-webapp-context/src/main/resources/hello-webapp/hello.html similarity index 100% rename from webapps/hello/src/main/webapp/hello.html rename to embedded/ee8-webapp-context/src/main/resources/hello-webapp/hello.html diff --git a/embedded/pom.xml b/embedded/pom.xml index 9ef3b88..f805143 100644 --- a/embedded/pom.xml +++ b/embedded/pom.xml @@ -18,6 +18,8 @@ compressed-encoding connectors deploying + ee8-webapp-context + ee10-webapp-context error-handling file-server file-upload @@ -30,7 +32,6 @@ servlet-security simple-server virtual-hosts - webapp-context websocket-jakarta-api websocket-jetty-api xml diff --git a/embedded/webapp-context/pom.xml b/embedded/webapp-context/pom.xml deleted file mode 100644 index 27a47a8..0000000 --- a/embedded/webapp-context/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - 4.0.0 - - org.eclipse.jetty.examples.embedded - jetty-embedded-examples - 12.0.x - - webapp-context - 12.0.x - jar - Jetty Examples :: Jetty 12.0.x :: Embedded :: WebApp Context - - - - org.eclipse.jetty - jetty-server - ${jetty.version} - - - - org.eclipse.jetty.ee10 - jetty-ee10-webapp - ${jetty.version} - - - - org.eclipse.jetty.examples.webapps - hello - ${project.version} - war - - - diff --git a/pom.xml b/pom.xml index 02e19b8..908e54b 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ 17 6.2 jetty-examples - 12.0.5 + 12.0.6 diff --git a/webapps/hello-servlet-3/pom.xml b/webapps/hello-servlet-3/pom.xml new file mode 100644 index 0000000..e176cda --- /dev/null +++ b/webapps/hello-servlet-3/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + org.eclipse.jetty.examples.webapps + jetty-webapp-examples + 12.0.x + + hello-servlet-3 + 12.0.x + war + Jetty Examples :: Jetty 12.0.x :: Hello WebApp (Servlet 3.1) + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + hello + + + diff --git a/webapps/hello-servlet-3/src/main/java/examples/HelloServlet.java b/webapps/hello-servlet-3/src/main/java/examples/HelloServlet.java new file mode 100644 index 0000000..e79e4fa --- /dev/null +++ b/webapps/hello-servlet-3/src/main/java/examples/HelloServlet.java @@ -0,0 +1,45 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package examples; + +import java.io.IOException; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class HelloServlet extends HttpServlet +{ + private String msg; + + @Override + public void init(ServletConfig config) throws ServletException + { + super.init(config); + + msg = config.getInitParameter("message"); + if (msg == null) + { + msg = "User"; + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException + { + response.setContentType("text/plain"); + response.getWriter().printf("%s%n", msg); + } +} diff --git a/webapps/hello-servlet-3/src/main/webapp/WEB-INF/web.xml b/webapps/hello-servlet-3/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..debf554 --- /dev/null +++ b/webapps/hello-servlet-3/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + hello webapp + + hello + examples.HelloServlet + + message + Hello from webapps/hello + + + + + hello + /hello + + + + hello.html + + \ No newline at end of file diff --git a/webapps/hello-servlet-3/src/main/webapp/hello.html b/webapps/hello-servlet-3/src/main/webapp/hello.html new file mode 100644 index 0000000..4550829 --- /dev/null +++ b/webapps/hello-servlet-3/src/main/webapp/hello.html @@ -0,0 +1,12 @@ + + + Hello Example + + +

This is the classpath's hello-webapp /hello.html

+

+ See the /hello servlet output + +

+ + \ No newline at end of file diff --git a/webapps/hello/pom.xml b/webapps/hello-servlet-5/pom.xml similarity index 70% rename from webapps/hello/pom.xml rename to webapps/hello-servlet-5/pom.xml index 3bb4a37..c06a840 100644 --- a/webapps/hello/pom.xml +++ b/webapps/hello-servlet-5/pom.xml @@ -6,13 +6,21 @@ jetty-webapp-examples 12.0.x - hello + hello-servlet-5 12.0.x war Jetty Examples :: Jetty 12.0.x :: Hello WebApp + + + jakarta.servlet + jakarta.servlet-api + 5.0.0 + provided + + + hello - diff --git a/embedded/webapp-context/src/main/java/examples/HelloServlet.java b/webapps/hello-servlet-5/src/main/java/examples/HelloServlet.java similarity index 99% rename from embedded/webapp-context/src/main/java/examples/HelloServlet.java rename to webapps/hello-servlet-5/src/main/java/examples/HelloServlet.java index ac1d5e7..c5e5173 100644 --- a/embedded/webapp-context/src/main/java/examples/HelloServlet.java +++ b/webapps/hello-servlet-5/src/main/java/examples/HelloServlet.java @@ -14,6 +14,7 @@ package examples; import java.io.IOException; + import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; diff --git a/webapps/hello/src/main/webapp/WEB-INF/web.xml b/webapps/hello-servlet-5/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from webapps/hello/src/main/webapp/WEB-INF/web.xml rename to webapps/hello-servlet-5/src/main/webapp/WEB-INF/web.xml diff --git a/webapps/hello-servlet-5/src/main/webapp/hello.html b/webapps/hello-servlet-5/src/main/webapp/hello.html new file mode 100644 index 0000000..4550829 --- /dev/null +++ b/webapps/hello-servlet-5/src/main/webapp/hello.html @@ -0,0 +1,12 @@ + + + Hello Example + + +

This is the classpath's hello-webapp /hello.html

+

+ See the /hello servlet output + +

+ + \ No newline at end of file diff --git a/webapps/pom.xml b/webapps/pom.xml index 372e4ed..37d8328 100644 --- a/webapps/pom.xml +++ b/webapps/pom.xml @@ -10,19 +10,10 @@ jetty-webapp-examples 12.0.x pom - Jetty Examples :: Jetty 12.0.x :: WebApps + Jetty Examples :: Jetty 12.0.x :: Hello WebApp (Servlet 5) - hello + hello-servlet-3 + hello-servlet-5 - - - - jakarta.servlet - jakarta.servlet-api - 5.0.0 - provided - - -