Browse Source

added netty-resteasy

master
Jaryl Chng 1 year ago
parent
commit
408879d972
16 changed files with 261 additions and 44 deletions
  1. +6
    -1
      .gitlab-ci.yml
  2. +3
    -2
      README.md
  3. +58
    -0
      common-jersey/pom.xml
  4. +3
    -5
      common-jersey/src/main/java/com/jarylchng/reactivemongoexample/common/ResourceReactive.java
  5. +41
    -0
      common-resteasy/pom.xml
  6. +5
    -5
      common-resteasy/src/main/java/com/jarylchng/reactivemongoexample/common/ResourceReactive.java
  7. +3
    -6
      common-resteasy/src/main/java/com/jarylchng/reactivemongoexample/common/ResteasyApplication.java
  8. +2
    -2
      common/src/main/java/com/jarylchng/reactivemongoexample/common/ResourceSynced.java
  9. +1
    -6
      grizzly-jersey/pom.xml
  10. +0
    -1
      grizzly-jersey/src/main/java/com/jarylchng/reactivemongoexample/grizzlyjersey/GrizzlyJersey.java
  11. +90
    -0
      netty-resteasy/pom.xml
  12. +29
    -0
      netty-resteasy/src/main/java/com/jarylchng/reactivemongoexample/nettyresteasy/NettyResteasy.java
  13. +5
    -2
      pom.xml
  14. +9
    -0
      stub.sh
  15. +1
    -12
      undertow-resteasy/pom.xml
  16. +5
    -2
      undertow-resteasy/src/main/java/com/jarylchng/reactivemongoexample/undertowresteasy/UndertowResteasy.java

+ 6
- 1
.gitlab-ci.yml View File

@ -13,6 +13,11 @@ build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS package
- mkdir ci
- mv */target/*.jar ci
- rm ci/original-*.jar ci/common*.jar
- for f in ci/*; do cat stub.sh $f > $(echo $f | cut -d'/' -f 2); done
- chmod +x *.jar
artifacts:
paths:
- "*/target/*.jar"
- "*.jar"

+ 3
- 2
README.md View File

@ -4,8 +4,9 @@
##### Note: runs embedded MongoDB on separate port 27018 by default, no need to install it.
# Current Implementations Done
- Jersey on Grizzly container (grizzly-jersey)
- RestEasy on Undertow container (undertow-resteasy)
- Jersey on Grizzly (grizzly-jersey)
- RestEasy on Undertow (undertow-resteasy)
- RestEasy on Netty (netty-resteasy)
# Guide
## 1. Running implementations

+ 58
- 0
common-jersey/pom.xml View File

@ -0,0 +1,58 @@
<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>common-jersey</artifactId>
<dependencies>
<dependency>
<groupId>com.jarylchng</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- Java 9 workaround -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

grizzly-jersey/src/main/java/com/jarylchng/reactivemongoexample/grizzlyjersey/ResourceReactive.java → common-jersey/src/main/java/com/jarylchng/reactivemongoexample/common/ResourceReactive.java View File

@ -1,6 +1,4 @@
package com.jarylchng.reactivemongoexample.grizzlyjersey;
import com.jarylchng.reactivemongoexample.common.User;
package com.jarylchng.reactivemongoexample.common;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@ -14,7 +12,7 @@ import java.util.concurrent.CompletionStage;
public class ResourceReactive {
@GET
@Path("{userID}")
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_PLAIN)
public CompletionStage<String> getIt(@PathParam("userID") String userID) {
CompletableFuture<String> future = new CompletableFuture<>();
@ -28,7 +26,7 @@ public class ResourceReactive {
@GET
@Path("{userID}/{name}/{phoneNumber}")
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_PLAIN)
public CompletionStage<String> newUser(@PathParam("userID") String userID,
@PathParam("name") String name,
@PathParam("phoneNumber") String phoneNumber) {

+ 41
- 0
common-resteasy/pom.xml View File

@ -0,0 +1,41 @@
<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>common-resteasy</artifactId>
<dependencies>
<dependency>
<groupId>com.jarylchng</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-rxjava2</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

undertow-resteasy/src/main/java/com/jarylchng/reactivemongoexample/undertowresteasy/ResourceReactive.java → common-resteasy/src/main/java/com/jarylchng/reactivemongoexample/common/ResourceReactive.java View File

@ -1,19 +1,19 @@
package com.jarylchng.reactivemongoexample.undertowresteasy;
package com.jarylchng.reactivemongoexample.common;
import com.jarylchng.reactivemongoexample.common.User;
import com.mongodb.reactivestreams.client.Success;
import io.reactivex.Single;
import org.jboss.resteasy.annotations.Stream;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("async")
public class ResourceReactive {
@GET
@Path("{userID}")
@Stream
@Produces(MediaType.TEXT_PLAIN)
public Single<String> getIt(@PathParam("userID") String userID) {
return User.ReactiveDAO.findByID(userID)
.map(User::toString)
@ -22,7 +22,7 @@ public class ResourceReactive {
@GET
@Path("{userID}/{name}/{phoneNumber}")
@Stream
@Produces(MediaType.TEXT_PLAIN)
public Single<String> newUser(@PathParam("userID") String userID,
@PathParam("name") String name,
@PathParam("phoneNumber") String phoneNumber) {

undertow-resteasy/src/main/java/com/jarylchng/reactivemongoexample/undertowresteasy/Application.java → common-resteasy/src/main/java/com/jarylchng/reactivemongoexample/common/ResteasyApplication.java View File

@ -1,14 +1,11 @@
package com.jarylchng.reactivemongoexample.undertowresteasy;
package com.jarylchng.reactivemongoexample.common;
import com.jarylchng.reactivemongoexample.common.ResourceSynced;
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 Application extends javax.ws.rs.core.Application {
public class ResteasyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return Collections.emptySet();

+ 2
- 2
common/src/main/java/com/jarylchng/reactivemongoexample/common/ResourceSynced.java View File

@ -10,7 +10,7 @@ import javax.ws.rs.core.MediaType;
public class ResourceSynced {
@GET
@Path("{userID}")
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_PLAIN)
public String getIt(@PathParam("userID") String userID) {
User user = User.SyncedDAO.findByID(userID);
@ -22,7 +22,7 @@ public class ResourceSynced {
@GET
@Path("{userID}/{name}/{phoneNumber}")
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_PLAIN)
public String newUser(@PathParam("userID") String userID,
@PathParam("name") String name,
@PathParam("phoneNumber") String phoneNumber) {

+ 1
- 6
grizzly-jersey/pom.xml View File

@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>com.jarylchng</groupId>
<artifactId>common</artifactId>
<artifactId>common-jersey</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -22,11 +22,6 @@
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
<build>

+ 0
- 1
grizzly-jersey/src/main/java/com/jarylchng/reactivemongoexample/grizzlyjersey/GrizzlyJersey.java View File

@ -9,7 +9,6 @@ import java.net.URI;
public class GrizzlyJersey {
private static void startServer() {
final ResourceConfig rc = new ResourceConfig()
.packages("com.jarylchng.reactivemongoexample.grizzlyjersey")
.packages("com.jarylchng.reactivemongoexample.common");
GrizzlyHttpServerFactory.createHttpServer(URI.create("http://localhost:8080/"), rc);
}

+ 90
- 0
netty-resteasy/pom.xml View File

@ -0,0 +1,90 @@
<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>netty-resteasy</artifactId>
<dependencies>
<dependency>
<groupId>com.jarylchng</groupId>
<artifactId>common-resteasy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core-spi</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-netty4</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.jarylchng.reactivemongoexample.nettyresteasy.UndertowResteasy</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.jarylchng.reactivemongoexample.nettyresteasy.UndertowResteasy</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

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

@ -0,0 +1,29 @@
package com.jarylchng.reactivemongoexample.nettyresteasy;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import com.jarylchng.reactivemongoexample.common.ResteasyApplication;
import org.jboss.resteasy.core.ResteasyDeploymentImpl;
import org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer;
import org.jboss.resteasy.spi.ResteasyDeployment;
import javax.ws.rs.core.Application;
public class NettyResteasy extends Application {
private static void startServer() {
NettyJaxrsServer netty = new NettyJaxrsServer();
ResteasyDeployment deployment = new ResteasyDeploymentImpl();
deployment.setApplication(new ResteasyApplication());
netty.setDeployment(deployment);
netty.setHostname("localhost");
netty.setPort(8080);
netty.setRootResourcePath("/");
netty.setSecurityDomain(null);
netty.start();
}
public static void main(String[] args) {
EmbedMongo.start();
startServer();
}
}

+ 5
- 2
pom.xml View File

@ -17,16 +17,19 @@
<rxjava.version>2.2.10</rxjava.version>
<jersey.version>2.28</jersey.version>
<jersey.version>2.29</jersey.version>
<undertow.version>2.0.22.Final</undertow.version>
<resteasy.version>3.8.0.Final</resteasy.version>
<resteasy.version>4.1.1.Final</resteasy.version>
</properties>
<modules>
<module>common</module>
<module>common-jersey</module>
<module>common-resteasy</module>
<module>grizzly-jersey</module>
<module>undertow-resteasy</module>
<module>netty-resteasy</module>
</modules>
<dependencyManagement>

+ 9
- 0
stub.sh View File

@ -0,0 +1,9 @@
#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
java="$JAVA_HOME/bin/java"
fi
exec "$java" $java_args -jar $MYSELF "$@"
exit 1

+ 1
- 12
undertow-resteasy/pom.xml View File

@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>com.jarylchng</groupId>
<artifactId>common</artifactId>
<artifactId>common-resteasy</artifactId>
<version>${project.version}</version>
</dependency>
@ -23,22 +23,11 @@
<artifactId>undertow-servlet</artifactId>
<version>${undertow.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-undertow</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-rxjava2</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>
<build>

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

@ -1,17 +1,20 @@
package com.jarylchng.reactivemongoexample.undertowresteasy;
import com.jarylchng.reactivemongoexample.common.EmbedMongo;
import com.jarylchng.reactivemongoexample.common.ResteasyApplication;
import io.undertow.Undertow;
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
public class UndertowResteasy {
import javax.ws.rs.core.Application;
public class UndertowResteasy extends Application {
private static void startServer() {
String host = "localhost";
int port = 8080;
Undertow.Builder builder = Undertow.builder().addHttpListener(port, host);
UndertowJaxrsServer server = new UndertowJaxrsServer().start(builder);
server.deploy(Application.class, "/");
server.deploy(ResteasyApplication.class, "/");
}
public static void main(String[] args) {

Loading…
Cancel
Save