首页 > 解决方案 > 骆驼 - 试图达到终点

问题描述

我是骆驼的新手。我正在尝试通过编写一个简单的应用程序来学习。我有一个小项目设置,我正在尝试访问我在网上找到的端点。enpoint 确实返回 json。

我得到的错误是:

org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> 
To[https://jsonplaceholder.typicode.com/albums] <<< in route: Route(route1)[[From[direct:httpRoute]] -> [SetHeader[CamelHt... because of Failed to resolve endpoint: 
https://jsonplaceholder.typicode.com/albums due to: No component found with scheme: https

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: 
https://jsonplaceholder.typicode.com/albums due to: No component found with scheme: https

这是主要方法

 public static void main(String[] args) {

    CamelContext camelContext = new DefaultCamelContext();
    try {

        camelContext.addRoutes(new MyRouteBuilder());
        camelContext.start();
        Thread.sleep(5000);
        camelContext.stop();

    }catch (Exception e){
        e.printStackTrace();
    }

}

MyRouteBuilder

public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {

    from("direct:httpRoute").setHeader(Exchange.HTTP_METHOD, simple("GET"))
            .to("https://jsonplaceholder.typicode.com/albums")
            .process(new AlbumProcessor());
    }
}

专辑处理器

public class AlbumProcessor implements Processor {


@Override
public void process(Exchange exchange) throws Exception {

    System.out.println(exchange.getIn().getBody(String.class));

}

}

骆驼配置.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring
    http://camel.apache.org/schema/spring/camel-spring.xsd">

<bean id="routeBuilder" class="com.learncamel.MyRouteBuilder" />
<bean id="processor" class="com.learncamel.AlbumProcessor" />

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <routeBuilder ref="routeBuilder" />
</camelContext>

pom 应该具有所有依赖项。喜欢:

绒球

  <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http</artifactId>
        <version>3.3.0</version>
        <scope>test</scope>
    </dependency>

    <!-- http components -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.5</version>
    </dependency>

非常感谢任何帮助,因为我现在只是想学习。提前致谢。

标签: javaapache-camelendpoint

解决方案


添加?bridgeEndpoint=true到您的 uri。

*在Bedla指出我的回答中的错误后编辑。


推荐阅读