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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to read OSGI run mode configurations with OSGI R6 annotation?

Avatar

Level 2

I am working on the migration of SCR annotation to OSGI R6 annotations. But I am not sure on how to progress with the OSGI run mode configuration migration using the new @component annotation provided by org.osgi.service.component.annotations. Any help would be appreciated.

8 Replies

Avatar

Level 2

Thanks Veena for your reply. I am trying to migrate something similar in this document. (https://helpx.adobe.com/experience-manager/using/osgi_config.html ). They are using SCR annotations in this. I am trying to do that using the OSGI R6 annotations.

Avatar

Level 2

Hi smacdonald2008,

Thanks for your reply but I am afraid these docs are not helping me. Earlier I read run mode configurations using

@Property(unbounded=PropertyUnbounded.DEFAULT, label="Standard Rates Service URL", description="URL to connect Standard Rates Service API")

and in the @Activate I apply the below code to read the property values.

protected void activate(Map<String, Object> properties)

  {

this.standardrateserviceurl = PropertiesUtil.toString(properties.get(STANDARD_SERVICE_URL), "default");

}

By using this I can create a node of type 'sling:OsgiConfig' with fully qualified class name under each run mode config folders. This would help me from manually changing the property files in each environment.

But I am not sure on how to do that using the OSGI R6 annotations.

I am trying to rewrite this one 'https://helpx.adobe.com/experience-manager/using/osgi_config.html'

Avatar

Community Advisor

Exactly same as before, but rely on the new OSGi annotations, annotations, @Activated and @Modified are still there.

Regards,

Peter

Avatar

Level 5

@ObjectClassDefinition(name = "Example Global Configs", description = "Example Global Configs")

public @interface ExampleGlobalConfig {

    @AttributeDefinition(name = "example.path", description = "This is example path")

    String getExamplePath() default "";

}

@Component(service = ExampleGlobalConfigService.class, immediate = true)

@Designate(ocd = ExampleGlobalConfig.class)

public class ExampleGlobalConfigService {

/**

* example path

*/

private String examplePath;

@Activate

@Modified

protected void activate(final ExampleGlobalConfig exampleGlobalConfig) {

examplePath = exampleGlobalConfig.getExamplePath();

}

/**

* @return the exampleath

        */

public String getExamplePath() {

return examplePath;

}

}


May be you can do something like this. You can use the service in servlets or sling models or wcmusepojo or anywhere else you need

Avatar

Level 2

Thanks susheel for your reply but I am trying to rewrite this one 'I am trying to rewrite this one 'https://helpx.adobe.com/experience-manager/using/osgi_config.html'. Unfortunately these code examples are not helping me.

Avatar

Level 2

Thanks all for your help. I got it resolved. What I did was that I created a new component without specifying the name attribute. Then created OSGI config nodes under different run modes. Then in the activate method with parameter of type Map simply called the property field name.