Expand my Community achievements bar.

SOLVED

Overriding OOTB CommandServlet to add custom logic for replication

Avatar

Level 1

Hi,

I am trying to override default behavior of OOTB CommandServlet comes with cq-replication bundle which uses scr annotation and handles all replication actions. I am trying to override this servlet to have a custom logic to replicate to a specific publish server based on agentId but I am unable to do so as POST call to /bin/replicate always goes to OOTB servlet only though I have a same configuration in the Custom Servlet to handle the replication actions.

Thanks.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @nitinfuture, in general overriding OOTB CommandServlet is not a good approach. The main reason for that is you can affect other functionalities that use this servlet, this approach could also get you in trouble after AEM upgrade (i.e. installing SP). Below you can find some options including the one that should allow you to use your servlet.

  1. If you still want to use your implementation of CommandServlet, you can try to manipulate service.ranking property. You can also use ACS Commons OSGi Component Disabler to switch off OOTB CommandServlet - this will guarantee only your servlet will be available. Nevertheless all options described in this point are not recommended.
  2. You can use replication API, .e.g Preprocessor and AgentFilter, this will allow you to control which replication agent should be used, e.g. base on agent id or other criteria/rules.
  3. I am not sure what is exactly the case, but this also could be an option. If you would like to use different replication agents for different content paths. The easiest way will be to create dedicated users that will be used by each agent. Each user should have permission only to specific content path. In other words each agent will be able to replicate content from path to which it has permission.

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @nitinfuture, in general overriding OOTB CommandServlet is not a good approach. The main reason for that is you can affect other functionalities that use this servlet, this approach could also get you in trouble after AEM upgrade (i.e. installing SP). Below you can find some options including the one that should allow you to use your servlet.

  1. If you still want to use your implementation of CommandServlet, you can try to manipulate service.ranking property. You can also use ACS Commons OSGi Component Disabler to switch off OOTB CommandServlet - this will guarantee only your servlet will be available. Nevertheless all options described in this point are not recommended.
  2. You can use replication API, .e.g Preprocessor and AgentFilter, this will allow you to control which replication agent should be used, e.g. base on agent id or other criteria/rules.
  3. I am not sure what is exactly the case, but this also could be an option. If you would like to use different replication agents for different content paths. The easiest way will be to create dedicated users that will be used by each agent. Each user should have permission only to specific content path. In other words each agent will be able to replicate content from path to which it has permission.