我是骆驼新手。我试图通过编写一个简单的应用程序来学习。我有一个小型项目设置,我正在尝试找到我在网上找到的端点。 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());
}
}
AlbumProcessor
public class AlbumProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println(exchange.getIn().getBody(String.class));
}
}
camel-config.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后指出我的答案中的错误。