14
votes

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
5
It would help to add the whole stacktrace of the error. - Martín Schonaker

5 Answers

19
votes

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

4
votes

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.

1
votes

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();
}   
0
votes

Try not only adding the entry to the pom, but also add the HTTPComponent object to your camel context like so...

    HttpComponent httpComponent = new HttpComponent();
    context.addComponent("http", httpComponent);
0
votes

Please add apache camel-http dependency in your pom or build.gradle, this will resolve your error.

eg. implementation group: 'org.apache.camel', name: 'camel-http', version: '3.1.0'