小编Azh*_*l A的帖子

在apache camel中找不到与http http错误的组件

我已经编写了使用apache camel调用rest api的示例代码.哪个在独立工作正常,但是我用来创建OSGI捆绑包的相同代码并将其部署到karaf容器中,捆绑包是成功创建的但我得到的错误如"没有组件找到方案http"当我尝试叫它.

你能帮我解决这个问题吗?

这是代码:

        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {
            public void configure() {
                from("direct:start")
                .setHeader(Exchange.HTTP_METHOD,simple("GET"))
                .to("http://10.10.10.10:8080/RestfulDemo/rest/get");
            }
        });

        context.start();

        ProducerTemplate template = context.createProducerTemplate();
        String headerValue = "application/xml";

        Map<String, Object> headers = new HashMap<String,Object>();
        headers.put("Content-Type", headerValue);

        Object result = template.requestBodyAndHeaders("direct:start", null, headers, String.class);
        Exchange exchange = new DefaultExchange(context); 
        String response = ExchangeHelper.convertToType(exchange, String.class, result); 
        System.out.println("Response : "+response);
        context.stop();
Run Code Online (Sandbox Code Playgroud)

错误如下:

org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: http://10.10.10.10:8080/RestfulDemo/rest/get due to: No component found with scheme: http
Run Code Online (Sandbox Code Playgroud)

java apache-camel

13
推荐指数
1
解决办法
2万
查看次数

如何解决 Apache Camel 中的“无法创建路由 route1 异常”?

我是 Apache Camel 概念的新手。我曾尝试使用 apache camel API 编写示例代码,但在尝试运行代码时出现以下异常。

谁能帮我解决这个问题?

这是示例代码和一个例外,

示例代码:

 CamelContext context = new DefaultCamelContext();
 context.addRoutes(new RouteBuilder() { 
  public void configure() {
    from("direct:start")
    .setHeader(Exchange.HTTP_URI,simple("`http://sample-host:8080/demo/get`"))
    .to("http://emptyhost");
  }
 });
 context.start();
 ProducerTemplate template = context.createProducerTemplate();
 System.out.println(template.requestBodyAndHeaders("direct:start", null, null,String.class));
Run Code Online (Sandbox Code Playgroud)

例外 :

Exception in thread "main" org.apache.camel.FailedToCreateRouteException: 
Failed to create route route1 at: 
    >>> To[`http://sample-host:8080/demo/get`] <<< 
in route: Route(route1)
    [[From[direct:start]] -> [`To[http://sample-host:8`…
because of 
    Failed to resolve endpoint: `http://sample-host:8080/demo/get`
due to: 
    No component found with scheme: http
Run Code Online (Sandbox Code Playgroud)

java apache-camel

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

apache-camel ×2

java ×2