"camel-blueprint" namespace not found in blueprint declaration (Aries within Felix) - apache-camel

I'm trying to run a standalone OSGi framework to run blueprint bundles within it that execute camel routes. The OSGi framework is Apache Felix, the blueprint implementation is Apache Aries.
The following bundles are loaded to the BundleContext of the framework:
Now I have a test bundle that has a blueprint definition which contains a camelContext that looks as follows:
<?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"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="testRoute1">
<from uri="timer:foo?period=5000" />
<log message="Hello world!" />
</route>
</camelContext>
</blueprint>
Even though all the bundles are loaded and the requirements are resolved, the blueprint container gives the following log:
[de.hff.yosgi.test1.Test] : Installing test bundle
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[de.hff.yosgi.test1.Test] : Test bundle installed, starting
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[org.apache.aries.blueprint.container.BlueprintExtender] : Scanning bundle osgi-test1 for blueprint application
[org.apache.aries.blueprint.container.BlueprintExtender] : Found blueprint application in bundle osgi-test1 with paths: [bundle://24.0:0/OSGI-INF/blueprint/blueprint.xml]
[org.apache.aries.blueprint.container.BlueprintExtender] : Scheduling creation of blueprint bundle osgi-test1 asynchronously
[org.apache.aries.blueprint.container.BlueprintContainerImpl] : Running blueprint container for bundle osgi-test1 in state Unknown
[org.apache.aries.blueprint.container.BlueprintEventDispatcher] : Sending blueprint container event BlueprintEvent[type=CREATING] for bundle osgi-test1
[de.hff.yosgi.test1.Test] : Test bundle started
[org.apache.aries.blueprint.container.BlueprintContainerImpl] : Running blueprint container for bundle osgi-test1 in state WaitForNamespaceHandlers
[org.apache.aries.blueprint.container.BlueprintContainerImpl] : Bundle osgi-test1 is waiting for namespace handlers [http://camel.apache.org/schema/blueprint]
[org.apache.aries.blueprint.container.BlueprintEventDispatcher] : Sending blueprint container event BlueprintEvent[type=GRACE_PERIOD, dependencies=[(&(objectClass=org.apache.aries.blueprint.NamespaceHandler)(osgi.service.blueprint.namespace=http://camel.apache.org/schema/blueprint))]] for bundle osgi-test1
The important line here is the Waiting for namespace handlers: the test bundle can't find the camel-blueprint namespace. But this namespace should be defined in the camel-blueprint bundle that is installed.
Without the camelContext in the blueprint, everything works (blueprint services are loaded and initialized).
Has anyone had similar problems with this? What is preventing the test bundle to have access to the camel-blueprint provided namespaces?

We fixed this issue by cleaning up the dependencies. Only the following are actually required:
Also, to successfully get Camel to run inside Aries Blueprint, an additional parameter is required when instantiating the framework. This allows the bundles to access the sun.* packages.
Iterator<FrameworkFactory> iterator =
ServiceLoader.load(FrameworkFactory.class).iterator();
FrameworkFactory factory = iterator.next();
Map<> configuration = new HashMap<String, String>();
configuration.put("org.osgi.framework.bootdelegation", "sun.*");
this.framework = factory.newFramework(configuration);

Related

OSGI service Call using Camel route

I get method not found exception when I try to connect/call OSGI service using camel route and I am not sure what logic I am missing here.
//Exception
Caused by: org.apache.camel.RuntimeCamelException: org.apache.camel.component.bean.MethodNotFoundException: Static method with name: getGreeting not found on class: com.test.api.Hello
//The below is the blueprint that exports osgi service
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="hello" class="com.test.HelloImpl"/>
<service ref="hello" interface="com.test.api.Hello"/>
</blueprint>
// Below is Java Interface and I did not include the java implementation code for interface here. but FYI, all method and class are declared as public
package com.test.api;
public interface Hello {
public String getGreeting();
}
//This below timer route is in Java DSL that is called by the route builder ref in the camel context and this camel context is defined inside blueprint
from("timer:foo?repeatCount=1")
.bean(com.test.api.Hello.class, "getGreeting")
.log("The message contains: ${body}")
I got the same exception when I tried executing this route in the same bundle where I export interface service and also I tried executing this timer route in another separate bundle by referencing the exported OSGI interface.
I am testing/executing these bundles in Red Hat Fuse server.
Request for thumbs down audience: please specify the reason before you thumbs down so that helps me to ask question in better way in future.
Thanks!!

Apache Camel reference property files with and without OSGI

I understand that if you deploy your Camel project to an OSGI environment like Karaf you can simply write:
<cm:property-placeholder id="INT001_********_Properties" persistent-id="INT001_SelfServiceMachine" />
<camelContext xmlns="http://camel.apache.org/schema/blueprint"
id="INT001_SelfServiceMachine" useMDCLogging="true">
<propertyPlaceholder id="properties" location="blueprint:INT001_*********_Properties"/>
And this works when the project is deployed to Karaf and the property file is located there in the etc folder.
But how can you configure it when Karaf is not available?
I used this bean before:
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:some.properties"
/> </bean>
But is there a single way to refer to property files regardless of when you are in Karaf or when you are in your e.g. Eclipse environment and your property file is in your /src/resources folder and the bean above works? For instance, when you use Jenkins and and want to run tests and build the bundle, you may not have Karaf available.
Thanks for any input on this.
You can maybe implement your own PropertiesResolver which know how to resolve your properties according to the runtime environment. If OSGi is detected, then it can use ConfigurationAdmin, else it can use a static properties file.
Personally, I use something more simple thanks to Spring DM: my beans/configurations are dispatched in multiples files, and all the configuration related to OSGi is regrouped in one file. In Karaf, Spring DM load all XML in META-INF/spring. Outside of Karaf, I filter the XML to exclude the OSGi configuration.
There is a blueprint noosgi bundle around, that one can be used to have the blueprint capabilities outside of the osgi container. With this you're able to stick to your blueprint xml, though you need to change from configuration admin service for property lookup to native blueprint property replacement.

Using blueprint as the Apache Camel DSL to describe routes in IBM Liberty

My goal is to get Camel running under IBM Liberty application server using OSGi and be able to describe the DSL (Domain Specific Language) routes in Blueprint. I am making progress and now have a Liberty environment with Camel installed and configured as OSGi bundles. When I write a Java DSL Camel app as an OSGi bundle, all works exactly as I might hope.
My last step is to be able to describe my camel routes in Blueprint. To that end I create a new OSGi bundle and defined a blueprint.xml that looks as follows:
<?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:camelBlueprint="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint-2.14.1.xsd">
<camelBlueprint:camelContext>
<camelBlueprint:route>
<camelBlueprint:from uri="file:c:/temp/in"/>
<camelBlueprint:to uri="file:c:/temp/out"/>
</camelBlueprint:route>
</camelBlueprint:camelContext>
</blueprint>
When I attempt to deploy this OSGi bundle, the IBM Liberty OSGi framework fails to deploy the application with the following errors:
[3/2/15 0:42:38:796 CST] 00000035 com.ibm.ws.app.manager.esa.internal.DeploySubsystemAction
A CWWKZ0403E: A management exception was generated when trying to install the application Camel1 into an OSGi framework. The error text from the OSGi framework is:
Resource does not exist: org.apache.aries.subsystem.core.archive.SubsystemContentRequirement:
namespace=osgi.identity, attributes={}, directives={filter=(&(osgi.identity=OSGITest1)(type=osgi.bundle)(version>=1.0.0))}, resource=org.apache.aries.subsystem.core.internal.SubsystemResource#7bc2d3bc
Unfortunately this is where I am now stumped and stuck. I believe that IBM Liberty uses Equinox as the OSGi platform and not Karaf but reading the Camel Blueprint docs I seem to understand that Apache Aries is required (which Liberty supplies and uses) and that Karaf isn't a dependency.
My MANIFEST.MF for my test bundle is:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OSGITest1
Bundle-SymbolicName: OSGITest1
Bundle-Version: 1.0.0.qualifier
Bundle-Blueprint: OSGI-INF/blueprint/*.xml
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: kolban.osgitest
Import-Package: org.apache.camel;version="2.14.1",
org.apache.camel.blueprint;version="2.14.1"
this message can occur if the resolver can't see the bundle, or there's something wrong with the bundle (typically with the Blueprint). If the bundle resolves ok when you remove the blueprint, then you need to look at what might be wrong in the blueprint. If this is the case, I would suspect you don't have the Camel blueprint namespace handler enabled in the runtime.
I hope this helps.
Regards, Graham.

how to create and export camelProxy with apache camel blueprint

I am using camel-blueprint with aries blueprint in osgi container. My configuration is as follows
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://camel.apache.org/schema/blueprint">
<c:camelContext>
<c:proxy id="myProxySender" serviceInterface="com.cmt.gabs.camel.test.MyInterface" serviceUrl="direct:a" />
<c:route>
<c:from uri="direct:a" />
<c:transform>
<c:simple>Hello ${body}</c:simple>
</c:transform>
<c:to uri="log:org.apache.camel.example?level=ERROR" />
</c:route>
</c:camelContext>
When i start the bundle it does not give any error, but the proxy is also not created as a service. Please tell me if i am doing any wrong.
I Want to use Camel Proxy for endpoint direct:a
edit
Camel version 2.11
OSGI container equinox 3.8
I had found the answer long ago but forgot to respond to it.
The answer is simple i just had to export it as a service.

Translation XML information to Java - Apache Camel

This is the example that is bundled with apache camel binaries
<route>
<!-- incoming requests from the servlet is routed -->
<from uri="servlet:///hello"/>
<choice>
<when>
<!-- is there a header with the key name? -->
<header>name</header>
<!-- yes so return back a message to the user -->
<transform>
<simple>Hello ${header.name} how are you?</simple>
</transform>
</when>
<otherwise>
<!-- if no name parameter then output a syntax to the user -->
<transform>
<constant>Add a name parameter to uri, eg ?name=foo</constant>
</transform>
</otherwise>
</choice>
</route>
How to translate this to Java
Am a beginner in camel, and some how came up to this
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder(){
public void configure(){
from("servlet://hello").transform().....
}
});
But dont know how to proceed further...
If you want to port it over to java without any XML (spring that is) you can't (easily) use the servlet component.
Just porting the route will be like:
from("servlet:///hello")
.choice()
.when()
.header("name")
.transform(simple("Hello ${header.name} how are you?"))
.otherwise()
.transform(constant("Add a name parameter to uri, eg ?name=foo"));
It should work in the spring example (or any spring web app), just replacing the <route> in the <CamelContext> with <routeBuilder ref="demoRoute"> given you have defined your route as a spring bean (<bean id="demoRoute" class="org.example.demo.DemoRoute">).
However, I guess you want to do this in plain java (no spring, no xml, no webapp). You could go with the Jetty component. The difference being that Camel then will start the servlet container, instead of the servlet container starting Camel. No difference for this simple example though.
I suggest you start out with a Maven archetype to get the skeleton up
e.g. mvn archetype:generate then choose org.apache.camel.archetypes:camel-archetype-java (Creates a new Camel project using Java DSL.)
Well, you don't need the maven archetype if you have your own java application and have the thread keep running. Then you should do fine with your approach. The maven archetype is however very good for training purposes.
You then need to add a dependency to Jetty (camel-jetty.jar) (read more here).
The actual route would be exactly the same except the first row: from("jetty:http://localhost:8080/camel/hello")
Nice and easy.
Try this one:
from("servlet://hello")
.choice()
.when(header("name").isNotNull()).transform(simple("Hello ${header.name} how are you?"))
.otherwise().transform(constant("Add a name parameter to uri, eg ?name=foo"));

Resources