4 Replies Latest reply on Aug 10, 2017 1:09 AM by cpandey

    How to access OSGi Properties in Camel Custom Component

    jaisha57

      Created camel custom component, need to access properties value in the producer endpoint.

      Please help me how to achieve this on Jboss Fuse 6.3 Fabric container.

        • 1. Re: How to access OSGi Properties in Camel Custom Component
          cpandey

          I might not have understood your problem correctly, but is link[1] and [2] an answer to your query ?

           

          [1]Apache Camel: Using PropertyPlaceholder

          [2]Apache Camel: Using PropertyPlaceholder

          • 2. Re: How to access OSGi Properties in Camel Custom Component
            jaisha57

            I have developed camel custom component - producer endpoint
            public class LogManagerProducer extends DefaultProducer {

            private LogManagerEndPoint endpoint;

             

             

            public LogManagerProducer(LogManagerEndPoint endpoint) {

            super(endpoint);

            this.endpoint = endpoint;

            }

            public void process(Exchange exchange) throws Exception {

            // here I need to access fabric profile properties

            }

            }

             

            I did couple of experiments and find details below:

            bean.xml

            <context:property-placeholder properties-ref="props"/>

                <osgix:cm-properties id="props" persistent-id="logmanager" />

                

                <bean id="configuration" class="qa.com.cbq.json.model.ConfigModel" >

                    <property name="ipAddress" value="${ip.address}"/>

                    <property name="port" value="${port}"/>   

                </bean>

            when deployed configuration are loaded as needed but how can I access these values, for this issue

            java code

            ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"bean.xml"});

            ConfigModel config =  (ConfigModel) context.getBean("configuration");

             

            bean.xml not able to load when the method is invoked.

            IOException parsing XML document from class path resource [bean.xml]

             

            After this exception, placed in resource folder but still getting the same issue

             

            Ultimately, I need to access osgi properties/ fabric profile properties in the java class.

            Please help me fix this issue.

            • 3. Re: How to access OSGi Properties in Camel Custom Component
              jaisha57

              Hi All,

               

              I found work around, by just declaring as static variable ipAddress & port. When bundle is deployed in the container, these variable will be initialized.

              <bean id="configuration" class="qa.com.cbq.json.model.ConfigModel" init-method="initializeConfigValues" >

                      <property name="ipAddress" value="${ip.address}"/>

                      <property name="port" value="${port}"/>  

              </bean>

               

              At the same time, I do not know this is the appropriate way to fix this issue, however, it solves my purpose.
              If anyone finds correct solution, please comment below.

               

              Regards,

              Jayashankar C

              • 4. Re: How to access OSGi Properties in Camel Custom Component
                cpandey

                Hi, Good to know it worked for you. Also using BundleActivator you might have initialized the variables. AFAIK BundleActivator initializes variables even before the beans in spring/blueprint based context.xml.

                 

                fuse-examples-6.2/ActivateTest.java at master · 1984shekhar/fuse-examples-6.2 · GitHub

                fuse-examples-6.2/pom.xml at master · 1984shekhar/fuse-examples-6.2 · GitHub