Most of the time while working on the project we will have scenarios to dynamically register the servlets with different resource types, selector and extension, etc — registering the same servlet with different resource types, selector, extensions, etc. Let's assume we have a servlet that is registered with a specific resource type but later we have a requirement to enable the same servlet for a different resource type, one of the common options is modifying the source code to enable the additional resource types. The code change might not be the optimal solution in most cases. In this tutorial, let us see the simple approach to register the servlets dynamically with different resource types, selectors, and extensions. The OSGi Metatype Annotations(OSGi Declarative Services Annotations) can be used to register the dynamic servlets. ObjectClassDefinition — Generate a Meta Type Resource using the annotated type AttributeDefinition — AttributeDefinition information for the annotated method. Designate — Generate a Designate element in the Meta Type Resource for an ObjectClassDefinition using the annotated Declarative Services component.
Please use this thread to ask the related questions.
Hi @kautuk_sahni ,
Is there any specific reason is there that JSON or txt extensions can be accessed only from jcr:content node.
Please provide me some explanation.
In this article for configuration class static is added. Because of that configuration is not registering. After removing static it worked perfectly.
public static @interface Config
Thanks, @Sandeep6 for the feedback, the resource type is tagged to the jcr:content node of the cq:page so the _jcr_content should be included to invoke the servlet.
Anyhow the HTML extension is invoking the servlet without adding the _jcr_content to the request path.
Let me know if you need any further information on this. I will review the issue with the static keyword.
Hi @Albin_Issac ,
Is there any way to invoke the servlet without adding the _jcr_content for json and txt extension.
One option to add the resource type as cq/Page so the servlet can be accessed directly on page nodes, in this case, the servlet will be invoked for all the pages irrespective of the page resource type specified in jcr:content node.