Java 在 apache 骆驼中找不到带有方案 http 错误的组件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22264790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No component found with scheme http error in apache camel
提问by Azhaguvel A
I have written sample code for calling rest api using apache camel. Which is working correctly in standalone but the same code I have used to create OSGI bundle and deploy it into the karaf container that the bundle is created sucessfully but i am getting the error such as "No component found with scheme http"when i try to call it.
我已经编写了使用 apache camel 调用 rest api 的示例代码。哪个在独立模式下工作正常,但我用来创建 OSGI 包并将其部署到成功创建包的 karaf 容器中的代码相同,但是当我尝试时出现错误,例如“没有使用方案 http 找到组件”称它为。
Can you help me to resolve this issue?
你能帮我解决这个问题吗?
Here's the code :
这是代码:
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();
Error below :
下面的错误:
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
回答by Peter Keller
Add following snipplet to your pom.xml
:
将以下代码片段添加到您的pom.xml
:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
If you use Camel in a OSGI/Karaf/ServiceMix/JBoss FUSE ESB Environment you have to add the bundle via Karaf console with
如果您在 OSGI/Karaf/ServiceMix/JBoss FUSE ESB 环境中使用 Camel,则必须通过 Karaf 控制台添加包
features:install camel-http
Find more information about installing camel for Karaf, have a look at http://camel.apache.org/karaf
查找有关为 Karaf 安装骆驼的更多信息,请查看http://camel.apache.org/karaf
回答by Willem Jiang
If you create the camel context in OSGi, you need to create OsgiDefaultCamelContext instead of DefaultCamelContext, and you need to pass the bundle context as the construction parameter.
如果在 OSGi 中创建骆驼上下文,则需要创建 OsgiDefaultCamelContext 而不是 DefaultCamelContext,并且需要传递 bundle 上下文作为构造参数。
If you are using Blueprint or Spring, it could be much easy for you by look up the camel context from the Application context then create a new camel context yourself.
如果您使用的是 Blueprint 或 Spring,通过从应用程序上下文中查找骆驼上下文,然后自己创建一个新的骆驼上下文,对您来说可能会容易得多。
回答by Tatecabbage
Try not only adding the entry to the pom, but also add the HTTPComponent object to your camel context like so...
尝试不仅将条目添加到 pom,还要像这样将 HTTPComponent 对象添加到您的骆驼上下文中......
HttpComponent httpComponent = new HttpComponent();
context.addComponent("http", httpComponent);