1 Star 0 Fork 1

寒松/camel-spring-boot-examples2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
README.adoc 3.54 KB
一键复制 编辑 原始数据 按行查看 历史

Spring Boot Example with Camel REST DSL, Geocoder and Swagger

Introduction

This example illustrates how to use Spring Boot with Camel. It provides a simple REST service that is created with Camel REST DSL, using the Geocoder component and documented with Swagger.

The project uses the camel-spring-boot-starter and camel-geocoder-starter dependencies as Spring Boot starter dependencies for Camel that simplify the Maven configuration.

The project was based on it’s camel-example-spring-boot-rest-swagger sibling.

Build

You can build this example using:

$ mvn package

Run

You can run this example using:

$ mvn spring-boot:run

You should see the following output when the application is launched:

[...]
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.0.RELEASE)
[...]
2018-03-30 16:28:56.354  INFO 29880 --- [           main] o.a.c.e.springboot.geocoder.Application  : Started Application in 4.806 seconds (JVM running for 5.435)

After the Spring Boot application is started, you can open the following URL in your web browser to access the REST endpoint and request the address for "Paris": http://localhost:8080/camel/geocoder/?address=Paris

You can also access the REST endpoint from the command line:

$ curl http://localhost:8080/camel/geocoder/?address=Paris

You’ll need to setup the google Maps API credentials to make this example work.

The command will produce the following output:

{
  "status" : "OK",
  "results" : [ {
    "types" : [ "locality", "political" ],
    "formattedAddress" : "Paris, France",
    "addressComponents" : [ {
      "longName" : "Paris",
      "shortName" : "Paris",
      "types" : [ "locality", "political" ]
    }, {
      "longName" : "Paris",
      "shortName" : "Paris",
      "types" : [ "administrative_area_level_2", "political" ]
    }, {
      "longName" : "Île-de-France",
      "shortName" : "Île-de-France",
      "types" : [ "administrative_area_level_1", "political" ]
    }, {
      "longName" : "France",
      "shortName" : "FR",
      "types" : [ "country", "political" ]
    } ],
    "geometry" : {
      "location" : {
        "lat" : 48.856614,
        "lng" : 2.3522219
      },
      "locationType" : "APPROXIMATE",
      "viewport" : {
        "southwest" : {
          "lat" : 48.815573,
          "lng" : 2.225193
        },
        "northeast" : {
          "lat" : 48.9021449,
          "lng" : 2.4699208
        }
      },
      "bounds" : {
        "southwest" : {
          "lat" : 48.815573,
          "lng" : 2.224199
        },
        "northeast" : {
          "lat" : 48.9021449,
          "lng" : 2.4699208
        }
      }
    },
    "partialMatch" : false
  } ]
}

The Swagger documentation is located at: http://localhost:8080/camel/api-doc and can be retrieved with the following command:

$ curl http://localhost:8080/camel/api-doc

The Spring Boot application can be stopped pressing [CTRL]+[C] in the shell.

Help and contributions

If you hit any problem using Camel or have some feedback, then please let us know.

We also love contributors, so get involved :-)

The Camel riders!

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qqzahng/camel-spring-boot-examples2.git
git@gitee.com:qqzahng/camel-spring-boot-examples2.git
qqzahng
camel-spring-boot-examples2
camel-spring-boot-examples2
camel-3.4.x

搜索帮助

0d507c66 1850385 C8b1a773 1850385