Expand my Community achievements bar.

SOLVED

Using Same OSGI Service at Multiple Times

Avatar

Community Advisor

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?

1 Accepted Solution

Avatar

Correct answer by
Level 8
@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)); } }

View solution in original post

13 Replies

Avatar

Level 10

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.

Avatar

Community Advisor

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?

Avatar

Level 10

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?

Avatar

Community Advisor

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.

Avatar

Level 8

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.

Avatar

Level 3

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.

Avatar

Community Advisor

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

  1. @Property(label = "Multi Property", unbounded = PropertyUnbounded.ARRAY, propertyPrivate = false, description = "A property that allows multiple values")
  2. 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?

Avatar

Level 8

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

Avatar

Community Advisor

leeasling wrote...

Yes you can.  Your service needs to be a component factory.  See below.

  1. @Component(metatype = true, label = "Configuration Factory", description = "Configuration Factory",
  2. configurationFactory = true)
  3. @Service

 

 

Thanks. Do you have any example?

Avatar

Correct answer by
Level 8
@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)); } }

Avatar

Level 6

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

  1. @Property(label = "Multi Property", unbounded = PropertyUnbounded.ARRAY, propertyPrivate = false, description = "A property that allows multiple values")
  2. 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?

Avatar

Level 10

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

Avatar

Administrator

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



Kautuk Sahni