Skip to content

Latest commit

 

History

History
113 lines (86 loc) · 4.45 KB

README.md

File metadata and controls

113 lines (86 loc) · 4.45 KB

H2C & gRPC Sample Apps

This folder contains Cloud Foundry sample apps showcasing plain text HTTP2 (H2C) and gRPC via secure HTTP2.

A more detailed look into HTTP/2 on the SAP BTP, Cloud Foundry environment can be found in the following blog post:

Each sample has a README file that explains how to run it locally. Some of these examples require additional applications or commands that can be obtained from their respective home pages or operating system distribution.

Note: due to the lack of H2C support in popular frameworks, the Ruby and Python examples are very low level.

Downloading the Samples

Clone this repo

# Skip this if you cloned the repository already
git clone https://github.com/SAP-samples/cf-routing-samples
cd cf-routing-samples/http2

Deploying all Apps

Each app can be deployed individually, or all apps can be deployed at the same time using a common manifest provided in apps-manifest.yml.

The following sections explain pre-requisites and instructions for the different sample apps.

Pre-requisites

Make sure you have CF CLI version 8 or higher installed

cf version

example output:

cf version 8.0.0+e8d41cf8e.2021-09-16

Pre-requisites for Java apps

# please make sure that the openjdk@11 is installed and gradle wrapper is pointing to it
./gradlew clean build

Deploying Apps Individually

HTTP/2 Plain Text (H2C)

Please check the README file for each of the HTTP/2 (H2C) example apps:

gRPC

Please check the README file for each of the gRPC example apps:

Deploying all Apps with one Manifest

# run the following commands in cf environment
cd http2
export DOMAIN=my.cf.app.domain
cf push --manifest apps-manifest.yml --var domain=$DOMAIN --vars-file gradle.properties

Testing Sample Apps

Testing H2C Apps

# format: https://<language>-http2-test.my.cf.app.domain
export DOMAIN=my.cf.app.domain
curl -v --http2-prior-knowledge "https://go-http2-test.$DOMAIN"
curl -v --http2-prior-knowledge "https://java-http2-test.$DOMAIN"
curl -v --http2-prior-knowledge "https://node-http2-test.$DOMAIN"
curl -v --http2-prior-knowledge "https://python-http2-test.$DOMAIN"
curl -v --http2-prior-knowledge "https://ruby-http2-test.$DOMAIN"

The output of each of those commands should be HTTP 200 with the response body that reflects the app's implementation language.

Please note that for H2C, --http2-prior-knowledge is mandatory, as without TLS there is no ALPN.

Testing gRPC Apps

  1. Download grpcurl from https://github.com/fullstorydev/grpcurl/releases and put it in your path
  2. Make a gRPC request using grpcurl
    export DOMAIN=my.cf.app.domain
    # following example with mtls
    export MTLS_CERT_PATH=path/to/mtls_client_certificate.pem
    export MTLS_KEY_PATH=path/to/mtls_client_private_key.pem
    
    grpcurl -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH "go-grpc-test.$DOMAIN:443" example.Example.Run
    grpcurl -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH "java-grpc-test.$DOMAIN:443" example.Example.Run
    grpcurl -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH "python-grpc-test.$DOMAIN:443" example.Example.Run
    grpcurl -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH "ruby-grpc-test.$DOMAIN:443" example.Example.Run
    
    # Alternative grpcurl for apps which don't support reflection (such as Node.js)
    grpcurl -proto path/to/example.proto -insecure -cert "$MTLS_CERT_PATH" -key "$MTLS_KEY_PATH" "node-grpc-test.$DOMAIN:443" Example.Run

The output of each of those commands should be in the following format, with a message that reflects the app's implementation language:

{
  "message": "Hello! This Go application is speaking gRPC"
}