This is an automated email from the ASF dual-hosted git repository.
fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot-examples.git
The following commit(s) were added to refs/heads/main by this push:
new 4b4a617 Adds platform-http-proxy example
4b4a617 is described below
commit 4b4a6178b8ec36b152e625588989b68940401d4c
Author: Marco Carletti <[email protected]>
AuthorDate: Thu Sep 4 14:17:20 2025 +0200
Adds platform-http-proxy example
---
README.adoc | 4 +-
platform-http-proxy/README.adoc | 43 ++++++++
platform-http-proxy/pom.xml | 108 +++++++++++++++++++++
.../camel/example/springboot/Application.java | 34 +++++++
.../camel/example/springboot/CamelRouter.java | 50 ++++++++++
.../src/main/resources/application.properties | 18 ++++
pom.xml | 1 +
7 files changed, 257 insertions(+), 1 deletion(-)
diff --git a/README.adoc b/README.adoc
index f12b9c5..a5f80a2 100644
--- a/README.adoc
+++ b/README.adoc
@@ -27,7 +27,7 @@ readme's instructions.
=== Examples
// examples: START
-Number of Examples: 65 (0 deprecated)
+Number of Examples: 66 (0 deprecated)
[width="100%",cols="4,2,4",options="header"]
|===
@@ -153,6 +153,8 @@ Number of Examples: 65 (0 deprecated)
| link:platform-http/README.adoc[Platform Http] (platform-http) | Rest | An
example showing Camel REST DSL with platform HTTP
+| link:platform-http-proxy/README.adoc[Platform Http Proxy]
(platform-http-proxy) | EIP | An example with Camel Platform HTTP act as
reverse proxy
+
| link:rest-cxf/README.adoc[Rest Cxf] (rest-cxf) | Rest | An example showing
Camel REST using CXF with Spring Boot
| link:rest-openapi/README.adoc[Rest Openapi] (rest-openapi) | Rest | An
example showing Camel REST DSL and OpenApi with Spring Boot
diff --git a/platform-http-proxy/README.adoc b/platform-http-proxy/README.adoc
new file mode 100644
index 0000000..7ab369b
--- /dev/null
+++ b/platform-http-proxy/README.adoc
@@ -0,0 +1,43 @@
+== Spring Boot Example with Camel Platform HTTP act as reverse proxy
+
+=== Introduction
+
+This example illustrates how to use
https://projects.spring.io/spring-boot/[Spring Boot] with
http://camel.apache.org[Camel]. It implements a reverse proxy using
https://camel.apache.org/components/latest/platform-http-component.html[platform-http].
+
+The project uses `camel-platform-http-starter` component as the implementation
for platform-http-engine and `camel-http-starter` to implement the producer
calling the http endpoint.
+
+=== Run
+
+You can run this example using:
+
+[source,bash]
+----
+mvn spring-boot:run
+----
+
+After the Spring Boot application is started, you can execute the following
HTTP requests:
+
+[source,bash]
+----
+curl --proxy http://localhost:8080 -L http://httpbin.org/get?arg1=val1 -H
'accept: application/json'
+----
+
+The command will call a test endpoint using the application as reverse proxy,
you should see the Camel headers from both request and response in the log.
Something similar to:
+
+----
+INFO 70370 --- [ad #1 - WireTap] header-request :
{accept=application/json, arg1=val1, CamelHttpCharacterEncoding=UTF-8,
CamelHttpMethod=GET, CamelHttpPath=/get, CamelHttpQuery=arg1=val1,
CamelHttpServletRequest=org.apache.catalina.connector.RequestFacade@4f31b074,
CamelHttpServletResponse=org.springframework.web.context.request.async.StandardServletAsyncWebRequest$LifecycleHttpServletResponse@158137c0,
CamelHttpUri=/get, CamelHttpUrl=http://httpbin.org/get, Cam [...]
+INFO 70370 --- [ad #2 - WireTap] header-response :
{accept=application/json, Access-Control-Allow-Credentials=true,
Access-Control-Allow-Origin=*, arg1=val1, CamelHttpCharacterEncoding=UTF-8,
CamelHttpMethod=GET, CamelHttpQuery=arg1=val1, CamelHttpResponseCode=200,
CamelHttpResponseText=OK,
CamelHttpServletRequest=org.apache.catalina.connector.RequestFacade@4f31b074,
CamelHttpServletResponse=org.springframework.web.context.request.async.StandardServletAsyncWebReq
[...]
+
+----
+
+The Spring Boot application can be stopped pressing `[CTRL] + [C]` in the
shell.
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!
diff --git a/platform-http-proxy/pom.xml b/platform-http-proxy/pom.xml
new file mode 100644
index 0000000..e247eb7
--- /dev/null
+++ b/platform-http-proxy/pom.xml
@@ -0,0 +1,108 @@
+<!--
+
+ 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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel.springboot.example</groupId>
+ <artifactId>examples</artifactId>
+ <version>4.15.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-spring-boot-platform-http-proxy</artifactId>
+ <name>Camel SB Examples :: Platform HTTP as reverse proxy</name>
+ <description>An example showing Camel reverse proxy with platform
HTTP</description>
+
+ <properties>
+ <category>EIP</category>
+ </properties>
+
+ <!-- Spring-Boot and Camel BOM -->
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-platform-http-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-http-starter</artifactId>
+ </dependency>
+
+ <!-- Test -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-junit5</artifactId>
+ <version>${camel-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git
a/platform-http-proxy/src/main/java/org/apache/camel/example/springboot/Application.java
b/platform-http-proxy/src/main/java/org/apache/camel/example/springboot/Application.java
new file mode 100644
index 0000000..4c0bd71
--- /dev/null
+++
b/platform-http-proxy/src/main/java/org/apache/camel/example/springboot/Application.java
@@ -0,0 +1,34 @@
+/*
+ * 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.apache.camel.example.springboot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+// CHECKSTYLE:OFF
+@SpringBootApplication
+public class Application {
+
+ /**
+ * Main method to start the application.
+ */
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+}
+// CHECKSTYLE:ON
diff --git
a/platform-http-proxy/src/main/java/org/apache/camel/example/springboot/CamelRouter.java
b/platform-http-proxy/src/main/java/org/apache/camel/example/springboot/CamelRouter.java
new file mode 100644
index 0000000..400838d
--- /dev/null
+++
b/platform-http-proxy/src/main/java/org/apache/camel/example/springboot/CamelRouter.java
@@ -0,0 +1,50 @@
+/*
+ * 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.apache.camel.example.springboot;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+/**
+ * Reverse proxy route with routes that logs heders around the backend call
+ */
+@Component
+public class CamelRouter extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+
+ // @formatter:off
+ from("platform-http:proxy/*?matchOnUriPrefix=true")
+ .routeId("reverse-proxy")
+ .wireTap("direct:request")
+ .removeHeader(Exchange.HTTP_PATH)
+ .log("calling ${headers." + Exchange.HTTP_URL + "}")
+ .toD("${headers." + Exchange.HTTP_URL + "}"
+ + "?throwExceptionOnFailure=false&bridgeEndpoint=true")
+ .wireTap("direct:response");
+
+ from("direct:request")
+ .routeId("header-request")
+ .log("${headers}");
+ from("direct:response")
+ .routeId("header-response")
+ .log("${headers}");
+ // @formatter:on
+ }
+}
diff --git a/platform-http-proxy/src/main/resources/application.properties
b/platform-http-proxy/src/main/resources/application.properties
new file mode 100644
index 0000000..a4ed5c2
--- /dev/null
+++ b/platform-http-proxy/src/main/resources/application.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+# the name of Camel
+camel.main.name = MyCamelReverseProxy
diff --git a/pom.xml b/pom.xml
index 9f01024..8efdd1a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
<module>opentelemetry</module>
<module>paho-mqtt5-shared-subscriptions</module>
<module>platform-http</module>
+ <module>platform-http-proxy</module>
<module>pojo</module>
<module>rabbitmq</module>
<module>reactive-streams</module>