[ 
https://issues.apache.org/jira/browse/CAMEL-18545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17609243#comment-17609243
 ] 

Alexander Domke commented on CAMEL-18545:
-----------------------------------------

Hi Claus, thanks for your quick reply. Also my attempt to extend a Blueprint 
Camel Context at runtime with additional routes was not successful. Here is the 
approach:

*My Test Implementation:*
{code:java}
package testbundle;

import java.io.File;
import java.nio.file.Files;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.blueprint.BlueprintCamelContext;
import org.apache.camel.spi.Resource;
import org.apache.camel.support.DefaultExchange;
import org.apache.camel.support.ResourceHelper;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component(
    immediate = true,
    service = TestBundle.class,
    property = {"osgi.command.scope=test", "osgi.command.function=loadRoutes"})
public class TestBundle {

  public BlueprintCamelContext camelContext;

  @Reference(target = "(camel.context.name=dummyCamelContext)")
  public void bindCamelContext(CamelContext camelContext) {
    this.camelContext = (BlueprintCamelContext) camelContext;
  }

  public void unbindCamelContext() {
    camelContext = null;
  }

  public void loadRoutes() throws Exception {
    loadRoute("C:\\tmp\\before_create.xml", camelContext);
    camelContext.start();
    Exchange exchange = new DefaultExchange(camelContext);
    ProducerTemplate producerTemplate = 
exchange.getContext().createProducerTemplate();
    Exchange resultExchange = producerTemplate.send("direct:start", exchange);
    System.out.println("resultExchange: " + resultExchange);

    if (resultExchange.getException() != null) {
      throw resultExchange.getException();
    }
  }

  private void loadRoute(String name, BlueprintCamelContext camelContext) {
    ExtendedCamelContext ecc = camelContext.adapt(ExtendedCamelContext.class);
    try {
      File file = new File(name);
      byte[] content = Files.readAllBytes(file.toPath());
      Resource resource = ResourceHelper.fromBytes(file.getAbsolutePath(), 
content);
      ecc.getRoutesLoader().loadRoutes(resource);
      System.out.println("ecc routes: " + ecc.getRoutes());
      System.out.println("camelContext routes: " + 
camelContext.getRouteDefinitions());

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}

{code}

*My Blueprint with camel context:*
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"; 
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"; 
xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0"; xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>
    <camelContext xmlns="http://camel.apache.org/schema/blueprint"; 
id="dummyCamelContext">
        <route id="create" autoStartup="true">
            <from uri="direct:dummyStart" />
            <to uri="mock:dummyEnd" />
        </route>
    </camelContext>
</blueprint>
{code}


*My Route to load:*
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>
    <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns="http://camel.apache.org/schema/blueprint"; xsi:schemaLocation="
            http://camel.apache.org/schema/blueprint
            http://camel.apache.org/schema/blueprint/camel-blueprint.xsd";>

        <route id="xml-route" autoStartup="true">
            <from uri="direct:start" />
            <log message="Hello XML!" />
        </route>
    </routes>
</blueprint>
{code}

Error executing command: No consumers available on endpoint: direct://start. 
Exchange[]

I am at a loss, do you have any idea what I am doing wrong?


> Load a route from XML file does not work
> ----------------------------------------
>
>                 Key: CAMEL-18545
>                 URL: https://issues.apache.org/jira/browse/CAMEL-18545
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-blueprint, camel-osgi
>            Reporter: Alexander Domke
>            Assignee: Grzegorz Grzybek
>            Priority: Major
>
> Hello together!
> I am trying to load an XML route in a Karaf OSGi runtime and add it to a 
> camel context. Then I plan to pass an exchange to the endpoint from the 
> loaded route. All my attempts so far have failed and I don't know what to do 
> anymore. I have already investigated open Camel Jira issues and found nothing 
> that points to an existing problem. 
> *My Test Implementation:*
> {code:java}
> package testbundle;
> import java.io.File;
> import java.nio.file.Files;
> import org.apache.camel.Exchange;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.core.osgi.OsgiCamelContextHelper;
> import org.apache.camel.core.osgi.OsgiCamelContextPublisher;
> import org.apache.camel.core.osgi.OsgiDefaultCamelContext;
> import org.apache.camel.dsl.xml.io.XmlRoutesBuilderLoader;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.apache.camel.spi.Resource;
> import org.apache.camel.support.DefaultExchange;
> import org.apache.camel.support.ResourceHelper;
> import org.osgi.framework.BundleContext;
> import org.osgi.service.component.annotations.Activate;
> import org.osgi.service.component.annotations.Component;
> @Component(
>     immediate = true,
>     service = TestBundle.class,
>     property = {"osgi.command.scope=test", 
> "osgi.command.function=loadRoutes"})
> public class TestBundle {
>   private BundleContext bundleContext;
>   @Activate
>   public void activate(BundleContext bundleContext) {
>     this.bundleContext = bundleContext;
>   }
>   public void loadRoutes() throws Exception {
>     OsgiDefaultCamelContext camelContext = null;
>     try (OsgiCamelContextPublisher publisher = new 
> OsgiCamelContextPublisher(bundleContext); ) {
>       camelContext = new OsgiDefaultCamelContext(bundleContext);
>       OsgiCamelContextHelper.osgiUpdate(camelContext, bundleContext);
>       publisher.registerCamelContext(camelContext);
>       loadRoute("C:\\tmp\\before_create.xml", (DefaultCamelContext) 
> camelContext);
>       camelContext.start();
>       Exchange exchange = new DefaultExchange(camelContext);
>       ProducerTemplate producerTemplate = 
> exchange.getContext().createProducerTemplate();
>       Exchange resultExchange = producerTemplate.send("direct:start", 
> exchange);
>       System.out.println("resultExchange: " + resultExchange);
>       if (resultExchange.getException() != null) {
>         throw resultExchange.getException();
>       }
>     } finally {
>       camelContext.stop();
>     }
>   }
>   private void loadRoute(String name, DefaultCamelContext camelContext) {
>     try {
>       File file = new File(name);
>       byte[] content = Files.readAllBytes(file.toPath());
>       Resource resource = ResourceHelper.fromBytes(file.getAbsolutePath(), 
> content);
>       RouteBuilder builder =
>           (RouteBuilder) new 
> XmlRoutesBuilderLoader().loadRoutesBuilder(resource);
>       builder.setCamelContext(camelContext);
>       builder.configure();
>     } catch (Exception e) {
>       throw new RuntimeException(e);
>     }
>   }
> }
> {code}
> *My Test Route:*
> {code:xml}
> <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>         xmlns="http://camel.apache.org/schema/spring";
>         xsi:schemaLocation="
>             http://camel.apache.org/schema/spring
>             http://camel.apache.org/schema/spring/camel-spring.xsd";>
>     <route id="xml-route" autoStartup="true">
>         <from uri="direct:start"/>
>         <log message="Hello XML!"/>
>     </route>
> </routes>
> {code}
> *Installed Karaf Features:*
> {code:java}
> Name            | Version | Required | State   | Repository     | Description
> ----------------+---------+----------+---------+----------------+--------------------------------------------------
> xml-specs-api   | 2.9.0   |          | Started | camel-3.18.2   |
> camel           | 3.18.2  | x        | Started | camel-3.18.2   |
> camel-core      | 3.18.2  |          | Started | camel-3.18.2   |
> camel-blueprint | 3.18.2  | x        | Started | camel-3.18.2   |
> camel-jaxb      | 3.18.2  | x        | Started | camel-3.18.2   |
> aries-proxy     | 4.4.1   |          | Started | standard-4.4.1 | Aries Proxy
> aries-blueprint | 4.4.1   |          | Started | standard-4.4.1 | Aries 
> Blueprint
> feature         | 4.4.1   | x        | Started | standard-4.4.1 | Features 
> Support
> shell           | 4.4.1   | x        | Started | standard-4.4.1 | Karaf Shell
> deployer        | 4.4.1   | x        | Started | standard-4.4.1 | Karaf 
> Deployer
> bundle          | 4.4.1   | x        | Started | standard-4.4.1 | Provide 
> Bundle support
> config          | 4.4.1   | x        | Started | standard-4.4.1 | Provide 
> OSGi ConfigAdmin support
> diagnostic      | 4.4.1   | x        | Started | standard-4.4.1 | Provide 
> Diagnostic support
> instance        | 4.4.1   | x        | Started | standard-4.4.1 | Provide 
> Instance support
> jaas            | 4.4.1   | x        | Started | standard-4.4.1 | Provide 
> JAAS support
> log             | 4.4.1   | x        | Started | standard-4.4.1 | Provide Log 
> support
> package         | 4.4.1   | x        | Started | standard-4.4.1 | Package 
> commands and mbeans
> service         | 4.4.1   | x        | Started | standard-4.4.1 | Provide 
> Service support
> system          | 4.4.1   | x        | Started | standard-4.4.1 | Provide 
> System support
> kar             | 4.4.1   | x        | Started | standard-4.4.1 | Provide KAR 
> (KARaf archive) support
> ssh             | 4.4.1   | x        | Started | standard-4.4.1 | Provide a 
> SSHd server on Karaf
> management      | 4.4.1   | x        | Started | standard-4.4.1 | Provide a 
> JMX MBeanServer and a set of MBeans in
> eventadmin      | 4.4.1   | x        | Started | standard-4.4.1 | OSGi Event 
> Admin service specification for event-
> scr             | 4.4.1   | x        | Started | standard-4.4.1 | Declarative 
> Service support
> pax-url-wrap    | 2.6.11  |          | Started | standard-4.4.1 | Wrap URL 
> handler
> wrap            | 2.6.11  | x        | Started | standard-4.4.1 | Transition 
> feature to pax-url-wrap
> {code}
> *Installed Bundles:*
> {code:java}
> 121 | Active   |  80 | 3.18.2             | camel-xml-io
> 123 | Active   |  80 | 3.18.2             | camel-xml-io-dsl
> 125 | Active   |  80 | 3.18.2             | camel-dsl-support
> {code}
> Error I get after sending the exchange:
> {code:bash}
> 18:03:22.483 ERROR [Karaf local console user karaf] Exception caught while 
> executing command
> org.apache.camel.component.direct.DirectConsumerNotAvailableException: No 
> consumers available on endpoint: direct://start. Exchange[]
>         at 
> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:82)
>  ~[?:?]
>         at 
> org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:214)
>  ~[?:?]
>         at 
> org.apache.camel.impl.engine.SharedCamelInternalProcessor$1.process(SharedCamelInternalProcessor.java:111)
>  ~[?:?]
>         at 
> org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:83)
>  ~[?:?]
>         at 
> org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:108)
>  ~[?:?]
>         at 
> org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProducerCache.java:199)
>  ~[?:?]
>         at 
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:176)
>  ~[?:?]
>         at 
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:148)
>  ~[?:?]
>         at 
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:131)
>  ~[?:?]
>         at testbundle.TestBundle.loadRoutes(TestBundle.java:47) ~[?:?]
>         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
> Method) ~[?:?]
>         at 
> jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  ~[?:?]
>         at 
> jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:?]
>         at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
>         at 
> org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:143) ~[?:?]
>         at 
> org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:91) 
> ~[?:?]
>         at 
> org.apache.karaf.shell.impl.console.osgi.CommandTracker$1.execute(CommandTracker.java:112)
>  ~[?:?]
>         at 
> org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:68)
>  ~[?:?]
>         at 
> org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:86)
>  ~[?:?]
>         at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:599) 
> ~[?:?]
>         at 
> org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:526) 
> ~[?:?]
>         at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:415) 
> ~[?:?]
>         at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:416) ~[?:?]
>         at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229) ~[?:?]
>         at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59) ~[?:?]
>         at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
>         at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
>  ~[?:?]
>         at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
>  ~[?:?]
>         at java.lang.Thread.run(Thread.java:834) ~[?:?]
> {code}
> For the tests I used Camel version 3.18.2 and Karaf version 4.4.1. 
> Maybe one of you has done this before and can point me to the right solution?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to