You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Alexander Domke (Jira)" <ji...@apache.org> on 2022/09/23 16:20:00 UTC

[jira] [Created] (CAMEL-18545) Load a route from XML file does not work

Alexander Domke created CAMEL-18545:
---------------------------------------

             Summary: 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


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)