Skip to content

Commit

Permalink
Merge branch 'master' into 3.4.2-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier committed May 22, 2017
2 parents eb9e3ca + 65f2dce commit afeb5c9
Show file tree
Hide file tree
Showing 263 changed files with 1,510 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,7 @@ the event bus.
=== Vert.x fatjar examples

The link:fatjar-examples/README.adoc[Vert.x fatjar Examples] show how you can build fatjar with Maven or Gradle.

=== Http/2 Showcase

This link:http2-showcase/README.md application highlights the benefits of HTTP/2 when dealing with latency on the web.
19 changes: 19 additions & 0 deletions grpc-examples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ You can run the server and then run the client.

You can read more about it on the http://www.grpc.io/docs/quickstart/java.html[gRPC website]

== SSL example

This example is the _Hello World example_ with SSL configuration.

It shows a simple gRPC service that invokes a service that
takes takes an `HelloRequest` string wrapper and returns an `HelloReply` string wrapper. The communication uses SSL.

link:src/main/java/io/vertx/example/grpc/ssl/Server.java[gRPC server example]

The gRPC service extends the `GreeterGrpc.GreeterVertxImplBase` generated class and
implements the service logic.

link:src/main/java/io/vertx/example/grpc/ssl/Client.java[gRPC client example]

The gRPC client creates an instance of the `GreeterGrpc.newVertxStub` generated class and
then use it to invoke the service.

You can run the server and then run the client.

== Route Guide example

This example is adapted from the https://github.com/grpc/grpc-java/tree/master/examples[gRPC examples].
Expand Down
6 changes: 6 additions & 0 deletions grpc-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>1.1.33.Fork26</version>
</dependency>

<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>jetty-alpn-agent</artifactId>
Expand Down
40 changes: 40 additions & 0 deletions grpc-examples/src/main/java/io/vertx/example/grpc/ssl/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.vertx.example.grpc.ssl;

import io.grpc.ManagedChannel;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloRequest;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.net.JksOptions;
import io.vertx.example.grpc.util.Runner;
import io.vertx.grpc.VertxChannelBuilder;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
public class Client extends AbstractVerticle {

public static void main(String[] args) {
Runner.runExample(Client.class);
}

@Override
public void start() throws Exception {
ManagedChannel channel = VertxChannelBuilder
.forAddress(vertx, "localhost", 8080)
.useSsl(options -> options.setSsl(true)
.setUseAlpn(true)
.setTrustStoreOptions(new JksOptions()
.setPath("tls/client-truststore.jks")
.setPassword("wibble")))
.build();
GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
stub.sayHello(request, asyncResponse -> {
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
} else {
asyncResponse.cause().printStackTrace();
}
});
}
}
47 changes: 47 additions & 0 deletions grpc-examples/src/main/java/io/vertx/example/grpc/ssl/Server.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.vertx.example.grpc.ssl;

import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.net.JksOptions;
import io.vertx.example.grpc.util.Runner;
import io.vertx.grpc.VertxServer;
import io.vertx.grpc.VertxServerBuilder;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
public class Server extends AbstractVerticle {

public static void main(String[] args) {
Runner.runExample(Server.class);
}

@Override
public void start() throws Exception {
VertxServer server = VertxServerBuilder.forPort(vertx, 8080)
.addService(new GreeterGrpc.GreeterVertxImplBase() {
@Override
public void sayHello(HelloRequest request, Future<HelloReply> future) {
System.out.println("Hello " + request.getName());
future.complete(HelloReply.newBuilder().setMessage(request.getName()).build());
}
})
.useSsl(options -> options
.setSsl(true)
.setUseAlpn(true)
.setKeyStoreOptions(new JksOptions()
.setPath("tls/server-keystore.jks")
.setPassword("wibble")))
.build();
server.start(ar -> {
if (ar.succeeded()) {
System.out.println("gRPC service started");
} else {
System.out.println("Could not start server " + ar.cause().getMessage());
}
});
}
}
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions http2-showcase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
### Vert.x HTTP/2 showcase

This projects aims at showing [Vert.x](http://vertx.io) [HTTP/2](https://en.wikipedia.org/wiki/HTTP/2) capabilities.

To run the project, simply run `./gradlew run` from the project's root directory, then point your browser at [http://localhost:8080](http://localhost:8080) to get started.

Two HTTP servers are running:

* An HTTP/1.1 server running on http://localhost:8080
* An HTTP/2 server running on https://localhost:8443

They both are running the exact same code, the only difference is that the second one has been declared with a specific option : `setUseAlpn(true)`.

By default, when running on your local machine, a latency of 100ms is arbitrarily simulated. So that you can figure out the difference it makes in a real-life environment.
You can change the latency by clicking on the links on the right of the image, or by adding a query parameter named `latency` to the page's URL.

e.g. [http://localhost:8080/image.hbs?latency=999](http://localhost:8080/image.hbs?latency=999)

The project uses :
* [Vert.x](http://vertx.io)
* [Vert.x web](http://vertx.io/docs/#web)
* [Handlebars](https://github.com/jknack/handlebars.java) as template engine

Licensed under [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0)

Any contribution is welcome.
28 changes: 28 additions & 0 deletions http2-showcase/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id 'java'
id 'application'
// id 'com.github.johnrengelman.shadow' version '1.2.4'
}

repositories {
mavenLocal()
}

dependencies {
compile "io.vertx:vertx-core:$vertxVersion"
compile "io.vertx:vertx-web:$vertxVersion"
compile "io.vertx:vertx-web-templ-handlebars:$vertxVersion"

runtime "io.netty:netty-tcnative-boringssl-static:1.1.33.Fork26"
}

mainClassName = 'io.vertx.core.Launcher'
def mainVerticle = 'io.vertx.examples.http2.Http2ServerVerticle'

run {
args = ['run', mainVerticle]
}

task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
1 change: 1 addition & 0 deletions http2-showcase/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vertxVersion=3.4.1
Binary file added http2-showcase/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions http2-showcase/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Apr 27 09:09:06 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
172 changes: 172 additions & 0 deletions http2-showcase/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
echo "$*"
}

die ( ) {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save ( ) {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit afeb5c9

Please sign in to comment.