examples: move TLS example to a separate project

This commit is contained in:
ZHANG Dapeng 2018-12-06 12:03:25 -08:00 committed by GitHub
parent 2d654496ee
commit 3202fcc7d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 420 additions and 168 deletions

View File

@ -24,6 +24,7 @@ install:
- pushd examples && ./gradlew build && popd - pushd examples && ./gradlew build && popd
- pushd examples && mvn verify && popd - pushd examples && mvn verify && popd
- pushd examples/example-alts && ./gradlew build && popd - pushd examples/example-alts && ./gradlew build && popd
- pushd examples/example-tls && ../gradlew clean build && popd
- pushd examples/example-kotlin && ./gradlew build && popd - pushd examples/example-kotlin && ./gradlew build && popd
before_script: before_script:

View File

@ -222,7 +222,8 @@ subprojects {
// Keep the following references of tcnative version in sync whenever it's updated // Keep the following references of tcnative version in sync whenever it's updated
// SECURITY.md (multiple occurrences) // SECURITY.md (multiple occurrences)
// examples/build.gradle // examples/example-tls/build.gradle
// examples/example-tls/pom.xml
netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.20.Final', netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.20.Final',
conscrypt: 'org.conscrypt:conscrypt-openjdk-uber:1.0.1', conscrypt: 'org.conscrypt:conscrypt-openjdk-uber:1.0.1',

View File

@ -9,7 +9,3 @@ bazel build ...
cd examples cd examples
bazel clean bazel clean
bazel build ... bazel build ...
cd example-alts
bazel clean
bazel build ...

View File

@ -61,6 +61,9 @@ if [[ -z "${SKIP_TESTS:-}" ]]; then
# --batch-mode reduces log spam # --batch-mode reduces log spam
mvn clean verify --batch-mode mvn clean verify --batch-mode
popd popd
pushd examples/example-tls
mvn clean verify --batch-mode
popd
# TODO(zpencer): also build the GAE examples # TODO(zpencer): also build the GAE examples
fi fi

View File

@ -69,15 +69,15 @@ java_library(
"@com_google_api_grpc_proto_google_common_protos//jar", "@com_google_api_grpc_proto_google_common_protos//jar",
"@com_google_code_findbugs_jsr305//jar", "@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar", "@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@com_google_protobuf//:protobuf_java", "@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util", "@com_google_protobuf//:protobuf_java_util",
"@io_grpc_grpc_java//core", "@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//netty",
"@io_grpc_grpc_java//protobuf", "@io_grpc_grpc_java//protobuf",
"@io_grpc_grpc_java//stub", "@io_grpc_grpc_java//stub",
"@io_netty_netty_handler//jar",
], ],
runtime_deps = [
"@io_grpc_grpc_java//netty",
]
) )
java_binary( java_binary(
@ -133,23 +133,3 @@ java_binary(
":examples", ":examples",
], ],
) )
java_binary(
name = "hello-world-tls-client",
testonly = 1,
main_class = "io.grpc.examples.helloworldtls.HelloWorldClientTls",
runtime_deps = [
":examples",
"@io_netty_netty_tcnative_boringssl_static//jar",
],
)
java_binary(
name = "hello-world-tls-server",
testonly = 1,
main_class = "io.grpc.examples.helloworldtls.HelloWorldServerTls",
runtime_deps = [
":examples",
"@io_netty_netty_tcnative_boringssl_static//jar",
],
)

View File

@ -15,8 +15,7 @@ To build the examples, run in this directory:
$ ./gradlew installDist $ ./gradlew installDist
``` ```
This creates the scripts `hello-world-server`, `hello-world-client`, This creates the scripts `hello-world-server`, `hello-world-client`,
`hello-world-tls-server`, `hello-world-tls-client`,
`route-guide-server`, and `route-guide-client` in the `route-guide-server`, and `route-guide-client` in the
`build/install/examples/bin/` directory that run the examples. Each `build/install/examples/bin/` directory that run the examples. Each
example requires the server to be running before starting the client. example requires the server to be running before starting the client.
@ -33,84 +32,6 @@ And in a different terminal window run:
$ ./build/install/examples/bin/hello-world-client $ ./build/install/examples/bin/hello-world-client
``` ```
### Hello World with TLS
Running the hello world with TLS is the same as the normal hello world, but takes additional args:
**hello-world-tls-server**:
```text
USAGE: HelloWorldServerTls host port certChainFilePath privateKeyFilePath [trustCertCollectionFilePath]
Note: You only need to supply trustCertCollectionFilePath if you want to enable Mutual TLS.
```
**hello-world-tls-client**:
```text
USAGE: HelloWorldClientTls host port trustCertCollectionFilePath [clientCertChainFilePath clientPrivateKeyFilePath]
Note: clientCertChainFilePath and clientPrivateKeyFilePath are only needed if mutual auth is desired.
```
#### Generating self-signed certificates for use with grpc
You can use the following script to generate self-signed certificates for grpc-java including the hello world with TLS examples:
```bash
mkdir -p /tmp/sslcert
pushd /tmp/sslcert
# Changes these CN's to match your hosts in your environment if needed.
SERVER_CN=localhost
CLIENT_CN=localhost # Used when doing mutual TLS
echo Generate CA key:
openssl genrsa -passout pass:1111 -des3 -out ca.key 4096
echo Generate CA certificate:
# Generates ca.crt which is the trustCertCollectionFile
openssl req -passin pass:1111 -new -x509 -days 365 -key ca.key -out ca.crt -subj "/CN=${SERVER_CN}"
echo Generate server key:
openssl genrsa -passout pass:1111 -des3 -out server.key 4096
echo Generate server signing request:
openssl req -passin pass:1111 -new -key server.key -out server.csr -subj "/CN=${SERVER_CN}"
echo Self-signed server certificate:
# Generates server.crt which is the certChainFile for the server
openssl x509 -req -passin pass:1111 -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
echo Remove passphrase from server key:
openssl rsa -passin pass:1111 -in server.key -out server.key
echo Generate client key
openssl genrsa -passout pass:1111 -des3 -out client.key 4096
echo Generate client signing request:
openssl req -passin pass:1111 -new -key client.key -out client.csr -subj "/CN=${CLIENT_CN}"
echo Self-signed client certificate:
# Generates client.crt which is the clientCertChainFile for the client (need for mutual TLS only)
openssl x509 -passin pass:1111 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt
echo Remove passphrase from client key:
openssl rsa -passin pass:1111 -in client.key -out client.key
echo Converting the private keys to X.509:
# Generates client.pem which is the clientPrivateKeyFile for the Client (needed for mutual TLS only)
openssl pkcs8 -topk8 -nocrypt -in client.key -out client.pem
# Generates server.pem which is the privateKeyFile for the Server
openssl pkcs8 -topk8 -nocrypt -in server.key -out server.pem
popd
```
#### Hello world example with TLS (no mutual auth):
```bash
# Server
./build/install/examples/bin/hello-world-tls-server localhost 50440 /tmp/sslcert/server.crt /tmp/sslcert/server.pem
# Client
./build/install/examples/bin/hello-world-tls-client localhost 50440 /tmp/sslcert/ca.crt
```
#### Hello world example with TLS with mutual auth:
```bash
# Server
./build/install/examples/bin/hello-world-tls-server localhost 54440 /tmp/sslcert/server.crt /tmp/sslcert/server.pem /tmp/sslcert/ca.crt
# Client
./build/install/examples/bin/hello-world-tls-client localhost 54440 /tmp/sslcert/ca.crt /tmp/sslcert/client.crt /tmp/sslcert/client.pem
```
That's it! That's it!
Please refer to gRPC Java's [README](../README.md) and Please refer to gRPC Java's [README](../README.md) and
@ -134,12 +55,24 @@ If you prefer to use Bazel:
``` ```
(With Bazel v0.8.0 or above.) (With Bazel v0.8.0 or above.)
$ bazel build :hello-world-server :hello-world-client $ bazel build :hello-world-server :hello-world-client
$ # Run the server: $ # Run the server
$ bazel-bin/hello-world-server $ bazel-bin/hello-world-server
$ # In another terminal run the client $ # In another terminal run the client
$ bazel-bin/hello-world-client $ bazel-bin/hello-world-client
``` ```
## Other examples
### [Android examples](android)
### [Kotlin examples](example-kotlin)
### [Kotlin Android examples](example-kotlin/android)
### [TLS examples](example-tls)
### [ALTS examples](example-tls)
Unit test examples Unit test examples
============================================== ==============================================

View File

@ -23,23 +23,19 @@ targetCompatibility = 1.7
// Feel free to delete the comment at the next line. It is just for safely // Feel free to delete the comment at the next line. It is just for safely
// updating the version in our release process. // updating the version in our release process.
def grpcVersion = '1.18.0-SNAPSHOT' // CURRENT_GRPC_VERSION def grpcVersion = '1.18.0-SNAPSHOT' // CURRENT_GRPC_VERSION
def nettyTcNativeVersion = '2.0.20.Final'
def protobufVersion = '3.5.1' def protobufVersion = '3.5.1'
def protocVersion = '3.5.1-1' def protocVersion = '3.5.1-1'
dependencies { dependencies {
implementation "com.google.api.grpc:proto-google-common-protos:1.0.0"
implementation "io.grpc:grpc-netty-shaded:${grpcVersion}"
implementation "io.grpc:grpc-protobuf:${grpcVersion}" implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}" implementation "io.grpc:grpc-stub:${grpcVersion}"
compileOnly "javax.annotation:javax.annotation-api:1.2" compileOnly "javax.annotation:javax.annotation-api:1.2"
// Used in HelloWorldServerTls // examples/advanced need this for JsonFormat
implementation "io.grpc:grpc-netty:${grpcVersion}"
implementation "io.netty:netty-tcnative-boringssl-static:${nettyTcNativeVersion}"
implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}" implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
testImplementation "io.grpc:grpc-testing:${grpcVersion}" testImplementation "io.grpc:grpc-testing:${grpcVersion}"
testImplementation "junit:junit:4.12" testImplementation "junit:junit:4.12"
testImplementation "org.mockito:mockito-core:1.9.5" testImplementation "org.mockito:mockito-core:1.9.5"
@ -95,20 +91,6 @@ task helloWorldClient(type: CreateStartScripts) {
classpath = startScripts.classpath classpath = startScripts.classpath
} }
task helloWorldTlsServer(type: CreateStartScripts) {
mainClassName = 'io.grpc.examples.helloworldtls.HelloWorldServerTls'
applicationName = 'hello-world-tls-server'
outputDir = new File(project.buildDir, 'tmp')
classpath = startScripts.classpath
}
task helloWorldTlsClient(type: CreateStartScripts) {
mainClassName = 'io.grpc.examples.helloworldtls.HelloWorldClientTls'
applicationName = 'hello-world-tls-client'
outputDir = new File(project.buildDir, 'tmp')
classpath = startScripts.classpath
}
task compressingHelloWorldClient(type: CreateStartScripts) { task compressingHelloWorldClient(type: CreateStartScripts) {
mainClassName = 'io.grpc.examples.experimental.CompressingHelloWorldClient' mainClassName = 'io.grpc.examples.experimental.CompressingHelloWorldClient'
applicationName = 'compressing-hello-world-client' applicationName = 'compressing-hello-world-client'
@ -121,8 +103,6 @@ applicationDistribution.into('bin') {
from(routeGuideClient) from(routeGuideClient)
from(helloWorldServer) from(helloWorldServer)
from(helloWorldClient) from(helloWorldClient)
from(helloWorldTlsServer)
from(helloWorldTlsClient)
from(compressingHelloWorldClient) from(compressingHelloWorldClient)
fileMode = 0755 fileMode = 0755
} }

View File

@ -1,16 +0,0 @@
workspace(name = "example_alts")
# For released versions, use the tagged git-repository:
# git_repository(
# name = "io_grpc_grpc_java",
# remote = "https://github.com/grpc/grpc-java.git",
# tag = "<TAG>",
# )
local_repository(
name = "io_grpc_grpc_java",
path = "../..",
)
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
grpc_java_repositories()

View File

@ -0,0 +1,55 @@
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
proto_library(
name = "helloworld_proto",
srcs = ["src/main/proto/helloworld/helloworld.proto"],
)
java_proto_library(
name = "helloworld_java_proto",
deps = [":helloworld_proto"],
)
java_grpc_library(
name = "helloworld_java_grpc",
srcs = [":helloworld_proto"],
deps = [":helloworld_java_proto"],
)
java_library(
name = "example-tls",
testonly = 1,
srcs = glob(
["src/main/java/**/*.java"],
),
deps = [
":helloworld_java_grpc",
":helloworld_java_proto",
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//netty",
"@io_grpc_grpc_java//protobuf",
"@io_grpc_grpc_java//stub",
"@io_netty_netty_handler//jar",
],
runtime_deps = [
"@io_netty_netty_tcnative_boringssl_static//jar",
]
)
java_binary(
name = "hello-world-tls-client",
testonly = 1,
main_class = "io.grpc.examples.helloworldtls.HelloWorldClientTls",
runtime_deps = [
":example-tls",
],
)
java_binary(
name = "hello-world-tls-server",
testonly = 1,
main_class = "io.grpc.examples.helloworldtls.HelloWorldServerTls",
runtime_deps = [
":example-tls",
],
)

View File

@ -0,0 +1,118 @@
Hello World Example with TLS
==============================================
The example require grpc-java to already be built. You are strongly encouraged
to check out a git release tag, since there will already be a build of grpc
available. Otherwise you must follow [COMPILING](../COMPILING.md).
To build the example, run in this directory:
```
$ ../gradlew installDist
```
This creates the scripts `hello-world-tls-server`, `hello-world-tls-client`,
in the
`build/install/example-tls/bin/` directory that run the example. The
example requires the server to be running before starting the client.
Running the hello world with TLS is the same as the normal hello world, but takes additional args:
**hello-world-tls-server**:
```text
USAGE: HelloWorldServerTls host port certChainFilePath privateKeyFilePath [trustCertCollectionFilePath]
Note: You only need to supply trustCertCollectionFilePath if you want to enable Mutual TLS.
```
**hello-world-tls-client**:
```text
USAGE: HelloWorldClientTls host port trustCertCollectionFilePath [clientCertChainFilePath clientPrivateKeyFilePath]
Note: clientCertChainFilePath and clientPrivateKeyFilePath are only needed if mutual auth is desired.
```
#### Generating self-signed certificates for use with grpc
You can use the following script to generate self-signed certificates for grpc-java including the hello world with TLS examples:
```bash
mkdir -p /tmp/sslcert
pushd /tmp/sslcert
# Changes these CN's to match your hosts in your environment if needed.
SERVER_CN=localhost
CLIENT_CN=localhost # Used when doing mutual TLS
echo Generate CA key:
openssl genrsa -passout pass:1111 -des3 -out ca.key 4096
echo Generate CA certificate:
# Generates ca.crt which is the trustCertCollectionFile
openssl req -passin pass:1111 -new -x509 -days 365 -key ca.key -out ca.crt -subj "/CN=${SERVER_CN}"
echo Generate server key:
openssl genrsa -passout pass:1111 -des3 -out server.key 4096
echo Generate server signing request:
openssl req -passin pass:1111 -new -key server.key -out server.csr -subj "/CN=${SERVER_CN}"
echo Self-signed server certificate:
# Generates server.crt which is the certChainFile for the server
openssl x509 -req -passin pass:1111 -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
echo Remove passphrase from server key:
openssl rsa -passin pass:1111 -in server.key -out server.key
echo Generate client key
openssl genrsa -passout pass:1111 -des3 -out client.key 4096
echo Generate client signing request:
openssl req -passin pass:1111 -new -key client.key -out client.csr -subj "/CN=${CLIENT_CN}"
echo Self-signed client certificate:
# Generates client.crt which is the clientCertChainFile for the client (need for mutual TLS only)
openssl x509 -passin pass:1111 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt
echo Remove passphrase from client key:
openssl rsa -passin pass:1111 -in client.key -out client.key
echo Converting the private keys to X.509:
# Generates client.pem which is the clientPrivateKeyFile for the Client (needed for mutual TLS only)
openssl pkcs8 -topk8 -nocrypt -in client.key -out client.pem
# Generates server.pem which is the privateKeyFile for the Server
openssl pkcs8 -topk8 -nocrypt -in server.key -out server.pem
popd
```
#### Hello world example with TLS (no mutual auth):
```bash
# Run the server:
./build/install/example-tls/bin/hello-world-tls-server localhost 50440 /tmp/sslcert/server.crt /tmp/sslcert/server.pem
# In another terminal run the client
./build/install/example-tls/bin/hello-world-tls-client localhost 50440 /tmp/sslcert/ca.crt
```
#### Hello world example with TLS with mutual auth:
```bash
# Run the server:
./build/install/example-tls/bin/hello-world-tls-serverlocalhost 54440 /tmp/sslcert/server.crt /tmp/sslcert/server.pem /tmp/sslcert/ca.crt
# In another terminal run the client
./build/install/example-tls/bin/hello-world-tls-client localhost 54440 /tmp/sslcert/ca.crt /tmp/sslcert/client.crt /tmp/sslcert/client.pem
```
That's it!
## Maven
If you prefer to use Maven:
```
$ mvn verify
$ # Run the server
$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworldtls.HelloWorldServerTls -Dexec.args="localhost 50440 /tmp/sslcert/server.crt /tmp/sslcert/server.pem"
$ # In another terminal run the client
$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworldtls.HelloWorldClientTls -Dexec.args="localhost 50440 /tmp/sslcert/ca.crt"
```
## Bazel
If you prefer to use Bazel:
```
(With Bazel v0.8.0 or above.)
$ bazel build :hello-world-tls-server :hello-world-tls-client
$ # Run the server
$ bazel-bin/hello-world-tls-server localhost 50440 /tmp/sslcert/server.crt /tmp/sslcert/server.pem
$ # In another terminal run the client
$ bazel-bin/hello-world-tls-client localhost 50440 /tmp/sslcert/ca.crt
```

View File

@ -0,0 +1,77 @@
plugins {
// Provide convenience executables for trying out the examples.
id 'application'
// ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier gradle versions
id 'com.google.protobuf' version '0.8.5'
// Generate IntelliJ IDEA's .idea & .iml project files
id 'idea'
}
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/"
}
mavenLocal()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
// IMPORTANT: You probably want the non-SNAPSHOT version of gRPC. Make sure you
// are looking at a tagged version of the example and not "master"!
// Feel free to delete the comment at the next line. It is just for safely
// updating the version in our release process.
def grpcVersion = '1.18.0-SNAPSHOT' // CURRENT_GRPC_VERSION
def nettyTcNativeVersion = '2.0.20.Final'
def protocVersion = '3.5.1-1'
dependencies {
implementation "io.grpc:grpc-netty:${grpcVersion}"
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"
compileOnly "javax.annotation:javax.annotation-api:1.2"
runtimeOnly "io.netty:netty-tcnative-boringssl-static:${nettyTcNativeVersion}"
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
}
generateProtoTasks {
all()*.plugins { grpc {} }
}
}
// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
startScripts.enabled = false
task helloWorldTlsServer(type: CreateStartScripts) {
mainClassName = 'io.grpc.examples.helloworldtls.HelloWorldServerTls'
applicationName = 'hello-world-tls-server'
outputDir = new File(project.buildDir, 'tmp')
classpath = startScripts.classpath
}
task helloWorldTlsClient(type: CreateStartScripts) {
mainClassName = 'io.grpc.examples.helloworldtls.HelloWorldClientTls'
applicationName = 'hello-world-tls-client'
outputDir = new File(project.buildDir, 'tmp')
classpath = startScripts.classpath
}
applicationDistribution.into('bin') {
from(helloWorldTlsServer)
from(helloWorldTlsClient)
fileMode = 0755
}

View File

@ -0,0 +1,97 @@
<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>
<groupId>io.grpc</groupId>
<artifactId>example-tls</artifactId>
<packaging>jar</packaging>
<!-- Feel free to delete the comment at the end of these lines. It is just
for safely updating the version in our release process. -->
<version>1.18.0-SNAPSHOT</version><!-- CURRENT_GRPC_VERSION -->
<name>example-tls</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<grpc.version>1.18.0-SNAPSHOT</grpc.version><!-- CURRENT_GRPC_VERSION -->
<protoc.version>3.5.1-1</protoc.version>
<netty.tcnative.version>2.0.20.Final</netty.tcnative.version>
<!-- required for jdk9 -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
<scope>provided</scope> <!-- not needed at runtime -->
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${netty.tcnative.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.5.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireUpperBoundDeps/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,8 @@
pluginManagement {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/"
}
gradlePluginPortal()
}
}

View File

@ -21,7 +21,6 @@ import io.grpc.StatusRuntimeException;
import io.grpc.examples.helloworld.GreeterGrpc; import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply; import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest; import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.examples.helloworld.HelloWorldServer;
import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NegotiationType; import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyChannelBuilder;
@ -35,7 +34,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* A simple client that requests a greeting from the {@link HelloWorldServer} with TLS. * A simple client that requests a greeting from the {@link HelloWorldServerTls} with TLS.
*/ */
public class HelloWorldClientTls { public class HelloWorldClientTls {
private static final Logger logger = Logger.getLogger(HelloWorldClientTls.class.getName()); private static final Logger logger = Logger.getLogger(HelloWorldClientTls.class.getName());

View File

@ -0,0 +1,37 @@
// Copyright 2015 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}

View File

@ -24,6 +24,7 @@
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId> <artifactId>grpc-netty-shaded</artifactId>
<version>${grpc.version}</version> <version>${grpc.version}</version>
<scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
@ -47,24 +48,6 @@
<version>${grpc.version}</version> <version>${grpc.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- Used in HelloWorldServerTls -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${netty.tcnative.version}</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
<version>1.0.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId> <artifactId>protobuf-java-util</artifactId>