This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 0e087b0a9eebf99e25a502ddc28f11039eebe13d
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Tue Jun 15 10:12:24 2021 +0200

    doc(examples): http
---
 examples/http/NettySecureServer.java   | 55 ++++++++++++++++++++++++++++++++++
 examples/http/NettyServer.java         | 32 ++++++++++++++++++++
 examples/http/PlatformHttpServer.java  | 31 +++++++++++++++++++
 examples/http/PlatformHttpsServer.java | 49 ++++++++++++++++++++++++++++++
 examples/http/README.md                |  3 ++
 5 files changed, 170 insertions(+)

diff --git a/examples/http/NettySecureServer.java 
b/examples/http/NettySecureServer.java
new file mode 100644
index 0000000..a31dc19
--- /dev/null
+++ b/examples/http/NettySecureServer.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+// kamel run NettySecureServer.java --resource 
file:KeyStore.jks@/etc/ssl/keystore.jks 
+//                                  --resource 
file:truststore.jks@/etc/ssl/truststore.jks -t container.port=8443 --dev
+// 
+// recover the service location. If you're running on minikube, "minikube 
service netty-secure-server --url=true --https=true"
+// curl https://<service-location>/hello
+//
+
+import org.apache.camel.builder.RouteBuilder;
+
+import org.apache.camel.support.jsse.*;
+
+public class NettySecureServer extends RouteBuilder {
+  @Override
+  public void configure() throws Exception {
+    registerSslContextParameter();
+    
from("netty-http:https://0.0.0.0:8443/hello?sslContextParameters=#sslContextParameters&ssl=true";)
+      .transform().constant("Hello Secure World");
+  }
+
+  private void registerSslContextParameter() throws Exception {
+    KeyStoreParameters ksp = new KeyStoreParameters();
+       ksp.setResource("/etc/ssl/keystore.jks");
+       ksp.setPassword("changeit");
+    KeyManagersParameters kmp = new KeyManagersParameters();
+       kmp.setKeyPassword("changeit");
+       kmp.setKeyStore(ksp);
+    KeyStoreParameters tsp = new KeyStoreParameters();
+       tsp.setResource("/etc/ssl/truststore.jks");
+       tsp.setPassword("changeit");
+    TrustManagersParameters tmp = new TrustManagersParameters();
+       tmp.setKeyStore(tsp);
+    SSLContextParameters sslContextParameters = new SSLContextParameters();
+    sslContextParameters.setKeyManagers(kmp);
+    sslContextParameters.setTrustManagers(tmp);
+
+    this.getContext().getRegistry().bind("sslContextParameters", 
sslContextParameters);
+ }
+}
\ No newline at end of file
diff --git a/examples/http/NettyServer.java b/examples/http/NettyServer.java
new file mode 100644
index 0000000..050e889
--- /dev/null
+++ b/examples/http/NettyServer.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+// kamel run NettyServer.java --dev
+// 
+// recover the service location. If you're running on minikube, minikube 
service netty-server --url=true
+// curl http://<service-location>/hello
+//
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class NettyServer extends RouteBuilder {
+  @Override
+  public void configure() throws Exception {
+    from("netty-http:http://0.0.0.0:8080/hello";)
+      .transform().constant("Hello World");
+  }
+}
\ No newline at end of file
diff --git a/examples/http/PlatformHttpServer.java 
b/examples/http/PlatformHttpServer.java
new file mode 100644
index 0000000..42b50d8
--- /dev/null
+++ b/examples/http/PlatformHttpServer.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+// kamel run PlatformHttpServer.java --dev -t service.enabled=true
+// 
+// recover the service location. If you're running on minikube, minikube 
service platform-http-server --url=true
+// curl -H "name:World" http://<service-location>/hello
+//
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class PlatformHttpServer extends RouteBuilder {
+  @Override
+  public void configure() throws Exception {
+    from("platform-http:/hello?httpMethodRestrict=GET").setBody(simple("Hello 
${header.name}"));
+  }
+}
\ No newline at end of file
diff --git a/examples/http/PlatformHttpsServer.java 
b/examples/http/PlatformHttpsServer.java
new file mode 100644
index 0000000..01bed7b
--- /dev/null
+++ b/examples/http/PlatformHttpsServer.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+// Self signed certificate generation:
+//
+// openssl genrsa -out server.key 2048
+// openssl req -new -key server.key -out server.csr
+// openssl x509 -req -days 365 -in server.csr -signkey server.key -out 
server.crt
+
+// Storing certificate and keys in a secret
+// kubectl create secret generic my-self-signed-ssl --from-file=server.key 
--from-file=server.crt
+
+// Integration execution
+//
+// kamel run PlatformHttpsServer.java -p 
quarkus.http.ssl.certificate.file=/etc/ssl/my-self-signed-ssl/server.crt \
+//                                    -p 
quarkus.http.ssl.certificate.key-file=/etc/ssl/my-self-signed-ssl/server.key \ 
+//                                    --resource 
secret:my-self-signed-ssl@/etc/ssl/my-self-signed-ssl \
+//                                    -t container.port=8443 --dev
+
+// kamel run PlatformHttpsServer.java -p 
quarkus.http.ssl.certificate.file=/etc/ssl/my-self-signed-ssl/server.crt -p 
quarkus.http.ssl.certificate.key-file=/etc/ssl/my-self-signed-ssl/server.key 
--resource secret:my-self-signed-ssl@/etc/ssl/my-self-signed-ssl -t 
container.port=8443 --dev
+
+// Test
+//
+// recover the service location. If you're running on minikube, minikube 
service platform-https-server --url=true
+// curl -H "name:World" -k http://<service-location>/hello
+//
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class PlatformHttpsServer extends RouteBuilder {
+  @Override
+  public void configure() throws Exception {
+    from("platform-http:/hello?httpMethodRestrict=GET").setBody(simple("Hello 
${header.name}"));
+  }
+}
\ No newline at end of file
diff --git a/examples/http/README.md b/examples/http/README.md
new file mode 100644
index 0000000..361ce9f
--- /dev/null
+++ b/examples/http/README.md
@@ -0,0 +1,3 @@
+# Examples showing how to interact with HTTP/HTTPS protocol
+
+Find useful examples about how to develop a Camel K integration leveraging 
`Http`/`Https` protocol.
\ No newline at end of file

Reply via email to