java - 骆驼 - 试图达到终点
问题描述
我是骆驼的新手。我正在尝试通过编写一个简单的应用程序来学习。我有一个小项目设置,我正在尝试访问我在网上找到的端点。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>
非常感谢任何帮助,因为我现在只是想学习。提前致谢。
解决方案
添加?bridgeEndpoint=true
到您的 uri。
*在Bedla指出我的回答中的错误后编辑。
推荐阅读
- flutter - 如何将值传递给 dart/Flutter 中的文件路径
- java - 如何在 Java 上的 Windows 中启动交互式进程?
- c++ - 阶乘的大 n
- java - java - 在使用ObjectInputStream反序列化Java时如何检查EOF
- java - 创建 bmi 计算器时出错
- javascript - 标签颜色与背景颜色相同 - ChartJS
- r - 如何将 R 的 S3 类与参数一起使用?
- visual-studio-code - 如何限制我的 VS Code 扩展的 VS Code 引擎最低版本?
- assembly - 'imul' 的操作数大小不匹配
- scala - 如何从响应中获取价值?