gpt4 book ai didi

java - Camel - 试图到达终点

转载 作者:行者123 更新时间:2023-12-01 16:39:21 25 4
gpt4 key购买 nike

我是 Camel 新手。我正在尝试通过编写一个简单的应用程序来学习。我有一个小型项目设置,我正在尝试达到我在网上找到的端点。 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));

}

}

Camel 配置.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 应该具有所有依赖项。像:

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>

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

最佳答案

?bridgeEndpoint=true 添加到您的 uri。

*在Bedla指出我的答案中的错误后进行编辑。

关于java - Camel - 试图到达终点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61897194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com