Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How can we hit the servlet which is registered based on path from an OSGI EventHandler

Avatar

Level 1

Hi Team,

 

We have a requirement where we have to call a servlet by setting some request parameters from the EventHandler when the user Publish the page from Touch UI to clear the Dispatcher And CDN Cache for the published page (or) Asset (We already have a logic in the servlet to clear Dispatcher And CDN Cache).

 

So to achieve this we were trying to call the servlet from the Existing EventHandler (Which is to convert HTML page to PDF file when ever user change some content in the and page and publish it) by annotating SlingHttpServletRequest And SlingHttpServletResponse with @reference OSGI annotation, but we are getting these 2 objects as NULL in the EventHandler.

 

Please suggest some other approach to call the servlet from the EventHandler without using SlingHttpServletRequest And SlingHttpServletResponse objects (or) Any other way is also fine for us.

 

Regards,

Surendra k  

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

I would recommend to extract the logic from Servlet and put in a common service(which generate PDF) and then use this common service in Servlet and EventHandler.

 

technically it is possible to create request from EventListener but not the best design

https://github.com/arunpatidar02/aemaacs-aemlab/blob/f96ce5316dfa4798c72d2e87d3a0b41fc49791a4/core/s... 



Arun Patidar

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi,

I would recommend to extract the logic from Servlet and put in a common service(which generate PDF) and then use this common service in Servlet and EventHandler.

 

technically it is possible to create request from EventListener but not the best design

https://github.com/arunpatidar02/aemaacs-aemlab/blob/f96ce5316dfa4798c72d2e87d3a0b41fc49791a4/core/s... 



Arun Patidar

Avatar

Level 1

Thank you Arun, we just moved the cache clear logic from servlet to service and resolve the issue.