diff --git a/pom.xml b/pom.xml index c05abde3b..df61bfdf3 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,7 @@ splitter-eip widget-gadget azure + undertow variables vault diff --git a/undertow/pom.xml b/undertow/pom.xml new file mode 100644 index 000000000..689dbd95d --- /dev/null +++ b/undertow/pom.xml @@ -0,0 +1,124 @@ + + + + + 4.0.0 + + + org.apache.camel.springboot.example + examples + 4.23.0-SNAPSHOT + + + camel-example-spring-boot-undertow + Camel SB Examples :: Undertow + An example showing how to use Camel with Spring Boot and Undertow as the embedded web server + + + Beginner + 1.0.0.Final-SNAPSHOT + + + + + + + org.apache.camel.springboot + camel-spring-boot-bom + ${camel-version} + pom + import + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-version} + pom + import + + + + + + + + + org.springframework.boot + spring-boot-starter-webmvc + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + io.undertow + undertow-spring-boot-starter + ${undertow-spring-boot-version} + + + + + org.apache.camel.springboot + camel-spring-boot-starter + + + org.apache.camel.springboot + camel-platform-http-starter + + + org.apache.camel.springboot + camel-jackson3-starter + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.camel + camel-test-spring-junit6 + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + + + repackage + + + + + + + + diff --git a/undertow/src/main/java/sample/camel/MyCamelApplication.java b/undertow/src/main/java/sample/camel/MyCamelApplication.java new file mode 100644 index 000000000..8b679284c --- /dev/null +++ b/undertow/src/main/java/sample/camel/MyCamelApplication.java @@ -0,0 +1,28 @@ +/* + * 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 sample.camel; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MyCamelApplication { + + public static void main(String[] args) { + SpringApplication.run(MyCamelApplication.class, args); + } +} diff --git a/undertow/src/main/java/sample/camel/MyCamelRouter.java b/undertow/src/main/java/sample/camel/MyCamelRouter.java new file mode 100644 index 000000000..32ce0a20b --- /dev/null +++ b/undertow/src/main/java/sample/camel/MyCamelRouter.java @@ -0,0 +1,40 @@ +/* + * 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 sample.camel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestBindingMode; +import org.springframework.stereotype.Component; + +@Component +public class MyCamelRouter extends RouteBuilder { + + @Override + public void configure() throws Exception { + restConfiguration() + .bindingMode(RestBindingMode.json); + + rest("/api") + .get("/hello") + .routeId("hello-get") + .to("direct:hello"); + + from("direct:hello") + .routeId("hello") + .setBody(constant(java.util.Map.of("message", "Hello from Camel on Undertow!"))); + } +} diff --git a/undertow/src/main/resources/application.properties b/undertow/src/main/resources/application.properties new file mode 100644 index 000000000..7cf7f8483 --- /dev/null +++ b/undertow/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. +## --------------------------------------------------------------------------- + +camel.main.name = MyCamelUndertow diff --git a/undertow/src/test/java/sample/camel/UndertowTest.java b/undertow/src/test/java/sample/camel/UndertowTest.java new file mode 100644 index 000000000..d6378cc49 --- /dev/null +++ b/undertow/src/test/java/sample/camel/UndertowTest.java @@ -0,0 +1,64 @@ +/* + * 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 sample.camel; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +import org.apache.camel.CamelContext; +import org.apache.camel.test.spring.junit6.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@CamelSpringBootTest +@SpringBootTest(classes = MyCamelApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) +public class UndertowTest { + + @Autowired + private CamelContext camelContext; + + @LocalServerPort + private int port; + + @Test + public void shouldStartCamelContext() { + assertNotNull(camelContext); + assertTrue(camelContext.getStatus().isStarted()); + } + + @Test + public void shouldHandleGetRequest() throws Exception { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://localhost:" + port + "/api/hello")) + .GET() + .build(); + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + assertEquals(200, response.statusCode()); + assertTrue(response.body().contains("Hello from Camel on Undertow!")); + } +}