Browse Source

added tomcat web server support

master
Jaryl Chng 1 year ago
parent
commit
4be948de77
10 changed files with 184 additions and 8 deletions
  1. +6
    -6
      README.md
  2. +2
    -0
      common-jersey/src/main/java/com/jarylchng/reactivemongoexample/common/CommonApplication.java
  3. +2
    -0
      common-resteasy/src/main/java/com/jarylchng/reactivemongoexample/common/CommonApplication.java
  4. +1
    -1
      netty-resteasy/src/main/java/com/jarylchng/reactivemongoexample/nettyresteasy/NettyResteasy.java
  5. +2
    -0
      pom.xml
  6. +48
    -0
      tomcat-jersey/pom.xml
  7. +42
    -0
      tomcat-jersey/src/main/java/com/jarylchng/reactivemongoexample/tomcatjersey/TomcatJersey.java
  8. +43
    -0
      tomcat-resteasy/pom.xml
  9. +37
    -0
      tomcat-resteasy/src/main/java/com/jarylchng/reactivemongoexample/tomcatresteasy/TomcatResteasy.java
  10. +1
    -1
      undertow-resteasy/src/main/java/com/jarylchng/reactivemongoexample/undertowresteasy/UndertowResteasy.java

+ 6
- 6
README.md View File

@ -1,13 +1,16 @@
# JAX-RS MongoDB ReactiveStreams to RxJava Examples
#### A one stop project for examples of using the ReactiveStreams MongoDB driver with RxJava.
### A one stop project for examples of using the ReactiveStreams MongoDB driver with RxJava.
#### Includes initializing with multiple embedded web servers for further reference and benchmarking
##### Note: runs embedded MongoDB on separate port 27018 by default, no need to install it.
# Current Implementations Done
- Jersey on Grizzly (grizzly-jersey)
- Jersey on Netty (netty-jersey)
- Jersey on Tomcat (tomcat-jersey)
- RestEasy on Undertow (undertow-resteasy)
- RestEasy on Netty (netty-resteasy)
- RestEasy on Tomcat (tomcat-resteasy)
## Resource references
- [Jersey Reactive Resource](https://gitlab.com/jarylc/jax-rs-mongodb-reactivestreams-to-rxjava-examples/blob/master/common-jersey/src/main/java/com/jarylchng/reactivemongoexample/common/ResourceReactive.java) - Jersey does not have support for RxJava and is implemented with Completable
@ -23,7 +26,7 @@ $ maven package
### Running
```sh
$ java -jar (implementation)/target/(implementation).jar
$ java -jar grizzly-jersey/target/grizzly-jersey.jar
$ java -jar grizzly-jersey/target/undertow-resteasy.jar
```
## 2. Endpoints
@ -38,7 +41,4 @@ $ java -jar grizzly-jersey/target/grizzly-jersey.jar
Use your tool of choice like [wrk](https://github.com/wg/wrk) or [JMeter](https://jmeter.apache.org/)
```sh
$ wrk -t12 -c400 -d30s http://127.0.0.1:8080/user/jaryl/Jaryl%20Chng/01189998819991197253
```
### Todos
- More implementations (Spring, etc.)
```

+ 2
- 0
common-jersey/src/main/java/com/jarylchng/reactivemongoexample/common/CommonApplication.java View File

@ -1,10 +1,12 @@
package com.jarylchng.reactivemongoexample.common;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@ApplicationPath("/")
public class CommonApplication extends Application {
@Override
public Set<Class<?>> getClasses() {

+ 2
- 0
common-resteasy/src/main/java/com/jarylchng/reactivemongoexample/common/CommonApplication.java View File

@ -1,10 +1,12 @@
package com.jarylchng.reactivemongoexample.common;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@ApplicationPath("/")
public class CommonApplication extends Application {
@Override
public Set<Class<?>> getClasses() {

+ 1
- 1
netty-resteasy/src/main/java/com/jarylchng/reactivemongoexample/nettyresteasy/NettyResteasy.java View File

@ -1,7 +1,7 @@
package com.jarylchng.reactivemongoexample.nettyresteasy;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import com.jarylchng.reactivemongoexample.common.CommonApplication;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import org.jboss.resteasy.core.ResteasyDeploymentImpl;
import org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer;
import org.jboss.resteasy.spi.ResteasyDeployment;

+ 2
- 0
pom.xml View File

@ -31,9 +31,11 @@
<module>grizzly-jersey</module>
<module>netty-jersey</module>
<module>tomcat-jersey</module>
<module>undertow-resteasy</module>
<module>netty-resteasy</module>
<module>tomcat-resteasy</module>
</modules>
<build>

+ 48
- 0
tomcat-jersey/pom.xml View File

@ -0,0 +1,48 @@
<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.jarylchng</groupId>
<artifactId>reactive-mongo-examples</artifactId>
<version>1.0</version>
</parent>
<artifactId>tomcat-jersey</artifactId>
<dependencies>
<dependency>
<groupId>com.jarylchng</groupId>
<artifactId>common-jersey</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.jarylchng.reactivemongoexample.tomcatjersey.TomcatJersey</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 42
- 0
tomcat-jersey/src/main/java/com/jarylchng/reactivemongoexample/tomcatjersey/TomcatJersey.java View File

@ -0,0 +1,42 @@
package com.jarylchng.reactivemongoexample.tomcatjersey;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import com.jarylchng.reactivemongoexample.common.ResourceReactive;
import com.jarylchng.reactivemongoexample.common.ResourceSynced;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import javax.servlet.annotation.WebFilter;
import javax.ws.rs.core.Application;
import java.io.File;
@WebFilter(asyncSupported = true)
public class TomcatJersey extends Application {
private static void startServer() throws LifecycleException {
Tomcat tomcat = new Tomcat();
File base = new File(System.getProperty("java.io.tmpdir"));
tomcat.setBaseDir(base.getAbsolutePath());
tomcat.setPort(8080);
Context context = tomcat.addWebapp("", base.getAbsolutePath());
Tomcat.addServlet(context, "tomcat-jersey",
new ServletContainer(new ResourceConfig()
.register(ResourceReactive.class)
.register(ResourceSynced.class)))
.setAsyncSupported(true);
context.addServletMappingDecoded("/*", "tomcat-jersey");
tomcat.start();
tomcat.getConnector();
}
public static void main(String[] args) throws LifecycleException {
EmbedMongo.start();
startServer();
}
}

+ 43
- 0
tomcat-resteasy/pom.xml View File

@ -0,0 +1,43 @@
<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.jarylchng</groupId>
<artifactId>reactive-mongo-examples</artifactId>
<version>1.0</version>
</parent>
<artifactId>tomcat-resteasy</artifactId>
<dependencies>
<dependency>
<groupId>com.jarylchng</groupId>
<artifactId>common-resteasy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.jarylchng.reactivemongoexample.tomcatresteasy.TomcatResteasy</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 37
- 0
tomcat-resteasy/src/main/java/com/jarylchng/reactivemongoexample/tomcatresteasy/TomcatResteasy.java View File

@ -0,0 +1,37 @@
package com.jarylchng.reactivemongoexample.tomcatresteasy;
import com.jarylchng.reactivemongoexample.common.CommonApplication;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;
import javax.ws.rs.core.Application;
import java.io.File;
public class TomcatResteasy extends Application {
private static void startServer() throws LifecycleException {
Tomcat tomcat = new Tomcat();
File base = new File(System.getProperty("java.io.tmpdir"));
tomcat.setBaseDir(base.getAbsolutePath());
tomcat.setPort(8080);
Context context = tomcat.addContext("", base.getAbsolutePath());
context.addApplicationListener(ResteasyBootstrap.class.getName());
Tomcat.addServlet(context, "tomcat-resteasy", new HttpServletDispatcher());
context.addParameter("javax.ws.rs.Application", CommonApplication.class.getName());
context.addServletMappingDecoded("/*", "tomcat-resteasy");
tomcat.start();
tomcat.getConnector();
}
public static void main(String[] args) throws LifecycleException {
EmbedMongo.start();
startServer();
}
}

+ 1
- 1
undertow-resteasy/src/main/java/com/jarylchng/reactivemongoexample/undertowresteasy/UndertowResteasy.java View File

@ -1,7 +1,7 @@
package com.jarylchng.reactivemongoexample.undertowresteasy;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import com.jarylchng.reactivemongoexample.common.CommonApplication;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import io.undertow.Undertow;
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;

Loading…
Cancel
Save