That works fine if config admin is defined within pojosr unit test class
configAdmin = getOsgiService(ConfigurationAdmin.class);
assertNotNull(configAdmin);
Configuration config =
configAdmin.createFactoryConfiguration("encrypt.config");
Dictionary props = new Properties();
// Encrypt a key/value
// bar is encrypted and link to foo key
encryptedValue = enc.encrypt("bar");
props.put("foo", encryptedValue);
config.setBundleLocation(null);
config.update(props);
On Thu, Dec 20, 2012 at 9:52 AM, Charles Moulliard <[email protected]> wrote:
> Hi Jean-Baptiste,
>
> Until now I have only created a PoJoSr unit test to validate that we could
> also use jaas/jasypt with config admin and property placeholder.
> I'm able to retrieve the ConfigurationAdmin object from the bundleContext
> but next when I use the following syntax the object is null even
>
> ServiceReference serviceReference =
> bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
>
> if (serviceReference != null) {
> configAdmin = (ConfigurationAdmin)
> bundleContext.getService(serviceReference);
> }
>
> Configuration[] configs = configAdmin.listConfigurations(null); //
> NULL NULL ? Is it because there is something to do with POJOSR for
> blueprint file
>
> for (Configuration config : configs) {
> System.out.println(">> Config pid : " + config.getPid());
> Map<String, Object> dict = (Map<String, Object>)
> config.getProperties();
> for (Map.Entry<String, Object> e : dict.entrySet()) {
> System.out.println(e.getKey() + ": " + e.getValue());
> }
>
> }
>
> Regards,
>
> Charles
>
>
> On Wed, Dec 19, 2012 at 7:23 PM, Jean-Baptiste Onofré
> <[email protected]>wrote:
>
>> Hi Charles,
>>
>> 1/ the pid is not correct: it's the OSGi one, not the Felix one that you
>> have to get
>>
>> 2/ you have a service with the ID, not a service.pid
>>
>> 3/ Why don't you get the ConfigAdmin service using Blueprint:
>>
>> <reference id="configurationAdmin" interface="org.osgi.service.**
>> cm.ConfigurationAdmin"/>
>>
>> and after inject in your bean
>>
>> <property name="configAdmin" ref="configurationAdmin"/>
>>
>> 4/ You can get the ConfigAdmin service programmaticaly using
>> bundleContext.**getServiceReferences(null, filter).
>>
>> Anyway, the "encoded" approach doesn't look good to me.
>>
>> What you want to achieve exactly ?
>>
>> By the way, I created a Jira to have something more generic: a
>> ConfigAdmin interceptor/adapter that check if the value contains {CRYPT} as
>> prefix/suffix and unencode it in that case.
>>
>> Regards
>> JB
>>
>>
>> On 12/19/2012 05:32 PM, Charles Moulliard wrote:
>>
>>> Hi,
>>>
>>> Using PoJoSr and extending the example that we have as unit test for
>>> jaas/jasypt, I try to retrieve a OSGI Config Admin service registered
>>> using blueprint under the key encryptConfig
>>>
>>> <cm:property-placeholder persistent-id="encryptConfig"
>>> update-strategy="reload" >
>>> <cm:default-properties>
>>> <cm:property name="encoded" value="ENC(${foo})"/>
>>> </cm:default-properties>
>>> </cm:property-placeholder>
>>>
>>> Java code
>>>
>>> ConfigurationAdmin configAdmin =
>>> getOsgiService(**ConfigurationAdmin.class,
>>> "(service.pid=org.apache.**felix.cm.ConfigurationAdmin)")**; // THERE
>>> IS AN
>>> OBJECT IN DEBUG MODE
>>> Configuration[] configs =
>>> configAdmin.**listConfigurations("(service.**pid=encryptConfig)");
>>>
>>>
>>> When I execute the following code, the Configuration[] object is null
>>> Can someone tell me what is wrong in my code ?
>>>
>>> Regards,
>>>
>>> --
>>> Charles Moulliard
>>> Apache Committer / Sr. Enterprise Architect (RedHat)
>>> Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com
>>>
>>>
>> --
>> Jean-Baptiste Onofré
>> [email protected]
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>
>
>
> --
> Charles Moulliard
> Apache Committer / Sr. Enterprise Architect (RedHat)
> Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com
>
>
--
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com