apache-camel - 设置端点(骆驼)
问题描述
我是骆驼的新手,正在学习设置路线。
所以我从一个简单的场景开始,我点击了一个 URL,它返回了一些数据。对于这个例子,我使用http://services.groupkt.com/country/get/all来返回该数据。
这是我的路径的设置
from("direct:greet")
.autoStartup(true)
.routeId("greet")
.setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.GET))
.to("http4://services.groupkt.com/country/get/all")
现在我有一个 URL 的 requestMapping /check
,当我点击这个 URLhttp://localhost:8080/check
时它返回这个
{ "timestamp": 1527882311362, "status": 404, "error": "Not Found", "message": "No message available", "path": "/check" }
当您在浏览器中点击 URL ( http://services.groupkt.com/country/get/all )时,我希望 JSON 响应会显示所有列出的国家/地区的数据。
映射在其他类中:
@RequestMapping(value = "/check", method = RequestMethod.GET)
public String get(@RequestParam(value = "name") String name) {
return serviceProcessor.getServiceResponse(name);
getServiceResponse 如下:
public String getServiceResponse(String name) {
final ModelCamelContext context = userServiceRoute.getContext();
final ProducerTemplate template = new DefaultProducerTemplate(context);
try {
template.start();
} catch (Exception e) {
LOGGER.error("Error starting producerTemplate with userServiceRoute" + e);
}
final Endpoint endpoint = context.getEndpoint("direct:greet");
template.setDefaultEndpoint(endpoint);
return template.requestBody((Object)name, String.class);
}
路径设置有问题还是方法本身有问题?
解决方案
推荐阅读
- python-3.x - 如何修复 spyder for python 中的导入错误“nvcuda.dll”?
- javascript - 在 vuejs 中将 div 保存为图像文件
- ruby-on-rails - 未定义的方法 `scoped' for #
- knockout.js - 在 Knockout 中绑定后如何重新绑定?
- c# - 检查消息 ID 数组或消息 ID 列表中是否不存在值 SearchFilter.SearchFilterCollection
- sql - 如何在 Hive 表中插入回溯数据?
- javascript - 无法将图像设置为背景
- python - skimage.morphology.watershed 导致 32 位内核死亡
- azure - azure cosmos 分区键的最大值
- .net-core - 在安装了 2.1 的服务器上运行 Core 2.0.x