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.
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.
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!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。