-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
1 parent
db30cc0
commit 99c3041
Showing
6 changed files
with
168 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,13 @@ | ||
|
||
## Install | ||
``` | ||
$ mvn install | ||
``` | ||
|
||
## Run | ||
``` | ||
$ mvn exec:java -Dexec.mainClass="com.pinpoint.test.plugin.JettyServerStarterMain" | ||
``` | ||
You can then access here: http://localhost:18080/ | ||
|
||
## Stop |
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,47 @@ | ||
<?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>com.navercorp.pinpoint</groupId> | ||
<artifactId>pinpoint-agent-testweb</artifactId> | ||
<version>2.5.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pinpoint-jetty-plugin-testweb</artifactId> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<pinpoint.agent.jvmargument> | ||
${pinpoint.agent.default.jvmargument} | ||
</pinpoint.agent.jvmargument> | ||
<jetty.version>9.4.42.v20210604</jetty.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
<version>${jetty.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-servlet</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
42 changes: 42 additions & 0 deletions
42
agent-testweb/jetty-plugin-testweb/src/main/java/com/pinpoint/test/plugin/AsyncServlet.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 @@ | ||
package com.pinpoint.test.plugin; | ||
|
||
import javax.servlet.AsyncContext; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.WriteListener; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class AsyncServlet extends HttpServlet { | ||
private static final String HEAVY_RESOURCE = "This is some heavy resource that will be served in an async way"; | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
ByteBuffer content = ByteBuffer.wrap(HEAVY_RESOURCE.getBytes(StandardCharsets.UTF_8)); | ||
|
||
AsyncContext async = request.startAsync(); | ||
ServletOutputStream out = response.getOutputStream(); | ||
out.setWriteListener(new WriteListener() { | ||
@Override | ||
public void onWritePossible() throws IOException { | ||
while (out.isReady()) { | ||
if (!content.hasRemaining()) { | ||
response.setStatus(200); | ||
async.complete(); | ||
return; | ||
} | ||
out.write(content.get()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
getServletContext().log("Async Error", t); | ||
async.complete(); | ||
} | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...-testweb/jetty-plugin-testweb/src/main/java/com/pinpoint/test/plugin/BlockingServlet.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,16 @@ | ||
package com.pinpoint.test.plugin; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class BlockingServlet extends HttpServlet { | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
response.setContentType("application/json"); | ||
response.setStatus(HttpServletResponse.SC_OK); | ||
response.getWriter().println("{ \"status\": \"ok\"}"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...b/jetty-plugin-testweb/src/main/java/com/pinpoint/test/plugin/JettyServerStarterMain.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,49 @@ | ||
package com.pinpoint.test.plugin; | ||
|
||
import org.eclipse.jetty.server.Connector; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.servlet.ServletHandler; | ||
import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
|
||
public class JettyServerStarterMain { | ||
|
||
private Server server; | ||
|
||
void start() throws Exception { | ||
|
||
int maxThreads = 10; | ||
int minThreads = 3; | ||
int idleTimeout = 30; | ||
|
||
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads, minThreads, idleTimeout); | ||
|
||
server = new Server(threadPool); | ||
ServerConnector connector = new ServerConnector(server); | ||
connector.setPort(18080); | ||
server.setConnectors(new Connector[]{connector}); | ||
|
||
ServletHandler servletHandler = new ServletHandler(); | ||
server.setHandler(servletHandler); | ||
|
||
servletHandler.addServletWithMapping(BlockingServlet.class, "/status"); | ||
servletHandler.addServletWithMapping(AsyncServlet.class, "/async"); | ||
|
||
server.start(); | ||
} | ||
|
||
void stop() throws Exception { | ||
if (server != null) { | ||
server.stop(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
JettyServerStarterMain starter = new JettyServerStarterMain(); | ||
try { | ||
starter.start(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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