You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dm...@apache.org on 2018/08/14 15:24:45 UTC
[camel] branch master updated: CAMEL-12729: Align Swagger and Rest
DSL implementation for camel-example-spring-boot-rest-* examples
This is an automated email from the ASF dual-hosted git repository.
dmvolod pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new fa201dd CAMEL-12729: Align Swagger and Rest DSL implementation for camel-example-spring-boot-rest-* examples
fa201dd is described below
commit fa201ddefad0211d7e7d438a958e131c9a5c6246
Author: Dmitry Volodin <dm...@gmail.com>
AuthorDate: Tue Aug 14 18:23:49 2018 +0300
CAMEL-12729: Align Swagger and Rest DSL implementation for
camel-example-spring-boot-rest-* examples
---
.../camel-example-spring-boot-rest-jpa/README.md | 2 +-
.../example/spring/boot/rest/jpa/Application.java | 6 ++++++
.../src/main/resources/application-dev.yml | 5 +++++
.../camel/example/springboot/CamelRouter.java | 22 ++++++++++++++++++++--
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/examples/camel-example-spring-boot-rest-jpa/README.md b/examples/camel-example-spring-boot-rest-jpa/README.md
index 72e3975..475a5e7 100644
--- a/examples/camel-example-spring-boot-rest-jpa/README.md
+++ b/examples/camel-example-spring-boot-rest-jpa/README.md
@@ -25,7 +25,7 @@ $ mvn package
You can run this example with Maven using:
```sh
-$ mvn spring-boot:run
+$ mvn spring-boot:run -Dspring.profiles.active=dev
```
Alternatively, you can also run this example using the executable JAR:
diff --git a/examples/camel-example-spring-boot-rest-jpa/src/main/java/org/apache/camel/example/spring/boot/rest/jpa/Application.java b/examples/camel-example-spring-boot-rest-jpa/src/main/java/org/apache/camel/example/spring/boot/rest/jpa/Application.java
index e595cab..da17c01 100644
--- a/examples/camel-example-spring-boot-rest-jpa/src/main/java/org/apache/camel/example/spring/boot/rest/jpa/Application.java
+++ b/examples/camel-example-spring-boot-rest-jpa/src/main/java/org/apache/camel/example/spring/boot/rest/jpa/Application.java
@@ -18,9 +18,11 @@ package org.apache.camel.example.spring.boot.rest.jpa;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@SpringBootApplication
@@ -29,6 +31,9 @@ public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
+
+ @Autowired
+ private Environment env;
@Component
class RestApi extends RouteBuilder {
@@ -41,6 +46,7 @@ public class Application extends SpringBootServletInitializer {
.apiProperty("api.version", "1.0")
.apiProperty("cors", "true")
.apiContextRouteId("doc-api")
+ .port(env.getProperty("server.port", "8080"))
.bindingMode(RestBindingMode.json);
rest("/books").description("Books REST service")
diff --git a/examples/camel-example-spring-boot-rest-jpa/src/main/resources/application-dev.yml b/examples/camel-example-spring-boot-rest-jpa/src/main/resources/application-dev.yml
index dcc0a56..7fb0971 100644
--- a/examples/camel-example-spring-boot-rest-jpa/src/main/resources/application-dev.yml
+++ b/examples/camel-example-spring-boot-rest-jpa/src/main/resources/application-dev.yml
@@ -19,6 +19,11 @@ camel:
springboot:
# The Camel context name
name: CamelRestJpa
+
+ component:
+ servlet:
+ mapping:
+ contextPath: /camel-rest-jpa/*
spring:
# Spring JDBC configuration
diff --git a/examples/camel-example-spring-boot-rest-swagger/src/main/java/org/apache/camel/example/springboot/CamelRouter.java b/examples/camel-example-spring-boot-rest-swagger/src/main/java/org/apache/camel/example/springboot/CamelRouter.java
index e43daca..d6c7591 100644
--- a/examples/camel-example-spring-boot-rest-swagger/src/main/java/org/apache/camel/example/springboot/CamelRouter.java
+++ b/examples/camel-example-spring-boot-rest-swagger/src/main/java/org/apache/camel/example/springboot/CamelRouter.java
@@ -18,28 +18,41 @@ package org.apache.camel.example.springboot;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import static org.apache.camel.model.rest.RestParamType.body;
import static org.apache.camel.model.rest.RestParamType.path;
+import org.apache.camel.Exchange;
+
/**
* A simple Camel REST DSL route with Swagger API documentation.
*/
@Component
public class CamelRouter extends RouteBuilder {
+
+ @Autowired
+ private Environment env;
+
+ @Value("${camel.component.servlet.mapping.context-path}")
+ private String contextPath;
@Override
public void configure() throws Exception {
// @formatter:off
-
+
// this can also be configured in application.properties
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.enableCORS(true)
+ .port(env.getProperty("server.port", "8080"))
+ .contextPath(contextPath.substring(0, contextPath.length() - 2))
// turn on swagger api-doc
.apiContextPath("/api-doc")
.apiProperty("api.title", "User API")
@@ -63,7 +76,12 @@ public class CamelRouter extends RouteBuilder {
.param().name("id").type(path).description("The ID of the user to update").dataType("integer").endParam()
.param().name("body").type(body).description("The user to update").endParam()
.responseMessage().code(204).message("User successfully updated").endResponseMessage()
- .to("bean:userService?method=updateUser");
+ .to("direct:update-user");
+
+ from("direct:update-user")
+ .to("bean:userService?method=updateUser")
+ .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(204))
+ .setBody(constant(""));
// @formatter:on
}