From 3b552349ae49149ee379a46dd271a948f27065f5 Mon Sep 17 00:00:00 2001 From: "Edward M. Kagan" Date: Tue, 2 Nov 2021 23:07:00 +0300 Subject: [PATCH] Jersey test suite --- modules/jersey-grizzly2/pom.xml | 51 +++++++++++++++++ .../java/twopm/tech/bench/jaxrs/Bench.java | 22 ++++++++ .../twopm/tech/bench/jaxrs/TestResource.java | 33 +++++++++++ modules/jersey-jdk-http/pom.xml | 50 +++++++++++++++++ .../java/twopm/tech/bench/jaxrs/Bench.java | 20 +++++++ .../twopm/tech/bench/jaxrs/TestResource.java | 34 ++++++++++++ modules/jersey-jetty/pom.xml | 55 +++++++++++++++++++ .../java/twopm/tech/bench/jaxrs/Bench.java | 29 ++++++++++ .../twopm/tech/bench/jaxrs/TestResource.java | 33 +++++++++++ modules/jersey-netty/pom.xml | 55 +++++++++++++++++++ .../java/twopm/tech/bench/jaxrs/Bench.java | 27 +++++++++ .../twopm/tech/bench/jaxrs/TestResource.java | 33 +++++++++++ modules/jersey-simple-http/pom.xml | 50 +++++++++++++++++ .../java/twopm/tech/bench/jaxrs/Bench.java | 27 +++++++++ .../twopm/tech/bench/jaxrs/TestResource.java | 33 +++++++++++ pom.xml | 7 +++ 16 files changed, 559 insertions(+) create mode 100644 modules/jersey-grizzly2/pom.xml create mode 100644 modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/Bench.java create mode 100644 modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/TestResource.java create mode 100644 modules/jersey-jdk-http/pom.xml create mode 100644 modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java create mode 100644 modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java create mode 100644 modules/jersey-jetty/pom.xml create mode 100644 modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/Bench.java create mode 100644 modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java create mode 100644 modules/jersey-netty/pom.xml create mode 100644 modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/Bench.java create mode 100644 modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java create mode 100644 modules/jersey-simple-http/pom.xml create mode 100644 modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java create mode 100644 modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java diff --git a/modules/jersey-grizzly2/pom.xml b/modules/jersey-grizzly2/pom.xml new file mode 100644 index 0000000..fb983f2 --- /dev/null +++ b/modules/jersey-grizzly2/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + twopm.tech.jax-rs-bench + bom + 1.0-SNAPSHOT + ../../pom.xml + + jersey-grizzly2 + 1.0-SNAPSHOT + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + ${jersey.version} + + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven.shade.plugin.version} + + + package + + shade + + + false + + + + ${app.main.class} + + + + + + + + + diff --git a/modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/Bench.java b/modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/Bench.java new file mode 100644 index 0000000..341aa71 --- /dev/null +++ b/modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/Bench.java @@ -0,0 +1,22 @@ +package twopm.tech.bench.jaxrs; + +import java.io.IOException; +import java.net.URI; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; + +public class Bench { + + public static final String BASE_URI = "http://0.0.0.0:8080/"; + + public static void main(String[] args) throws IOException { + final ResourceConfig rc = new ResourceConfig().packages("twopm.tech.bench.jaxrs"); + final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + server.shutdownNow(); + })); + server.start(); + } + +} diff --git a/modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/TestResource.java b/modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/TestResource.java new file mode 100644 index 0000000..073e782 --- /dev/null +++ b/modules/jersey-grizzly2/src/main/java/twopm/tech/bench/jaxrs/TestResource.java @@ -0,0 +1,33 @@ +package twopm.tech.bench.jaxrs; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/test") +public class TestResource { + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public String index() { + return "{ \"status\" : \"OK\", \"method\" : \"GET\" }"; + } + + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String get(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"GET\", \"test\" : " + String.valueOf(id) + " }"; + } + + @POST + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String post(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"POST\", \"test\" : " + String.valueOf(id) + " }"; + } +} \ No newline at end of file diff --git a/modules/jersey-jdk-http/pom.xml b/modules/jersey-jdk-http/pom.xml new file mode 100644 index 0000000..95ccd2a --- /dev/null +++ b/modules/jersey-jdk-http/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + twopm.tech.jax-rs-bench + bom + 1.0-SNAPSHOT + ../../pom.xml + + jersey-jdk-http + 1.0-SNAPSHOT + + + org.glassfish.jersey.containers + jersey-container-jdk-http + ${jersey.version} + + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven.shade.plugin.version} + + + package + + shade + + + false + + + + ${app.main.class} + + + + + + + + + \ No newline at end of file diff --git a/modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java b/modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java new file mode 100644 index 0000000..277842c --- /dev/null +++ b/modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java @@ -0,0 +1,20 @@ +package twopm.tech.bench.jaxrs; + +import com.sun.net.httpserver.HttpServer; +import java.io.IOException; +import java.net.URI; +import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; + +public class Bench { + + public static final String BASE_URI = "http://0.0.0.0:8080/"; + + public static void main(String[] args) throws IOException, InterruptedException { + final ResourceConfig rc = new ResourceConfig().packages("twopm.tech.bench.jaxrs"); + final HttpServer server = JdkHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + server.stop(0); + })); + } +} diff --git a/modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java b/modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java new file mode 100644 index 0000000..095b609 --- /dev/null +++ b/modules/jersey-jdk-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java @@ -0,0 +1,34 @@ +package twopm.tech.bench.jaxrs; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; + + + +@Path("test") +public class TestResource { + + @GET +// @Path("/") + @Produces("application/json") + public String index() { + return "{ \"status\" : \"OK\", \"method\" : \"GET\" }"; + } + + @GET + @Path("{id}") + @Produces("application/json") + public String get(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"GET\", \"test\" : " + String.valueOf(id) + " }"; + } + + @POST + @Path("{id}") + @Produces("application/json") + public String post(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"POST\", \"test\" : " + String.valueOf(id) + " }"; + } +} \ No newline at end of file diff --git a/modules/jersey-jetty/pom.xml b/modules/jersey-jetty/pom.xml new file mode 100644 index 0000000..c64585c --- /dev/null +++ b/modules/jersey-jetty/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + twopm.tech.jax-rs-bench + bom + 1.0-SNAPSHOT + ../../pom.xml + + jersey-jetty + 1.0-SNAPSHOT + + + org.glassfish.jersey.containers + jersey-container-jetty-http + ${jersey.version} + + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + + + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet-api.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven.shade.plugin.version} + + + package + + shade + + + false + + + + ${app.main.class} + + + + + + + + + \ No newline at end of file diff --git a/modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/Bench.java b/modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/Bench.java new file mode 100644 index 0000000..498bbd6 --- /dev/null +++ b/modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/Bench.java @@ -0,0 +1,29 @@ +package twopm.tech.bench.jaxrs; + +import com.sun.net.httpserver.HttpServer; +import java.io.IOException; +import java.net.URI; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.eclipse.jetty.server.Server; +import org.glassfish.jersey.jetty.JettyHttpContainerFactory; +import org.glassfish.jersey.server.ResourceConfig; + +public class Bench { + + public static final String BASE_URI = "http://0.0.0.0:8080/"; + + public static void main(String[] args) throws IOException, Exception { + final ResourceConfig rc = new ResourceConfig().packages("twopm.tech.bench.jaxrs"); + final Server server = JettyHttpContainerFactory.createServer(URI.create(BASE_URI), rc); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + server.stop(); + } catch (Exception ex) { + Logger.getLogger(Bench.class.getName()).log(Level.SEVERE, null, ex); + } + })); + server.start(); + } + +} diff --git a/modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java b/modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java new file mode 100644 index 0000000..073e782 --- /dev/null +++ b/modules/jersey-jetty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java @@ -0,0 +1,33 @@ +package twopm.tech.bench.jaxrs; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/test") +public class TestResource { + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public String index() { + return "{ \"status\" : \"OK\", \"method\" : \"GET\" }"; + } + + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String get(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"GET\", \"test\" : " + String.valueOf(id) + " }"; + } + + @POST + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String post(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"POST\", \"test\" : " + String.valueOf(id) + " }"; + } +} \ No newline at end of file diff --git a/modules/jersey-netty/pom.xml b/modules/jersey-netty/pom.xml new file mode 100644 index 0000000..88f02e2 --- /dev/null +++ b/modules/jersey-netty/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + twopm.tech.jax-rs-bench + bom + 1.0-SNAPSHOT + ../../pom.xml + + jersey-netty + 1.0-SNAPSHOT + + + org.glassfish.jersey.containers + jersey-container-netty-http + ${jersey.version} + + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + + + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet-api.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven.shade.plugin.version} + + + package + + shade + + + false + + + + ${app.main.class} + + + + + + + + + \ No newline at end of file diff --git a/modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/Bench.java b/modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/Bench.java new file mode 100644 index 0000000..8f310c7 --- /dev/null +++ b/modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/Bench.java @@ -0,0 +1,27 @@ +package twopm.tech.bench.jaxrs; + +import io.netty.channel.Channel; +import java.io.IOException; +import java.net.URI; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.glassfish.jersey.netty.httpserver.NettyHttpContainerProvider; +import org.glassfish.jersey.server.ResourceConfig; + +public class Bench { + + public static final String BASE_URI = "http://0.0.0.0:8080/"; + + public static void main(String[] args) throws IOException, Exception { + final ResourceConfig rc = new ResourceConfig().packages("twopm.tech.bench.jaxrs"); + final Channel server = NettyHttpContainerProvider.createServer(URI.create(BASE_URI), rc, false); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + server.close(); + } catch (Exception ex) { + Logger.getLogger(Bench.class.getName()).log(Level.SEVERE, null, ex); + } + })); + } + +} diff --git a/modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java b/modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java new file mode 100644 index 0000000..073e782 --- /dev/null +++ b/modules/jersey-netty/src/main/java/twopm/tech/bench/jaxrs/TestResource.java @@ -0,0 +1,33 @@ +package twopm.tech.bench.jaxrs; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/test") +public class TestResource { + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public String index() { + return "{ \"status\" : \"OK\", \"method\" : \"GET\" }"; + } + + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String get(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"GET\", \"test\" : " + String.valueOf(id) + " }"; + } + + @POST + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String post(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"POST\", \"test\" : " + String.valueOf(id) + " }"; + } +} \ No newline at end of file diff --git a/modules/jersey-simple-http/pom.xml b/modules/jersey-simple-http/pom.xml new file mode 100644 index 0000000..8400673 --- /dev/null +++ b/modules/jersey-simple-http/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + twopm.tech.jax-rs-bench + bom + 1.0-SNAPSHOT + ../../pom.xml + + jersey-simple-http + 1.0-SNAPSHOT + + + org.glassfish.jersey.containers + jersey-container-simple-http + ${jersey.version} + + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven.shade.plugin.version} + + + package + + shade + + + false + + + + ${app.main.class} + + + + + + + + + \ No newline at end of file diff --git a/modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java b/modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java new file mode 100644 index 0000000..6063b5f --- /dev/null +++ b/modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/Bench.java @@ -0,0 +1,27 @@ +package twopm.tech.bench.jaxrs; + +import java.io.IOException; +import java.net.URI; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.simple.SimpleContainerFactory; +import org.glassfish.jersey.simple.SimpleServer; + +public class Bench { + + public static final String BASE_URI = "http://0.0.0.0:8080/"; + + public static void main(String[] args) throws IOException { + final ResourceConfig rc = new ResourceConfig().packages("twopm.tech.bench.jaxrs"); + final SimpleServer server = SimpleContainerFactory.create(URI.create(BASE_URI), rc); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + server.close(); + } catch (IOException ex) { + Logger.getLogger(Bench.class.getName()).log(Level.SEVERE, null, ex); + } + })); + } + +} diff --git a/modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java b/modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java new file mode 100644 index 0000000..073e782 --- /dev/null +++ b/modules/jersey-simple-http/src/main/java/twopm/tech/bench/jaxrs/TestResource.java @@ -0,0 +1,33 @@ +package twopm.tech.bench.jaxrs; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/test") +public class TestResource { + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public String index() { + return "{ \"status\" : \"OK\", \"method\" : \"GET\" }"; + } + + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String get(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"GET\", \"test\" : " + String.valueOf(id) + " }"; + } + + @POST + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public String post(@PathParam("id") Long id) { + return "{ \"status\" : \"OK\", \"method\" : \"POST\", \"test\" : " + String.valueOf(id) + " }"; + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 392f1ee..cecbfd6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,11 @@ 1.0-SNAPSHOT pom + modules/jersey-grizzly2 + modules/jersey-jdk-http + modules/jersey-simple-http + modules/jersey-jetty + modules/jersey-netty modules/rawnetty modules/jooby-netty modules/jooby-jetty @@ -23,6 +28,8 @@ 3.2.4 4.1.69.Final 2.11.0 + 3.0.3 + 5.0.0 UTF-8 UTF-8 quarkus-bom