-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
457 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.jetty.examples.embedded</groupId> | ||
<artifactId>jetty-embedded-examples</artifactId> | ||
<version>12.0.x</version> | ||
</parent> | ||
<artifactId>ee10-webapp-context</artifactId> | ||
<version>12.0.x</version> | ||
<packaging>jar</packaging> | ||
<name>Jetty Examples :: Jetty 12.0.x :: Embedded :: EE10 WebApp Context</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jetty.ee10</groupId> | ||
<artifactId>jetty-ee10-webapp</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jetty.examples.webapps</groupId> | ||
<artifactId>hello-servlet-5</artifactId> | ||
<version>${project.version}</version> | ||
<type>war</type> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>3.6.1</version> | ||
<executions> | ||
<execution> | ||
<id>copy-wars</id> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<phase>generate-resources</phase> | ||
<configuration> | ||
<includeArtifactIds>hello-servlet-3</includeArtifactIds> | ||
<includeScope>runtime</includeScope> | ||
<includeTypes>war</includeTypes> | ||
<overWriteSnapshots>true</overWriteSnapshots> | ||
<overWriteReleases>true</overWriteReleases> | ||
<stripVersion>true</stripVersion> | ||
<outputDirectory>${project.build.directory}/webapps</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.jetty.examples.embedded</groupId> | ||
<artifactId>jetty-embedded-examples</artifactId> | ||
<version>12.0.x</version> | ||
</parent> | ||
<artifactId>ee8-webapp-context</artifactId> | ||
<version>12.0.x</version> | ||
<packaging>jar</packaging> | ||
<name>Jetty Examples :: Jetty 12.0.x :: Embedded :: EE8 WebApp Context</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-slf4j-impl</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jetty.ee8</groupId> | ||
<artifactId>jetty-ee8-webapp</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jetty.examples.webapps</groupId> | ||
<artifactId>hello-servlet-3</artifactId> | ||
<version>${project.version}</version> | ||
<type>war</type> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>3.6.1</version> | ||
<executions> | ||
<execution> | ||
<id>copy-wars</id> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<phase>generate-resources</phase> | ||
<configuration> | ||
<includeArtifactIds>hello-servlet-3</includeArtifactIds> | ||
<includeScope>runtime</includeScope> | ||
<includeTypes>war</includeTypes> | ||
<overWriteSnapshots>true</overWriteSnapshots> | ||
<overWriteReleases>true</overWriteReleases> | ||
<stripVersion>true</stripVersion> | ||
<outputDirectory>${project.build.directory}/webapps</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
embedded/ee8-webapp-context/src/main/java/examples/HelloServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromClasspath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
embedded/ee8-webapp-context/src/main/java/examples/WebAppContextFromFileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
embedded/ee8-webapp-context/src/main/resources/hello-webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee | ||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||
version="3.1"> | ||
<display-name>hello webapp</display-name> | ||
<servlet> | ||
<servlet-name>hello</servlet-name> | ||
<servlet-class>examples.HelloServlet</servlet-class> | ||
<init-param> | ||
<param-name>message</param-name> | ||
<param-value>Hello from web.xml</param-value> | ||
</init-param> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>hello</servlet-name> | ||
<url-pattern>/hello</url-pattern> | ||
</servlet-mapping> | ||
|
||
<welcome-file-list> | ||
<welcome-file>hello.html</welcome-file> | ||
</welcome-file-list> | ||
</web-app> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.