首页 > 解决方案 > 设置端点(骆驼)

问题描述

我是骆驼的新手,正在学习设置路线。

所以我从一个简单的场景开始,我点击了一个 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);

}

路径设置有问题还是方法本身有问题?

标签: apache-camel

解决方案


推荐阅读