I want to use the same OSGI service to read config values from run modes instead of developing multiple OSGI services. For example, we can click on "+" button to configure multiple DB's in felix console. Is there a way in AEM to do that?
Solved! Go to Solution.
Views
Replies
Total Likes
@Component(metatype = true, label = "Configuration Factory", description = "Configuration Factory", configurationFactory = true) @Service public class TestConfigurationFactory { @Property(label = "Property 1", propertyPrivate = false, description = "Property 1") private static final String PROPERTY_1 = "property.one"; @Property(label = "Property 2", propertyPrivate = false, description = "Property 2") private static final String PROPERTY_2 = "property.two"; private String property1; private String property2; @Activate protected void activate(ComponentContext context) throws RepositoryException { this.property1 = PropertiesUtil.toStringArray(context.getProperties().get(PROPERTY_1)); this.property2 = PropertiesUtil.toStringArray(context.getProperties().get(PROPERTY_2)); } }
Views
Replies
Total Likes
AEM lets you write OSGi bundles that read Config values https://helpx.adobe.com/experience-manager/using/osgi_config.html. You can develop the code to perform different tasks based on config values read at run time.
Views
Replies
Total Likes
smacdonald2008 wrote...
AEM lets you write OSGi bundles that read Config values https://helpx.adobe.com/experience-manager/using/osgi_config.html. You can develop the code to perform different tasks based on config values read at run time.
Thanks Scott. This is not what I am looking for. Currently I have a OSGI service which I read some configuration values. Authors will go to configuration manager to author those values. For example, authors will come and configure the API headers.
I have a similar requirement but I have to configure the different API headers and also want to keep the old API headers. Instead of developing a new service, can I use this existing OSGI service?
Views
Replies
Total Likes
API headers. I am not sure what you mean by this term . Do you mean a page header that is part of a web page?
Views
Replies
Total Likes
smacdonald2008 wrote...
API headers. I am not sure what you mean by this term . Do you mean a page header that is part of a web page?
Sorry for the confusion. Here is what I want to do. Authors want to configure below values in the felix console for one requirement.
endPointUrl
contentType
For the other requirement, they want to configure the same values. So instead of writing a new OSGI service, can I use the existing service to configure these values multiple times by giving a specific name to each configuration?
For example, we can give a specific name to a DB configuration in felix console and we can configure as many databases as we want. In the similar way, can we configure my OSGI service? So whenever we want, we will just click on "+" symbol and configure those values.
Views
Replies
Total Likes
I'm a little lost as to what exactly you're looking for, but you cannot have an array OSGI configuration property with multiple fields. You can implement an array of properties by using the property definition like this
@Property(label = "Multi Property", unbounded = PropertyUnbounded.ARRAY, propertyPrivate = false, description = "A property that allows multiple values") private static final String RECIPIENT_PROPERTY = "property.multiple";
If you want to have multiple values for a single item then consider using a semi-colon or a pipe delimiter, then when you read the configuration you can separate the values.
The other concerning thing is that you mention authors authoring these values in the felix console. Nobody other than the administrator should have access to the felix console. I would consider a different method of managing these values.
Views
Replies
Total Likes
I think an Osgi configuration factory is what you are likely looking for. Here is a good reference on how to create those https://cqdump.wordpress.com/2014/08/05/managing-multiple-instances-of-services-osgi-service-factori...
And you should not give authors access to your Felix console. Admins should be doing that.
Views
Replies
Total Likes
leeasling wrote...
I'm a little lost as to what exactly you're looking for, but you cannot have an array OSGI configuration property with multiple fields. You can implement an array of properties by using the property definition like this
@Property(label = "Multi Property", unbounded = PropertyUnbounded.ARRAY, propertyPrivate = false, description = "A property that allows multiple values")
private static final String RECIPIENT_PROPERTY = "property.multiple";
If you want to have multiple values for a single item then consider using a semi-colon or a pipe delimiter, then when you read the configuration you can separate the values.
The other concerning thing is that you mention authors authoring these values in the felix console. Nobody other than the administrator should have access to the felix console. I would consider a different method of managing these values.
Okay. In a simple words, we can add multiple factory configurations to configure multiple databases in Felix console (Please see attached screen shot). In the same way, can I configure my OSGI service to configure multiple factory configurations?
Views
Replies
Total Likes
Yes you can. Your service needs to be a component factory. See below.
@Component(metatype = true, label = "Configuration Factory", description = "Configuration Factory", configurationFactory = true) @Service
Views
Replies
Total Likes
leeasling wrote...
Yes you can. Your service needs to be a component factory. See below.
@Component(metatype = true, label = "Configuration Factory", description = "Configuration Factory",
configurationFactory = true)
@Service
Thanks. Do you have any example?
Views
Replies
Total Likes
@Component(metatype = true, label = "Configuration Factory", description = "Configuration Factory", configurationFactory = true) @Service public class TestConfigurationFactory { @Property(label = "Property 1", propertyPrivate = false, description = "Property 1") private static final String PROPERTY_1 = "property.one"; @Property(label = "Property 2", propertyPrivate = false, description = "Property 2") private static final String PROPERTY_2 = "property.two"; private String property1; private String property2; @Activate protected void activate(ComponentContext context) throws RepositoryException { this.property1 = PropertiesUtil.toStringArray(context.getProperties().get(PROPERTY_1)); this.property2 = PropertiesUtil.toStringArray(context.getProperties().get(PROPERTY_2)); } }
Views
Replies
Total Likes
noksc wrote...
leeasling wrote...
I'm a little lost as to what exactly you're looking for, but you cannot have an array OSGI configuration property with multiple fields. You can implement an array of properties by using the property definition like this
@Property(label = "Multi Property", unbounded = PropertyUnbounded.ARRAY, propertyPrivate = false, description = "A property that allows multiple values")
private static final String RECIPIENT_PROPERTY = "property.multiple";
If you want to have multiple values for a single item then consider using a semi-colon or a pipe delimiter, then when you read the configuration you can separate the values.
The other concerning thing is that you mention authors authoring these values in the felix console. Nobody other than the administrator should have access to the felix console. I would consider a different method of managing these values.
Okay. In a simple words, we can add multiple factory configurations to configure multiple databases in Felix console (Please see attached screen shot). In the same way, can I configure my OSGI service to configure multiple factory configurations?
Do you want that property as editable each time. is that what you are looking for?
Views
Replies
Total Likes
Take a look at these two well explained articles on osgi config and how you read them
OSGi Configuration Management: http://adobeaemclub.com/osgi-configuration-management-aem/
Reading OSGi Configuration properties: http://adobeaemclub.com/reading-osgi-configuration-properties/
Thanks
Views
Replies
Total Likes
Hi
Hi
Please have a look at this community article:-
Link:- http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html
//You want to create configuration which can be edited at run time using OSGI console.
Another reference link:- http://www.tothenew.com/blog/creating-osgi-factory-configurations-in-aem/
I hope this is what exactly your are trying to achieve.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes