This section explains how to modify an existing Maven project for a Fuse Mediation Router application, so that the project generates an OSGi bundle suitable for deployment in the Fuse ESB OSGi container. To convert the Maven project, you need to modify the project POM file.
To configure a Maven POM file to generate a bundle, there are essentially two
changes you need to make: change the POM's package type to bundle
; and
add the Maven bundle plug-in to your POM. For details, see Modifying an Existing Maven Project.
There are two kinds of file that you can use to configure your project:
Spring configuration—in the standard Maven directory layout, Spring XML configuration files are located under
.ProjectDir
/src/main/resources/META-INF/springBlueprint configuration—in the standard Maven directory layout, blueprint XML configuration files are located under
.ProjectDir
/src/main/resources/OSGI-INF/blueprint
If you decide to use the blueprint configuration, you can embed
camelContext
elements in the blueprint file, as described in Blueprint configuration file.
If you decide to configure your Fuse Mediation Router application using blueprint, you must
ensure that the camel-blueprint
feature is installed (it is not
installed by default). If necessary, install it by entering the following console
command:
karaf@root> features:install camel-blueprint
The OSGi Configuration Admin service defines a mechanism for passing configuration settings to an OSGi bundle. You do not have to use this service for configuration, but it is typically the most convenient way of configuring bundle applications. Spring DM provides support for OSGi configuration, enabling you to substitute variables in a Spring XML file using values obtained from the OSGi Configuration Admin service.
Example 7.1 shows how to pass the value
of the prefix
variable to the constructor of the
MyTransform
bean, where the value of prefix
can be set
by the OSGi Configuration Admin service:
Example 7.1. Using OSGi Configuration Properties in Spring XML
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ctx="http://www.springframework.org/schema/context" xmlns:osgi="http://camel.apache.org/schema/osgi" xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" ... > ... <bean id="myTransform" class="org.fusesource.example.MyTransform"> <property name="prefix" value="${prefix}"/> </bean> <osgix:cm-properties id="preProps" persistent-id="org.fusesource.example"> <prop key="prefix">MyTransform</prop> </osgix:cm-properties> <ctx:property-placeholder properties-ref="preProps" /> </beans>
The syntax, ${prefix}
, substitutes the value of the
prefix
variable into the Spring XML file. The OSGi properties are
set up using the following XML elements:
osgix:cm-properties
To integrate Spring properties with the properties from the OSGi Configuration Admin service, insert an
osgix:cm-properties
element into the Spring XML file. This element creates a bean that gets injected with all of the properties from the OSGiManagedService
instance that is identified by thepersistent-id
attribute. The minimal configuration consists of an emptyosgix:cm-properties
element that sets thepersistent-id
attribute and theid
attribute—for example:<osgix:cm-properties id="preProps" persistent-id="org.fusesource.example"/>
For an example of how the persistent ID relates to OSGi configuration settings, see the example in Add OSGi configurations to the feature.
If you want to define defaults for some of the properties in the Spring XML file, add
prop
elements as children of theosgix:cm-properties
element, as shown in Example 7.1.ctx:property-placeholder
Property placeholder is a Spring mechanism that enables you to use the syntax,
${
, to substitute variables in a Spring XML file. By defining aPropName
}ctx:property-placeholder
element with a reference to thepreProps
bean (as in Example 7.1), you enable the property placeholder mechanism to substitute any of the variables from thepreProps
bean (which encapsulates the OSGi configuration properties) into the Spring XML file.