我编写了一份使用Apache Camel调用REST API的示例代码。这份代码在独立环境下可以正常运行,但当我将同样的代码用于创建OSGI bundle并将其部署到Karaf容器中时,尽管bundle已经成功创建,但是当我尝试调用它时出现了"No component found with scheme http"等错误信息。
请问您能帮助我解决这个问题吗?
这是我的代码:
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start")
.setHeader(Exchange.HTTP_METHOD,simple("GET"))
.to("http://10.10.10.10:8080/RestfulDemo/rest/get");
}
});
context.start();
ProducerTemplate template = context.createProducerTemplate();
String headerValue = "application/xml";
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(context);
String response = ExchangeHelper.convertToType(exchange, String.class, result);
System.out.println("Response : "+response);
context.stop();
以下是错误信息:
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: http://10.10.10.10:8080/RestfulDemo/rest/get due to: No component found with scheme: http