Highlighted

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

adarshm65812616

28-12-2017

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.

Replies

Highlighted

adarshm65812616

29-12-2017

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.

Highlighted

susheel

29-12-2017

@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

Highlighted
Highlighted

adarshm65812616

31-12-2017

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'

Highlighted

PuzanovsP

MVP

01-01-2018

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

Regards,

Peter

Highlighted

adarshm65812616

02-01-2018

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.