You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2015/02/02 12:02:07 UTC
camel git commit: [SpringBoot] Added fat jar/war helpers.
Repository: camel
Updated Branches:
refs/heads/master bd3d1f728 -> 6999028f2
[SpringBoot] Added fat jar/war helpers.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6999028f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6999028f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6999028f
Branch: refs/heads/master
Commit: 6999028f23ae69411f7650b78d3e9d809c9a910f
Parents: bd3d1f7
Author: Henryk Konsek <he...@gmail.com>
Authored: Mon Feb 2 12:02:00 2015 +0100
Committer: Henryk Konsek <he...@gmail.com>
Committed: Mon Feb 2 12:02:00 2015 +0100
----------------------------------------------------------------------
components/camel-spring-boot/pom.xml | 35 +++++++++++++
.../apache/camel/spring/boot/FatJarRouter.java | 33 ++++++++++++
.../camel/spring/boot/FatWarInitializer.java | 31 ++++++++++++
.../fatjarrouter/JUnitFatJarRouterTest.java | 52 +++++++++++++++++++
.../StandaloneFatJarRouterTest.java | 53 ++++++++++++++++++++
.../boot/fatjarrouter/TestFatJarRouter.java | 36 +++++++++++++
6 files changed, 240 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6999028f/components/camel-spring-boot/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/pom.xml b/components/camel-spring-boot/pom.xml
index b4a5192..5b81667 100644
--- a/components/camel-spring-boot/pom.xml
+++ b/components/camel-spring-boot/pom.xml
@@ -46,6 +46,25 @@
<artifactId>camel-spring</artifactId>
</dependency>
+ <!-- Spring web support -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot</artifactId>
+ <optional>true</optional>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <optional>true</optional>
+ <version>${spring-boot-version}</version>
+ </dependency>
+
<!-- Testing dependencies -->
<dependency>
@@ -54,10 +73,26 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>com.jayway.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>${commons-io-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-netty-http</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/6999028f/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java
new file mode 100644
index 0000000..d712bb0
--- /dev/null
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java
@@ -0,0 +1,33 @@
+/**
+ * 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.spring.boot;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.boot.SpringApplication;
+
+public class FatJarRouter extends RouteBuilder {
+
+ public static void main(String... args) {
+ new SpringApplication(FatJarRouter.class).run(args);
+ }
+
+ @Override
+ public void configure() throws Exception {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6999028f/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatWarInitializer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatWarInitializer.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatWarInitializer.java
new file mode 100644
index 0000000..8e54c51
--- /dev/null
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatWarInitializer.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.
+ */
+package org.apache.camel.spring.boot;
+
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.context.web.SpringBootServletInitializer;
+
+public abstract class FatWarInitializer extends SpringBootServletInitializer {
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(routerClass());
+ }
+
+ protected abstract Class<? extends FatJarRouter> routerClass();
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6999028f/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/JUnitFatJarRouterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/JUnitFatJarRouterTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/JUnitFatJarRouterTest.java
new file mode 100644
index 0000000..322eb40
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/JUnitFatJarRouterTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.spring.boot.fatjarrouter;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.IntegrationTest;
+import org.springframework.boot.test.SpringApplicationConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.util.SocketUtils;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringApplicationConfiguration(classes = TestFatJarRouter.class)
+@IntegrationTest("spring.main.sources=org.apache.camel.spring.boot.fatjarrouter")
+public class JUnitFatJarRouterTest extends Assert {
+
+ static int port = SocketUtils.findAvailableTcpPort();
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.setProperty("http.port", port + "");
+ }
+
+ @Test
+ public void shouldStartCamelRoute() throws InterruptedException, IOException {
+ String response = IOUtils.toString(new URL("http://localhost:" + port));
+
+ assertEquals("stringBean", response);
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/6999028f/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/StandaloneFatJarRouterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/StandaloneFatJarRouterTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/StandaloneFatJarRouterTest.java
new file mode 100644
index 0000000..5013538
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/StandaloneFatJarRouterTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.spring.boot.fatjarrouter;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.concurrent.Callable;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.util.SocketUtils;
+
+import static com.jayway.awaitility.Awaitility.await;
+
+public class StandaloneFatJarRouterTest extends Assert {
+
+ @Test
+ public void shouldStartCamelRoute() throws InterruptedException, IOException {
+ // Given
+ final int port = SocketUtils.findAvailableTcpPort();
+ TestFatJarRouter.main("--spring.main.sources=org.apache.camel.spring.boot.fatjarrouter", "--http.port=" + port);
+ await().until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ new URL("http://localhost:" + port);
+ return true;
+ }
+ });
+
+ // When
+ String response = IOUtils.toString(new URL("http://localhost:" + port));
+
+ // Then
+ assertEquals("stringBean", response);
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/6999028f/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/TestFatJarRouter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/TestFatJarRouter.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/TestFatJarRouter.java
new file mode 100644
index 0000000..87ae366
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarrouter/TestFatJarRouter.java
@@ -0,0 +1,36 @@
+/**
+ * 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.spring.boot.fatjarrouter;
+
+import org.apache.camel.spring.boot.FatJarRouter;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+
+@SpringBootApplication
+public class TestFatJarRouter extends FatJarRouter {
+
+ @Override
+ public void configure() throws Exception {
+ from("netty-http:http://0.0.0.0:{{http.port}}").setBody().simple("ref:stringBean");
+ }
+
+ @Bean
+ String stringBean() {
+ return "stringBean";
+ }
+
+}