Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No component found with scheme http error in apache camel

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.

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
like image 820
Azhaguvel A Avatar asked Mar 08 '14 03:03

Azhaguvel A


3 Answers

Add following snipplet to your 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

features:install camel-http

Find more information about installing camel for Karaf, have a look at http://camel.apache.org/karaf

like image 50
Peter Keller Avatar answered Oct 18 '22 10:10

Peter Keller


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.

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.

like image 4
Willem Jiang Avatar answered Oct 18 '22 11:10

Willem Jiang


Initializing the beans solved the issue. My app was using Camel with Spring Boot and DefaultCamelContext had "scheme" value as Null as the httpComponent was not set.

Hence, no component found with scheme: https

Initializing the bean on startup the scheme was set as expected.

import org.springframework.context.annotation.Bean;

@Bean({"http","https"})
HttpComponent httpComponent() {
    return new HttpComponent();
}   
like image 1
Aparna Avatar answered Oct 18 '22 09:10

Aparna