Я пытаюсь вызвать REST API, используя apache camel, но я получил исключение
org.apache.camel.FailedToCreateRouteException: не удалось создать маршрут route1 в: >>> To [http://devloyalty.darkwing.io/api/test_loyalty] <<< in route: Route (route1) [[From [direct: start]] -> [SetHeader [CamelHttpMe ... из-за не удалось разрешить конечную точку: "my_url_here" из-за: не найден компонент ссхема: http
Пример кода
public class RestApiRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:start").
setHeader(Exchange.HTTP_METHOD, constant("GET")).
setHeader(Exchange.CONTENT_TYPE, constant("text/plain")).
to("my_url");
}
}
и
public void restApiTest(){
RestApiRouteBuilder restApiRouteBuilder = new RestApiRouteBuilder();
CamelContext camelContext = new DefaultCamelContext();
try{
camelContext.addRoutes(restApiRouteBuilder);
camelContext.start();
ProducerTemplate template = camelContext.createProducerTemplate();
String headerValue = "text/plain";
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(camelContext);
String response = ExchangeHelper.convertToType(exchange, String.class, result);
System.out.println("Response : "+response);
} catch (Exception e){
System.out.println("The Exception is : " + e);
}
}
также maven зависимость для верблюда http
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http4</artifactId>
<version>2.22.2</version>
<scope>test</scope>
</dependency>