Skip to content

Commit 461a2ee

Browse files
committed
Adds platform-http-proxy example
1 parent 95be067 commit 461a2ee

File tree

7 files changed

+257
-1
lines changed

7 files changed

+257
-1
lines changed

README.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ readme's instructions.
2727
=== Examples
2828

2929
// examples: START
30-
Number of Examples: 65 (0 deprecated)
30+
Number of Examples: 66 (0 deprecated)
3131

3232
[width="100%",cols="4,2,4",options="header"]
3333
|===
@@ -153,6 +153,8 @@ Number of Examples: 65 (0 deprecated)
153153

154154
| link:platform-http/README.adoc[Platform Http] (platform-http) | Rest | An example showing Camel REST DSL with platform HTTP
155155

156+
| link:platform-http-proxy/README.adoc[Platform Http Proxy] (platform-http-proxy) | EIP | An example with Camel Platform HTTP act as reverse proxy
157+
156158
| link:rest-cxf/README.adoc[Rest Cxf] (rest-cxf) | Rest | An example showing Camel REST using CXF with Spring Boot
157159

158160
| link:rest-openapi/README.adoc[Rest Openapi] (rest-openapi) | Rest | An example showing Camel REST DSL and OpenApi with Spring Boot

platform-http-proxy/README.adoc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
== Spring Boot Example with Camel Platform HTTP act as reverse proxy
2+
3+
=== Introduction
4+
5+
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].
6+
7+
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.
8+
9+
=== Run
10+
11+
You can run this example using:
12+
13+
[source,bash]
14+
----
15+
mvn spring-boot:run
16+
----
17+
18+
After the Spring Boot application is started, you can execute the following HTTP requests:
19+
20+
[source,bash]
21+
----
22+
curl --proxy http://localhost:8080 -L http://httpbin.org/get?arg1=val1 -H 'accept: application/json'
23+
----
24+
25+
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:
26+
27+
----
28+
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, CamelPlatformHttpContextPath=/, host=httpbin.org, proxy-connection=Keep-Alive, user-agent=curl/8.9.1}
29+
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.StandardServletAsyncWebRequest$LifecycleHttpServletResponse@158137c0, CamelHttpUri=/get, CamelHttpUrl=http://httpbin.org/get, CamelPlatformHttpContextPath=/, Connection=keep-alive, Content-Length=387, Content-Type=application/json, Date=Thu, 04 Sep 2025 11:59:30 GMT, proxy-connection=Keep-Alive, Server=gunicorn/19.9.0}
30+
31+
----
32+
33+
The Spring Boot application can be stopped pressing `[CTRL] + [C]` in the shell.
34+
35+
=== Help and contributions
36+
37+
If you hit any problem using Camel or have some feedback, then please
38+
https://camel.apache.org/community/support/[let us know].
39+
40+
We also love contributors, so
41+
https://camel.apache.org/community/contributing/[get involved] :-)
42+
43+
The Camel riders!

platform-http-proxy/pom.xml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!--
2+
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<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">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>org.apache.camel.springboot.example</groupId>
24+
<artifactId>examples</artifactId>
25+
<version>4.15.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>camel-example-spring-boot-platform-http-proxy</artifactId>
29+
<name>Camel SB Examples :: Platform HTTP as reverse proxy</name>
30+
<description>An example showing Camel reverse proxy with platform HTTP</description>
31+
32+
<properties>
33+
<category>EIP</category>
34+
</properties>
35+
36+
<!-- Spring-Boot and Camel BOM -->
37+
<dependencyManagement>
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.apache.camel.springboot</groupId>
41+
<artifactId>camel-spring-boot-bom</artifactId>
42+
<version>${project.version}</version>
43+
<type>pom</type>
44+
<scope>import</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-dependencies</artifactId>
49+
<version>${spring-boot-version}</version>
50+
<type>pom</type>
51+
<scope>import</scope>
52+
</dependency>
53+
</dependencies>
54+
</dependencyManagement>
55+
56+
<dependencies>
57+
<!-- Spring Boot -->
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-starter-web</artifactId>
61+
</dependency>
62+
63+
<!-- Camel -->
64+
<dependency>
65+
<groupId>org.apache.camel.springboot</groupId>
66+
<artifactId>camel-spring-boot-starter</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.camel.springboot</groupId>
70+
<artifactId>camel-platform-http-starter</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.apache.camel.springboot</groupId>
74+
<artifactId>camel-http-starter</artifactId>
75+
</dependency>
76+
77+
<!-- Test -->
78+
<dependency>
79+
<groupId>org.springframework.boot</groupId>
80+
<artifactId>spring-boot-starter-test</artifactId>
81+
<scope>test</scope>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.apache.camel</groupId>
85+
<artifactId>camel-test-junit5</artifactId>
86+
<version>${camel-version}</version>
87+
<scope>test</scope>
88+
</dependency>
89+
</dependencies>
90+
91+
<build>
92+
<plugins>
93+
<plugin>
94+
<groupId>org.springframework.boot</groupId>
95+
<artifactId>spring-boot-maven-plugin</artifactId>
96+
<version>${spring-boot-version}</version>
97+
<executions>
98+
<execution>
99+
<goals>
100+
<goal>repackage</goal>
101+
</goals>
102+
</execution>
103+
</executions>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
108+
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.example.springboot;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
// CHECKSTYLE:OFF
23+
@SpringBootApplication
24+
public class Application {
25+
26+
/**
27+
* Main method to start the application.
28+
*/
29+
public static void main(String[] args) {
30+
SpringApplication.run(Application.class, args);
31+
}
32+
33+
}
34+
// CHECKSTYLE:ON
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.example.springboot;
18+
19+
import org.apache.camel.Exchange;
20+
import org.apache.camel.builder.RouteBuilder;
21+
import org.springframework.stereotype.Component;
22+
23+
/**
24+
* Reverse proxy route with routes that logs heders around the backend call
25+
*/
26+
@Component
27+
public class CamelRouter extends RouteBuilder {
28+
29+
@Override
30+
public void configure() throws Exception {
31+
32+
// @formatter:off
33+
from("platform-http:proxy/*?matchOnUriPrefix=true")
34+
.routeId("reverse-proxy")
35+
.wireTap("direct:request")
36+
.removeHeader(Exchange.HTTP_PATH)
37+
.log("calling ${headers." + Exchange.HTTP_URL + "}")
38+
.toD("${headers." + Exchange.HTTP_URL + "}"
39+
+ "?throwExceptionOnFailure=false&bridgeEndpoint=true")
40+
.wireTap("direct:response");
41+
42+
from("direct:request")
43+
.routeId("header-request")
44+
.log("${headers}");
45+
from("direct:response")
46+
.routeId("header-response")
47+
.log("${headers}");
48+
// @formatter:on
49+
}
50+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## ---------------------------------------------------------------------------
2+
## Licensed to the Apache Software Foundation (ASF) under one or more
3+
## contributor license agreements. See the NOTICE file distributed with
4+
## this work for additional information regarding copyright ownership.
5+
## The ASF licenses this file to You under the Apache License, Version 2.0
6+
## (the "License"); you may not use this file except in compliance with
7+
## the License. You may obtain a copy of the License at
8+
##
9+
## http://www.apache.org/licenses/LICENSE-2.0
10+
##
11+
## Unless required by applicable law or agreed to in writing, software
12+
## distributed under the License is distributed on an "AS IS" BASIS,
13+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
## See the License for the specific language governing permissions and
15+
## limitations under the License.
16+
## ---------------------------------------------------------------------------
17+
# the name of Camel
18+
camel.main.name = MyCamelReverseProxy

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<module>opentelemetry</module>
6969
<module>paho-mqtt5-shared-subscriptions</module>
7070
<module>platform-http</module>
71+
<module>platform-http-proxy</module>
7172
<module>pojo</module>
7273
<module>rabbitmq</module>
7374
<module>reactive-streams</module>

0 commit comments

Comments
 (0)