Extending AbstractSocialComponentFactory for AEM 6.5 with R6 annotations | Community
Skip to main content
Shubham_borole
Community Advisor
Community Advisor
April 30, 2021
Solved

Extending AbstractSocialComponentFactory for AEM 6.5 with R6 annotations

  • April 30, 2021
  • 2 replies
  • 1511 views

Hello All,

As part of upgrade from AEM 6.2 to AEM 6.5, I am looking to find a correct way to extend the 

AbstractSocialComponentFactory 
This is an example - https://github.com/Adobe-Marketing-Cloud/aem-scf-sample-components-extension/blob/master/bundles/aem-scf-extensions/src/main/java/com/adobe/aem/scf/extensions/IdeaSocialComponentFactory.java similar to which we have our custom implementation working for AEM 6.2. We are also using org.apache.felix.scr.annotations.Component; annotations in 6.2
 
However which updating the code to 6.5 I am looking to update the annotations as per https://docs.osgi.org/javadoc/r6/cmpn/org/osgi/service/component/annotations/Component.html#factory()
 
I have tried 
@Component(name = "Custom Community Component Factory", factory = "com.path.to..CustomCommunityComponentFactory", service = SocialComponentFactory.class, configurationPolicy = ConfigurationPolicy.OPTIONAL)
&
@Component(name = "Custom Community Component Factory", factory = "com.path.to..CustomCommunityComponentFactory")
and other combinations. But still the class never gets called. The bundle is active and the service class is active too (/system/console/components)

I see that the current custom factory is not registered as SocialComponentFactory but rather as ComponentFactory
 
Eg:
Desired:  [Custom COmmunity Component Factory,21308, [com.adobe.cq.social.scf.SocialComponentFactory]] ServiceEvent REGISTERED
Actual :   [Custom COmmunity Component Factory,21308, [org.osgi.service.component.ComponentFactory]] ServiceEvent REGISTERED 
 Below is the sample code that I am using.

 

 

package path.to.package; import com.adobe.cq.social.scf.ClientUtilities; import com.adobe.cq.social.scf.QueryRequestInfo; import com.adobe.cq.social.scf.SocialComponent; import com.adobe.cq.social.scf.SocialComponentFactory; import com.adobe.cq.social.scf.core.AbstractSocialComponentFactory; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.ConfigurationPolicy; /** Factory Class for Custom Community Component. * @author Shubham * */ @Component(name = "Custom Community Component", factory = "path.to.current.class.CustomCommunityComponentFactory", service = SocialComponentFactory.class, configurationPolicy = ConfigurationPolicy.OPTIONAL) public class CustomCommunityComponentFactory extends AbstractSocialComponentFactory implements SocialComponentFactory { @Override public SocialComponent getSocialComponent(final Resource resource) { return new CustomCommunityComponent(resource, this.getClientUtilities(resource.getResourceResolver())); } @Override public SocialComponent getSocialComponent(final Resource resource, final SlingHttpServletRequest request) { return new CustomCommunityComponent(resource, this.getClientUtilities(request)); } @Override public SocialComponent getSocialComponent(Resource resource, ClientUtilities clientUtils, QueryRequestInfo listInfo) { return new CustomCommunityComponent(resource, clientUtils); } @Override public int getPriority() { return 1000; } @Override public String getSupportedResourceType() { return "project/path/to/component"; } }

 

 


I have updated to R6 annotations for other services and servlet class but for this particular one updating to R6 reference and using @Component annotation does not seem to work. The component hbs does not render any thing and there are no errors in any of the logs. During debug as well on component page load I should be able to hit the lines with return statements, but I am unable to. This does work when I use the old annotations. Tried adding immediate=true, socialFactory=true but in vain.

Please help out if there is anything I am missing in terms of binding the custom component with the Social Component Factory class. Not sure if any one has tried this already. Could that be because the OOTB AbstractSocialComponentFactory is still using felix annotations?

cc @aponnusa 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Asutosh_Jena_

Hi @shubham_borole 

 

Please remove the factory attribute. It will resolve the issue and the component will be registered using SocialComponentFactory.

 

@Component(name = "Custom Community Component Factory", configurationPolicy = ConfigurationPolicy.OPTIONAL, service = SocialComponentFactory.class)
public class CustomCommunityComponentFactory extends AbstractSocialComponentFactory {
// Rest of the Code.
}

 

[Custom Community Component Factory,23947, [com.adobe.cq.social.scf.SocialComponentFactory]] ServiceEvent REGISTERED

 

Hope this helps!

Thanks

2 replies

Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
April 30, 2021

Hi @shubham_borole 

 

Please remove the factory attribute. It will resolve the issue and the component will be registered using SocialComponentFactory.

 

@Component(name = "Custom Community Component Factory", configurationPolicy = ConfigurationPolicy.OPTIONAL, service = SocialComponentFactory.class)
public class CustomCommunityComponentFactory extends AbstractSocialComponentFactory {
// Rest of the Code.
}

 

[Custom Community Component Factory,23947, [com.adobe.cq.social.scf.SocialComponentFactory]] ServiceEvent REGISTERED

 

Hope this helps!

Thanks

Shubham_borole
Community Advisor
Community Advisor
April 30, 2021
Thank you. This did help get to the Custom Social Factory. However still the component fails since he value of clientUtilities in SocialComponentFactory is null. I will probably add another question for this with details. Not sure if having R6 annotations for extended components work where the OOTB classes are not using them yet. Please feel free to comment on this.
joerghoh
Adobe Employee
Adobe Employee
May 1, 2021

SCR inheritance (which is supported by the Felix SCR annotations) is no longer possible with the OSGI annotations, and that's by design. IIRC Carsten Ziegeler (of the OSGI alliance) wrote that it caused more problems can benefits, so it was not included into the OSGI annotations