tree: afda9600d9b83a794c528aa10c99e8e8c21bb437 [path history] [tgz]
  1. NettySecureServer.java
  2. NettyServer.java
  3. PlatformHttpServer.java
  4. PlatformHttpsServer.java
  5. README.md
generic-examples/http/README.md

Examples showing how to interact with HTTP/HTTPS protocol

Find useful examples about how to develop a Camel K integration leveraging Http/Https protocol.

You can find more information about Apache Camel and Apache Camel K on the official Camel website.

Before you begin

Read the general instructions in the root README.md file for setting up your environment and the Kubernetes cluster before looking at this example.

Make sure you've read the installation instructions for your specific cluster before starting the example.

Understanding the Examples

  • Using HTTP with SSL/TLS layer

    • NettySecureServer.java: Uses HTTPS protocol. The route uses Netty HTTP as a HTTP server.
    • PlatformHttpsServer.java: Uses HTTPS protocol. The route uses the platform-http component which allows the use of the runtime's existing HTTP server.
  • Using HTTP

Running the Examples

Run the NettyServer

kamel run --dev -t service.type=NodePort NettyServer.java

Get the service location. If you're running on minikube, run minikube service netty-server --url=true.

You should see “Hello World” displayed on http://<service-location>/hello. Alternatively, you could run: curl http://<service-location>/hello.

Run the NettySecureServer

This integration requires a Keystore and a Truststore. Open NettySecureServer.java to find instructions on how to generate a required keystore.jks and truststore.jks file. For this example, keystore and truststore password is changeit

Generate keystore.jks and truststore.jks (for this example, keystore and truststore password = changeit):

keytool -genkeypair -alias EntryName -keyalg RSA -keysize 2048 -keystore keystore.jks
keytool -exportcert -alias EntryName -keystore keystore.jks -rfc -file public.cert
keytool -import -alias EntryName -file public.cert -storetype JKS -keystore truststore.jks

Create the secrets associated with the stores:

kubectl create secret generic http-keystore --from-file keystore.jks
kubectl create secret generic http-truststore --from-file truststore.jks

Run the integration:

kamel run --dev \
  -t mount.resources=secret:http-keystore/keystore.jks@/etc/ssl/keystore.jks \
  -t mount.resources=secret:http-truststore/truststore.jks@/etc/ssl/truststore.jks \
  -t container.port=8443 -t service.type=NodePort \
  NettySecureServer.java

Get the service location. If you're running on minikube, run minikube service netty-secure-server --url=true --https=true.

You should see “Hello Secure World” displayed on https://<service-location>/hello. Alternatively, you could run: curl -vk https://<service-location>/hello.

Run the PlatformHttpServer

kamel run --dev PlatformHttpServer.java

Get the service location. If you're running on minikube, run minikube service platform-http-server --url=true.

You can now run curl -H name:World http://<service-location>/hello.

Run the PlatformHttpsServer

This integration requires a server key and certificate. Open PlatformHttpsServer.java to find instructions on how to generate those.

Run the integration:

kubectl create secret generic my-self-signed-ssl --from-file=server.key --from-file=server.crt

kamel run --dev PlatformHttpsServer.java

Get the service location. If you're running on minikube, run minikube service platform-https-server --url=true --https=true.

You can now run curl -vk -H name:World https://<service-location>/hello.