New to Camel + SpringBoot + Swagger. Created some REST APIs using Camel 3.8.0 and SpringBoot 2.4.2 (using Camel's Servlet on Default TomCat of SpringBoot).
Here is pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/>
</parent>
<groupId>com.crsardar.java.apache.camel</groupId>
<artifactId>hands-on-camel-springboot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<camelVersion>3.8.0</camelVersion>
</properties>
<dependencies>
<!-- SpringBoot -->
<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-bom</artifactId>
<version>${camelVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camelVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet-starter</artifactId>
<version>${camelVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>${camelVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-rest-swagger-starter</artifactId>
<version>${camelVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swagger-java</artifactId>
<version>${camelVersion}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.40</version>
</dependency>
<!-- Others -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.18</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Configuration and REST end points -
package com.crsardar.java.apache.camel;
import com.crsardar.java.dao.Order;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
@Component
public class CamelController extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.component("servlet")
.port(8080)
.host("127.0.0.1")
.apiContextPath("api-docs")
.apiContextIdPattern("#name#")
.apiProperty("api.title", "Test REST API")
.apiProperty("api.version", "v1")
.apiProperty("cors", "true")
.bindingMode(RestBindingMode.json);
rest().post("/order")
.produces(MediaType.APPLICATION_JSON_VALUE)
.type(Order.class)
.outType(Order.class)
.to("bean:orderService?method=addOrder(${body})");
rest().get("/order")
.produces(MediaType.APPLICATION_JSON_VALUE)
.to("bean:orderService?method=getOrders()");
}
}
I am trying to document it and give an option to test it using Swagger UI.
If I run the application and hit http://127.0.0.1:8080/api-docs I am getting Swagger's API documentation.
But, I can not try it using Swagger UI, How can I make Swagger UI working on it?
I do not know - Whether Swagger-UI is working on this app or not? If working, what will be the URL for Swagger-UI?
Complete code is here https://github.com/crsardar/hands-on-java/tree/master/hands-on-camel-springboot