-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Porting over lowresource-access-webapp examples
- Loading branch information
Showing
16 changed files
with
595 additions
and
0 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,85 @@ | ||
<?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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.eclipse.jetty.examples</groupId> | ||
<artifactId>jetty-standalone-examples</artifactId> | ||
<version>9.4.x</version> | ||
</parent> | ||
|
||
<artifactId>lowresource-access</artifactId> | ||
<packaging>war</packaging> | ||
<name>lowresource-access</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<servlet.api.version>3.1.0</servlet.api.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>${servlet.api.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- used to reference LowResourceMonitor --> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
<version>${jetty.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-annotations</artifactId> | ||
<version>${jetty.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-deploy</artifactId> | ||
<version>${jetty.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-webapp</artifactId> | ||
<version>${jetty.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- test deps below --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.10.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>demo</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<executions> | ||
<execution> | ||
<id>copy-to-webapps</id> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<phase>install</phase> | ||
<configuration> | ||
<target> | ||
<copy file="${project.build.directory}/${project.build.finalName}.war" todir="${project.basedir}/webapps/" /> | ||
</target> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
standalone/lowresource-access/src/main/java/examples/AbstractLowResourceDumpServlet.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,34 @@ | ||
// | ||
// ======================================================================== | ||
// 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 java.util.Set; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.http.HttpServlet; | ||
|
||
import org.eclipse.jetty.server.LowResourceMonitor; | ||
|
||
public class AbstractLowResourceDumpServlet extends HttpServlet | ||
{ | ||
protected void dump(ServletOutputStream out, LowResourceMonitor monitor) throws IOException | ||
{ | ||
Set<LowResourceMonitor.LowResourceCheck> checks = monitor.getLowResourceChecks(); | ||
out.println("LowResourceChecks: "); | ||
for (LowResourceMonitor.LowResourceCheck check : checks) | ||
{ | ||
out.println(String.format(" (%s) %s%n", check.getClass().getName(), check)); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
standalone/lowresource-access/src/main/java/examples/FromBaseRequestServlet.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,40 @@ | ||
// | ||
// ======================================================================== | ||
// 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.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.eclipse.jetty.server.LowResourceMonitor; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Server; | ||
|
||
@WebServlet("/baserequest") | ||
public class FromBaseRequestServlet extends AbstractLowResourceDumpServlet | ||
{ | ||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | ||
{ | ||
Server server = Request.getBaseRequest(request).getHttpChannel().getServer(); | ||
|
||
LowResourceMonitor monitor = server.getBean(LowResourceMonitor.class); | ||
|
||
response.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/plain"); | ||
dump(response.getOutputStream(), monitor); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
standalone/lowresource-access/src/main/java/examples/FromRequestAttributeChannelServlet.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,41 @@ | ||
// | ||
// ======================================================================== | ||
// 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.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.eclipse.jetty.server.HttpChannel; | ||
import org.eclipse.jetty.server.LowResourceMonitor; | ||
import org.eclipse.jetty.server.Server; | ||
|
||
@WebServlet("/requestattribute/channel") | ||
public class FromRequestAttributeChannelServlet extends AbstractLowResourceDumpServlet | ||
{ | ||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | ||
{ | ||
HttpChannel channel = (HttpChannel)request.getAttribute(HttpChannel.class.getName()); | ||
Server server = channel.getServer(); | ||
|
||
LowResourceMonitor monitor = server.getBean(LowResourceMonitor.class); | ||
|
||
response.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/plain"); | ||
dump(response.getOutputStream(), monitor); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...lone/lowresource-access/src/main/java/examples/FromRequestAttributeConnectionServlet.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,41 @@ | ||
// | ||
// ======================================================================== | ||
// 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.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.eclipse.jetty.server.HttpConnection; | ||
import org.eclipse.jetty.server.LowResourceMonitor; | ||
import org.eclipse.jetty.server.Server; | ||
|
||
@WebServlet("/requestattribute/connection") | ||
public class FromRequestAttributeConnectionServlet extends AbstractLowResourceDumpServlet | ||
{ | ||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | ||
{ | ||
HttpConnection connection = (HttpConnection)request.getAttribute(HttpConnection.class.getName()); | ||
Server server = connection.getServer(); | ||
|
||
LowResourceMonitor monitor = server.getBean(LowResourceMonitor.class); | ||
|
||
response.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/plain"); | ||
dump(response.getOutputStream(), monitor); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
standalone/lowresource-access/src/main/java/examples/FromServletContextServlet.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,42 @@ | ||
// | ||
// ======================================================================== | ||
// 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.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.eclipse.jetty.server.LowResourceMonitor; | ||
|
||
@WebServlet("/servletcontext") | ||
public class FromServletContextServlet extends AbstractLowResourceDumpServlet | ||
{ | ||
private LowResourceMonitor monitor; | ||
|
||
@Override | ||
public void init() throws ServletException | ||
{ | ||
monitor = (LowResourceMonitor)getServletContext().getAttribute(LowResourceMonitor.class.getName()); | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | ||
{ | ||
response.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/plain"); | ||
dump(response.getOutputStream(), monitor); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
standalone/lowresource-access/src/main/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,5 @@ | ||
<?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>Accessing LowResourceMonitor from a Servlet</display-name> | ||
</web-app> |
Oops, something went wrong.