Expand my Community achievements bar.

Is there a way to get List of Servlets running in AEM ?

Avatar

Level 2

Needed it to configure default AEM forms (Not AEM adaptive forms) to display list of Servlets in Action dropdown, as it seems better to have Servlets as bundle instead of GET.jsp or POST.jsp nodes in crx.

Any help is highly appreciated.

TYA,

Sunil

5 Replies

Avatar

Employee Advisor

Why you want to list all the servlets running in AEM ? There are too many servlets which have nothing to do with forms. If you want to list all the custom servlets registered for the forms then you can use OSGI APIs to dynamically find all the servlets and then extract their URL property. 

Example - http://stackoverflow.com/questions/11151376/search-osgi-services-by-properties

http://felix.apache.org/apidocs/configadmin/1.4.0/org/osgi/framework/ServiceReference.html#getProper...

Avatar

Level 9

@Sunil Chowdhary,

There isn't a way to list out of all the servlets.Though You can get the object of service/servlet through Bundle Context API. But that is something you already know which one to fetch.

Here is a workaround. You want the list of actions to be listed in the form dropdowns. For this, you want to servlets because every action is a servlet. I would say change the approach of registering your servlets.

As of now, You might have registered servlets with some path. Rather than registering with a path, register your actions/servlets with resourceType. And As you know, you need to create a node in crx with that resourceType to make it work.

Once you have the list of nodes with resourceType in the crx, iterate those nodes and each node has resourceType key to fetch respective Action. I hope this is understandable. However, let me know if you have any other question.

Regards,

Jitendra

Sunil Chowdhary wrote...

Needed it to configure default AEM forms (Not AEM adaptive forms) to display list of Servlets in Action dropdown, as it seems better to have Servlets as bundle instead of GET.jsp or POST.jsp nodes in crx.

Any help is highly appreciated.

TYA,

Sunil

 

Avatar

Level 2

Hi @Steve Cave, thanks for your suggestion , but could not get much there.

Hi @kunal23 , yes there is no point getting list of all servlets running in AEM and we don't need it either. But thanks for pointing out the API , though could not get much from them or may be I am still missing something.

The code which  seem to do what needed is : 

ServiceReference[] registeredServices = FrameworkUtil.getBundle( <className>.class).getRegisteredServices();
registeredServices[i].getProperty("sling.servlet.selectors") //use this to filter servlets as required

Please revert in case of any issue or suggestion.

Hi @Jitendra S.Tomar,

I will highly appreciate if you don't answer questions asked by me, at least . It's not because your answers are not useful or don't contain information. It's just that it does not contains relevant information what a person is looking for , so sometimes it gets irritating reading your answers.  

 

 

Thanks,

Sunil

Avatar

Level 10

kunal23 answer would be the best answer here. Jitendra S.Tomar is not spam -its a honest answer.