14

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
Azhaguvel A
  • 631
  • 2
  • 10
  • 24

5 Answers5

19

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

Peter Keller
  • 7,526
  • 2
  • 26
  • 29
  • 2
    I have used the same version for both but still i am facing the same problem. – Azhaguvel A Mar 08 '14 at 09:18
  • @AzhaguvelA Do you use an OSGI environment? I added how to add the `camel-http` feature in my answer. – Peter Keller Mar 08 '14 at 09:28
  • Yes, I am using an OSGI environment. In an OSGI list, every camel supported lib are installed with active state. Still Do I need to install all those lib's in features console? – Azhaguvel A Mar 08 '14 at 13:29
  • If `camel-http` is already installed with `Active` status (use `list | grep camel-http`), then you don't need to install it a second time. – Peter Keller Mar 08 '14 at 14:51
  • camel-http is appearing under osgi:list not in features:list. Is this correct installation or need to install it under features group? – Azhaguvel A Mar 08 '14 at 14:59
  • If you don't find it under `features:list`, then try `features:install camel-http` as stated in my answer. If you use karaf have a look at http://camel.apache.org/karaf for more information – Peter Keller Mar 08 '14 at 15:04
  • Information about karaf can now be found at https://camel.apache.org/camel-karaf – Peter Keller Dec 05 '20 at 12:06
4

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.

Willem Jiang
  • 3,291
  • 1
  • 14
  • 14
1

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();
}   
Aparna
  • 11
  • 3
0

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

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'

user3769960
  • 91
  • 1
  • 5