You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/04/13 17:28:42 UTC
[camel-quarkus] 01/01: http-log example
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch http-log
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit d689e35bb4f8b808969364d99fc8eb9710d86a24
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 13 19:11:38 2020 +0200
http-log example
---
examples/http-log/README.adoc | 63 +++++++++
examples/http-log/pom.xml | 99 ++++++++++++++
.../src/main/java/org/acme/http/CamelRoute.java | 32 +++++
.../main/java/org/acme/http/ExampleResource.java | 32 +++++
.../src/main/resources/application.properties | 44 ++++++
.../src/main/resources/resources/index.html | 152 +++++++++++++++++++++
examples/pom.xml | 1 +
7 files changed, 423 insertions(+)
diff --git a/examples/http-log/README.adoc b/examples/http-log/README.adoc
new file mode 100644
index 0000000..b4f8ee6
--- /dev/null
+++ b/examples/http-log/README.adoc
@@ -0,0 +1,63 @@
+= http-log
+
+This is a basic hello world example that uses CDI and JAX-RS to setup
+a REST service and a Camel route to service HTTP traffic.
+
+TIP: Check the https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus User guide] for prerequisites
+and other general information.
+
+== Start in the Development mode
+
+[source,shell]
+----
+$ mvn clean compile quarkus:dev -DnoDeps
+----
+
+The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your
+workspace. Any modifications in your project will automatically take effect in the running application.
+
+TIP: Please refer to the Development mode section of
+https://camel.apache.org/camel-quarkus/latest/first-steps.html#_development_mode[Camel Quarkus User guide] for more details.
+
+You can from a web browser call the two services via
+
+- http://localhost:8080/hello
+- http://localhost:8080/camel/hello
+
+There is also health check and metrics available from the following urls:
+
+- http://localhost:8080/health
+- http://localhost:8080/metrcis
+
+=== Package and run the application
+
+Once you are done with developing you may want to package and run the application.
+
+TIP: Find more details about the JVM mode and Native mode in the Package and run section of
+https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_the_application[Camel Quarkus User guide]
+
+==== JVM mode
+
+[source,shell]
+----
+$ mvn clean package
+$ java -jar target/*-runner.jar
+...
+[io.quarkus] (main) Quarkus 0.23.2 started in 1.163s. Listening on: http://[::]:8080
+----
+
+==== Native mode
+
+IMPORTANT: Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section
+of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_prerequisites[Camel Quarkus User guide].
+
+To prepare a native executable using GraalVM, run the following command:
+
+[source,shell]
+----
+$ mvn clean package -Pnative
+$ ./target/*-runner
+...
+[io.quarkus] (main) Quarkus 0.23.2 started in 0.013s. Listening on: http://[::]:8080
+...
+----
diff --git a/examples/http-log/pom.xml b/examples/http-log/pom.xml
new file mode 100644
index 0000000..059a05b
--- /dev/null
+++ b/examples/http-log/pom.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-build-parent</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../../poms/build-parent/pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>camel-quarkus-examples-http-log</artifactId>
+ <name>Camel Quarkus :: Examples :: HTTP Log</name>
+ <description>Camel Quarkus Example :: HTTP to Log</description>
+
+ <properties>
+ <!-- mvnd, a.k.a. Maven Daemon: https://github.com/gnodet/mvnd -->
+ <!-- The following rule tells mvnd to build the listed deployment modules before this module. -->
+ <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not -->
+ <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
+ <!-- Please update rule whenever you change the dependencies of this module by running -->
+ <!-- mvn process-resources -Pformat from the root directory -->
+ <mvnd.builder.rule>camel-quarkus-log-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-timer-deployment</mvnd.builder.rule>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-platform-http</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-log</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-microprofile-health</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-microprofile-metrics</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>build</id>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/examples/http-log/src/main/java/org/acme/http/CamelRoute.java b/examples/http-log/src/main/java/org/acme/http/CamelRoute.java
new file mode 100644
index 0000000..c456f6f
--- /dev/null
+++ b/examples/http-log/src/main/java/org/acme/http/CamelRoute.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.
+ */
+package org.acme.http;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+
+@ApplicationScoped
+public class CamelRoute extends EndpointRouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from(platformHttp("/camel/hello"))
+ .setBody().simple("Camel runs on ${hostname}")
+ .to(log("hi").showExchangePattern(false).showBodyType(false));
+ }
+}
diff --git a/examples/http-log/src/main/java/org/acme/http/ExampleResource.java b/examples/http-log/src/main/java/org/acme/http/ExampleResource.java
new file mode 100644
index 0000000..4d71ac1
--- /dev/null
+++ b/examples/http-log/src/main/java/org/acme/http/ExampleResource.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.
+ */
+package org.acme.http;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/hello")
+public class ExampleResource {
+
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String hello() {
+ return "hello";
+ }
+}
diff --git a/examples/http-log/src/main/resources/application.properties b/examples/http-log/src/main/resources/application.properties
new file mode 100644
index 0000000..3801104
--- /dev/null
+++ b/examples/http-log/src/main/resources/application.properties
@@ -0,0 +1,44 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+#
+# Quarkus
+#
+quarkus.log.file.enable = false
+
+#
+# Quarkus - Camel
+#
+
+# disable build time route discovery as the only
+# route defined in this project is based on CDI.
+#
+# This is not strictly needed for the correctness
+# because camel-quarkus automatically
+# filters auto-discovered routes that targets CDI
+# but if is is known that routes are all leveraging
+# CDI, this option will give some little boost to
+# the build process
+quarkus.camel.main.routes-discovery.enabled = false
+
+# bean introspection to log reflection based configuration
+camel.main.beanIntrospectionExtendedStatistics=true
+camel.main.beanIntrospectionLoggingLevel=INFO
+
+#
+# Camel
+#
+camel.context.name = quarkus-camel-example-http-log
diff --git a/examples/http-log/src/main/resources/resources/index.html b/examples/http-log/src/main/resources/resources/index.html
new file mode 100644
index 0000000..c2a6961
--- /dev/null
+++ b/examples/http-log/src/main/resources/resources/index.html
@@ -0,0 +1,152 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>code-with-quarkus - 1.0.0-SNAPSHOT</title>
+ <style>
+ h1, h2, h3, h4, h5, h6 {
+ margin-bottom: 0.5rem;
+ font-weight: 400;
+ line-height: 1.5;
+ }
+
+ h1 {
+ font-size: 2.5rem;
+ }
+
+ h2 {
+ font-size: 2rem
+ }
+
+ h3 {
+ font-size: 1.75rem
+ }
+
+ h4 {
+ font-size: 1.5rem
+ }
+
+ h5 {
+ font-size: 1.25rem
+ }
+
+ h6 {
+ font-size: 1rem
+ }
+
+ .lead {
+ font-weight: 300;
+ font-size: 2rem;
+ }
+
+ .banner {
+ font-size: 2.7rem;
+ margin: 0;
+ padding: 2rem 1rem;
+ background-color: #00A1E2;
+ color: white;
+ }
+
+ body {
+ margin: 0;
+ font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
+ }
+
+ code {
+ font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
+ font-size: 87.5%;
+ color: #e83e8c;
+ word-break: break-word;
+ }
+
+ .left-column {
+ padding: .75rem;
+ max-width: 75%;
+ min-width: 55%;
+ }
+
+ .right-column {
+ padding: .75rem;
+ max-width: 25%;
+ }
+
+ .container {
+ display: flex;
+ width: 100%;
+ }
+
+ li {
+ margin: 0.75rem;
+ }
+
+ .right-section {
+ margin-left: 1rem;
+ padding-left: 0.5rem;
+ }
+
+ .right-section h3 {
+ padding-top: 0;
+ font-weight: 200;
+ }
+
+ .right-section ul {
+ border-left: 0.3rem solid #00A1E2;
+ list-style-type: none;
+ padding-left: 0;
+ }
+
+ </style>
+</head>
+<body>
+
+<div class="banner lead">
+ Your new Cloud-Native application is ready!
+</div>
+
+<div class="container">
+ <div class="left-column">
+ <p class="lead"> Congratulations, you have created a new Quarkus application.</p>
+
+ <h2>Why do you see this?</h2>
+
+ <p>This page is served by Quarkus. The source is in
+ <code>src/main/resources/META-INF/resources/index.html</code>.</p>
+
+ <h2>What can I do from here?</h2>
+
+ <p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>.
+ </p>
+ <ul>
+ <li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
+ <li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
+ <li>Configure your application in <code>src/main/resources/application.properties</code>.
+ </li>
+ </ul>
+
+ <h2>How do I get rid of this page?</h2>
+ <p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
+ </div>
+ <div class="right-column">
+ <div class="right-section">
+ <h3>Application</h3>
+ <ul>
+ <li>GroupId: org.apache.camel.quarkus</li>
+ <li>ArtifactId: http-log</li>
+ <li>Version: 1.0.0-SNAPSHOT</li>
+ <li>Quarkus Version: 1.3.2.Final</li>
+ </ul>
+ </div>
+ <div class="right-section">
+ <h3>Next steps</h3>
+ <ul>
+ <li><a href="https://quarkus.io/guides/maven-tooling.html" target="_blank">Setup your IDE</a></li>
+ <li><a href="https://quarkus.io/guides/getting-started.html" target="_blank">Getting started</a></li>
+ <li><a href="https://quarkus.io" target="_blank">Quarkus Web Site</a></li>
+ </ul>
+ </div>
+ </div>
+</div>
+
+
+</body>
+</html>
\ No newline at end of file
diff --git a/examples/pom.xml b/examples/pom.xml
index 9ef12c8..cacb3e9 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -33,6 +33,7 @@
<modules>
<module>observability</module>
+ <module>http-log</module>
<module>rest-json</module>
<module>timer-log</module>
<module>timer-log-cdi</module>