Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Read config nodes inside a non service class

Avatar

Avatar
Give Back 5
Level 3
minisanu
Level 3

Likes

9 likes

Total Posts

43 posts

Correct Reply

2 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 5
Ignite 3
View profile

Avatar
Give Back 5
Level 3
minisanu
Level 3

Likes

9 likes

Total Posts

43 posts

Correct Reply

2 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 5
Ignite 3
View profile
minisanu
Level 3

13-09-2017

How to read config nodes inside a non service class.

I have a configuration created in felix console. I want to read that property in one of my helper class.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 5
Level 3
minisanu
Level 3

Likes

9 likes

Total Posts

43 posts

Correct Reply

2 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 5
Ignite 3
View profile

Avatar
Give Back 5
Level 3
minisanu
Level 3

Likes

9 likes

Total Posts

43 posts

Correct Reply

2 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 5
Ignite 3
View profile
minisanu
Level 3

08-10-2017

Thanks Everyone...Sorry for the delayed reply..I lost track of my password and got it reset again. I have created a configAdmin and it is working fine

Answers (4)

Answers (4)

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,081 likes

Total Posts

3,121 posts

Correct Reply

1,061 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,081 likes

Total Posts

3,121 posts

Correct Reply

1,061 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

13-09-2017

Do not use the ConfigAdmin directly, I would consider this an Antipattern. A service/component should only read its own properties, but not read the property of other services, these are typically implementation details. If you really need to know something about other services, extend their interface and provide the information via the public API of this service. Then the compiler can support you to write robust code.

Jörg

Avatar

Avatar
Validate 25
MVP
Ratna_Kumar
MVP

Likes

158 likes

Total Posts

755 posts

Correct Reply

134 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile

Avatar
Validate 25
MVP
Ratna_Kumar
MVP

Likes

158 likes

Total Posts

755 posts

Correct Reply

134 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile
Ratna_Kumar
MVP

13-09-2017

Hi,

I agree with Scott!! You should look into the article mentioned

//Adobe Experience Manager Help | Reading Adobe Experience Manager OSGi Configuration Values

~Ratna

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

13-09-2017

We have an article that shows you how to read node values -- Scott's Digital Community: Reading AEM OSGi Configuration Values

Avatar

Avatar
Validate 1
Level 5
viveksachdeva
Level 5

Likes

52 likes

Total Posts

225 posts

Correct Reply

35 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 5
viveksachdeva
Level 5

Likes

52 likes

Total Posts

225 posts

Correct Reply

35 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
viveksachdeva
Level 5

13-09-2017

To read values of config, you need to get reference of ConfigurationAdmin which is only possible if your class is an OSGi component. If there is a helper class where you want to read such properties, you need to pass ConfigurationAdmin object to that method and then read the properties.

Something like:

String fetchConfigValue(ConfigurationAdmin cfgAdmin, String pid, String key){

....

}