You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by gnanda1 <gi...@hotmail.com> on 2010/06/29 01:23:57 UTC

reading config properties to a hashtable

Hi all,
I am using servicemix 4.2. I have a config file under etc directory. 
I load that config file in xbean.xml file as follows

<osgix:cm-properties id="cmProps" persistent-id="com.pf.namereolver">
 
</osgix:cm-properties>

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

    <bean:endpoint service="ns:bean" endpoint="endpoint"
                   bean="#resolverBean"/>
          <bean id="resolverBean" class="com.pf.resolver.NameResolver">
         <property name="testkey" value="${testname}" />        </bean>
                   
                   
    <!-- use this special class to register the endpoints with the NMR -->
    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" />

the config file name is com.pf.nameresolver.cfg
I need to load the properties from this config file to my java class file
(com.pf.resolver.Nameresolver) as a Hashtable, so that I could access value
of any of my keys decalred in my config file by passing the key name  to a
method defined in the java class as follows


public String resolveName(String name){
				
		log.info("input name is:"+name);
		String URL = this.nameMap.get(name);
		return  URL;
		
			}

How would I load the properties defined in the config file into the
hashtable field in my java class file?
Any help is appreciated.
Thank you



-- 
View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p511758.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: reading config properties to a hashtable

Posted by gnanda1 <gi...@hotmail.com>.
Please check the below link

http://servicemix.396122.n5.nabble.com/How-do-I-read-the-property-values-from-ConfigurationAdmin-for-a-PID-from-camel-code-td512223.html#a512613

In my xbean.xml file, I  have following lines

<osgi:reference id="configAdmin"
		interface="org.osgi.service.cm.ConfigurationAdmin" />

<bean id="processor" class="com.pf.management.mbean.CommandProcessor">
		
		<property name="configAdmin" ref="configAdmin" />
			</bean>

And in CommandProcessor java class , I have a setmethod corresponding to
"configAdmin" property
public void setConfigAdmin(ConfigurationAdmin configAdmin) {
		this.configAdmin = configAdmin;
	}
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p2740243.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: reading config properties to a hashtable

Posted by buzzvamsi <va...@gmail.com>.
Could you give me that Gert suggestion link please. I am unable to configure
this. I get BundleContext property required exception.

Any help please
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p2740152.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: reading config properties to a hashtable

Posted by gnanda1 <gi...@hotmail.com>.
Thanks Freeman. I did as Gert suggested in another thread and it worked.


-- 
View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p1045212.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: reading config properties to a hashtable

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

As Gert point out in another thread,

The easiest way to do that would be by creating the bean in the
Spring file where you defined your <camelContext>, leveraging Spring  
DM to
access either the ConfigurationAdmin (and inject that into your bean
afterwards) ...

<reference id="configAdmin"
interface="org.osgi.service.cm.ConfigurationAdmin"/>


Freeman
On 2010-7-7, at 上午4:31, gnanda1 wrote:

>
> Hi Freeman,
> I am still trying to figure out how to get a reference to  
> bundlecontext or
> configurationAdmin from my SU component to read/update properties  
> file.
>
> Is there any interface that I could implement to get a refrence to the
> bundlecontext  or somehow I could inject bundleconext or  
> configuartionAdmin
> thru camel-context.xml file?
>
> currently I do not have any osgi bundle , I do have only SAs  
> deployed in
> smx.
> Please suggest
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p946343.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


-- 
Freeman Fang

------------------------
Open Source SOA: http://fusesource.com
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org


Re: reading config properties to a hashtable

Posted by gnanda1 <gi...@hotmail.com>.
Hi Freeman,
I am still trying to figure out how to get a reference to bundlecontext or
configurationAdmin from my SU component to read/update properties file.

Is there any interface that I could implement to get a refrence to the
bundlecontext  or somehow I could inject bundleconext or configuartionAdmin
thru camel-context.xml file?

currently I do not have any osgi bundle , I do have only SAs deployed in
smx.
Please suggest
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p946343.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: reading config properties to a hashtable

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

I guess you miss my previous answer, you needn't and shouldn't use  
ConfigCommandSupport.
I just show you that class to demonstrate how to use  
ConfigurationAdmin service.

Freeman
On 2010-7-1, at 下午12:02, gnanda1 wrote:

>
> Hi Freeman,
>
> what dependency I have to add in my pom to get access to
> ConfigCommandSupport?
>
> Would you suggest using any other class to get a reference to the
> ConfigurationAdmin ? In my scenario could I just use  
> ConfigCommandSupport
> class in both the side (building Dictionary and consumer class  
> accessing the
> dictionary to retrieve data).
>
> Thanks & Regards
> Gnanda
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p512269.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


-- 
Freeman Fang
------------------------
Open Source SOA: http://fusesource.com


Re: reading config properties to a hashtable

Posted by gnanda1 <gi...@hotmail.com>.
Hi Freeman,

what dependency I have to add in my pom to get access to
ConfigCommandSupport?

Would you suggest using any other class to get a reference to the
ConfigurationAdmin ? In my scenario could I just use ConfigCommandSupport
class in both the side (building Dictionary and consumer class accessing the
dictionary to retrieve data). 

Thanks & Regards
Gnanda
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p512269.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: reading config properties to a hashtable

Posted by Freeman Fang <fr...@gmail.com>.
resend it
On 2010-6-30, at 上午11:34, Freeman Fang wrote:

> Hi,
>
> My comment inline
> On 2010-6-30, at 上午2:12, gnanda1 wrote:
>
>>
>>
>> Hi Freeman,
>> Thanks for the reply. I am new to this and not sure if I got it  
>> yet. A little more detailed instruction will be very helpful to me
>> I looked into both the links.
>> The questions that I have here are
>>
>> Do I need to write a java class extending ConfigCommandSupport and  
>> override doExecute(ConfigurationAdmin admin) method?
> No, you needn't.
> I give those two links just let you know how to get  
> ConfigurationAdmin services in bundles and how to use  
> ConfigurationAdmin services to retrieve properties
>
>> In the doExecute method, I guess I need to build my Dictionary  
>> object (either by reading from a config file or building my own  
>> properties or doing both)
>> org.osgi.service.cm.Configuration conf = admin.getConfiguration("my- 
>> persistent-id", null);
>> //my-persisten-id.cfg could be a file in cfg directory??
> should be in $SMX_HOME/etc folder
>>        Dictionary<Object, Object> props = conf.getProperties();
>>        if (props == null) {
>>            props = new Properties();
>>        }
>>
>>
>>        props.put("my-business-resource1", "my-URL1"); //adding more  
>> properties
>>        props.put("my-business-resource2", "my-URL2");
>>        conf.update(props);
>> Is that right?
> Yeah, I think so, you can also retrieve properties from your my- 
> persisten-id.cfg file.
>>
>> 3.       How would I deploy this java class in Karaf? Do I need to  
>> create an OSGI bundle with servicemix-bean endpoint?
> As ConfigAdmin service is OSGi concept and has nothing to do with  
> JBI/servicemix, so you can simply add those code piece in your  
> bundle, any bundle is ok, not only the one use servicemix-bean  
> endpoint.
>> 4.       After I deploy it to Karaf somehow, how would I refer it  
>> in my other bundle to access this Dictionary object?
>>
> In other bundles you can also use ConfigAdmin service to retrieve  
> properties you previously saved.
>
> Hope this helps
>
> Freeman
>>
>> Thanks & Regards
>>
>> GNanda
>>
>>
>>


-- 
Freeman Fang
------------------------
Open Source SOA: http://fusesource.com


RE: reading config properties to a hashtable

Posted by gnanda1 <gi...@hotmail.com>.

 Hi Freeman,
Thanks for the reply. I am new to this and not sure if I got it yet. A little more detailed instruction will be very helpful to me
I looked into both the links.
The questions that I have here are

Do I need to write a java class extending ConfigCommandSupport and override doExecute(ConfigurationAdmin admin) method?
In the doExecute method, I guess I need to build my Dictionary object (either by reading from a config file or building my own properties or doing both)
org.osgi.service.cm.Configuration conf = admin.getConfiguration("my-persistent-id", null); 
//my-persisten-id.cfg could be a file in cfg directory??
        Dictionary<Object, Object> props = conf.getProperties(); 
        if (props == null) { 
            props = new Properties(); 
        } 

        
        props.put("my-business-resource1", "my-URL1"); //adding more properties
        props.put("my-business-resource2", "my-URL2"); 
        conf.update(props);
Is that right?
 
3.       How would I deploy this java class in Karaf? Do I need to create an OSGI bundle with servicemix-bean endpoint?
4.       After I deploy it to Karaf somehow, how would I refer it in my other bundle to access this Dictionary object?  
 

Thanks & Regards

GNanda


 


Date: Mon, 28 Jun 2010 19:30:37 -0700
From: ml-node+511778-1229574568-36531@n5.nabble.com
To: gitanjali1_nanda@hotmail.com
Subject: Re: reading config properties to a hashtable

Hi, 

For your case, IMHO the best practice in OSGi container to read   
configuration properties is leverage OSGi ConfigurationAdmin services. 
Actually smx4.2 has a config:list command from console which can list   
all configuration files and its properties. You need take a look at   
this[1] to get idea how it works. 
And here [2] shows how to get ConfigurationAdmin service. 

[1]https://svn.apache.org/repos/asf/karaf/trunk/shell/config/src/main/java/org/apache/felix/karaf/shell/config/ListCommand.java
[2]https://svn.apache.org/repos/asf/karaf/trunk/shell/config/src/main/java/org/apache/felix/karaf/shell/config/ConfigCommandSupport.java

Freeman 
On 2010-6-29, at 上午7:23, gnanda1 wrote: 


> 
> Hi all, 
> I am using servicemix 4.2. I have a config file under etc directory. 
> I load that config file in xbean.xml file as follows 
> 
> <osgix:cm-properties id="cmProps" persistent-id="com.pf.namereolver"> 
> 
> </osgix:cm-properties> 
> 
> <context:property-placeholder properties-ref="cmProps" /> 
> 
>    <bean:endpoint service="ns:bean" endpoint="endpoint" 
>                   bean="#resolverBean"/> 
>          <bean id="resolverBean" class="com.pf.resolver.NameResolver"> 
>         <property name="testkey" value="${testname}" />        </bean> 
> 
> 
>    <!-- use this special class to register the endpoints with the   
> NMR --> 
>    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" /> 
> 
> the config file name is com.pf.nameresolver.cfg 
> I need to load the properties from this config file to my java class   
> file 
> (com.pf.resolver.Nameresolver) as a Hashtable, so that I could   
> access value 
> of any of my keys decalred in my config file by passing the key   
> name  to a 
> method defined in the java class as follows 
> 
> 
> public String resolveName(String name){ 
> 
> log.info("input name is:"+name); 
> String URL = this.nameMap.get(name); 
> return  URL; 
> 
> } 
> 
> How would I load the properties defined in the config file into the 
> hashtable field in my java class file? 
> Any help is appreciated. 
> Thank you 
> 
> 
> 
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p511758.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com. 

-- 
Freeman Fang 
------------------------ 
Open Source SOA: http://fusesource.com






View message @ http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p511778.html 
To unsubscribe from reading config properties to a hashtable, click here. 
 		 	   		  
_________________________________________________________________
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. 
http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p511921.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: reading config properties to a hashtable

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

For your case, IMHO the best practice in OSGi container to read  
configuration properties is leverage OSGi ConfigurationAdmin services.
Actually smx4.2 has a config:list command from console which can list  
all configuration files and its properties. You need take a look at  
this[1] to get idea how it works.
And here [2] shows how to get ConfigurationAdmin service.

[1]https://svn.apache.org/repos/asf/karaf/trunk/shell/config/src/main/java/org/apache/felix/karaf/shell/config/ListCommand.java
[2]https://svn.apache.org/repos/asf/karaf/trunk/shell/config/src/main/java/org/apache/felix/karaf/shell/config/ConfigCommandSupport.java

Freeman
On 2010-6-29, at 上午7:23, gnanda1 wrote:

>
> Hi all,
> I am using servicemix 4.2. I have a config file under etc directory.
> I load that config file in xbean.xml file as follows
>
> <osgix:cm-properties id="cmProps" persistent-id="com.pf.namereolver">
>
> </osgix:cm-properties>
>
> <context:property-placeholder properties-ref="cmProps" />
>
>    <bean:endpoint service="ns:bean" endpoint="endpoint"
>                   bean="#resolverBean"/>
>          <bean id="resolverBean" class="com.pf.resolver.NameResolver">
>         <property name="testkey" value="${testname}" />        </bean>
>
>
>    <!-- use this special class to register the endpoints with the  
> NMR -->
>    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" />
>
> the config file name is com.pf.nameresolver.cfg
> I need to load the properties from this config file to my java class  
> file
> (com.pf.resolver.Nameresolver) as a Hashtable, so that I could  
> access value
> of any of my keys decalred in my config file by passing the key  
> name  to a
> method defined in the java class as follows
>
>
> public String resolveName(String name){
> 				
> 		log.info("input name is:"+name);
> 		String URL = this.nameMap.get(name);
> 		return  URL;
> 		
> 			}
>
> How would I load the properties defined in the config file into the
> hashtable field in my java class file?
> Any help is appreciated.
> Thank you
>
>
>
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/reading-config-properties-to-a-hashtable-tp511758p511758.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


-- 
Freeman Fang
------------------------
Open Source SOA: http://fusesource.com