Expand my Community achievements bar.

SOLVED

code trigger on move

Avatar

Level 4

Hi,

i'm searching to capture the event of the move command of pages.

This command does 4 things:

  1. it deletes a page author side
  2. it creates a renamed page author side
  3. it deletes a page public side
  4. it creates a renamed page publish side (if the user wants)

I can capture the first and second step with a trigger an author.

For the remaining points i must stay author side so i cannot do a trigger publish side.

Can i use a custom replication agent? How?

How can i associate a snippet java to a replicator agent?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Thats because, the #3 and #4 are the events that happens in publish instance and hence its in not captured in the servlet in the author mode. Publish the same servlet on the publish instance and see the logs in the publish server

View solution in original post

4 Replies

Avatar

Level 4

I can use a replication agent to call a servlet author side so i can capture the request that point to the publish.

This is my servlet:

package eu.unicredit.gimb.servlet; import org.apache.felix.scr.annotations.Properties; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.sling.SlingServlet; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.servlet.ServletException; import java.io.IOException; @SlingServlet(paths={"/services/gimbupdatepab/"}) @Properties({ @Property(name="service.description",value="publish/delete pab pages", propertyPrivate=false) }) public class GimbUpdatePab extends SlingAllMethodsServlet { protected final Logger log = LoggerFactory.getLogger(this.getClass()); @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { log.info("eseguita GET"); } @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { log.info("eseguita POST"); } }

 

 

and this is the log:

 

13.10.2015 14:30:12.952 *INFO*  Sending POST request to http://localhost:4502/services/gimbupdatepab 13.10.2015 14:30:12.952 *INFO*  sent. Response: 200 OK 13.10.2015 14:30:12.952 *INFO*  ------------------------------------------------ 13.10.2015 14:30:12.952 *INFO*  Sending message to localhost:4502 13.10.2015 14:30:12.952 *INFO*  >> POST /services/gimbupdatepab HTTP/1.0 13.10.2015 14:30:12.952 *INFO*  >> Action: Activate 13.10.2015 14:30:12.952 *INFO*  >> Path: /content/gimb_it/it/minisite/services 13.10.2015 14:30:12.952 *INFO*  >> Handle: /content/gimb_it/it/minisite/services 13.10.2015 14:30:12.952 *INFO*  >> ...spooling 2021 bytes... 13.10.2015 14:30:12.952 *INFO*  -- 13.10.2015 14:30:12.952 *INFO*  << HTTP/1.1 200 OK 13.10.2015 14:30:12.952 *INFO*  << Connection: Keep-Alive 13.10.2015 14:30:12.952 *INFO*  << Server: Day-Servlet-Engine/4.1.24 13.10.2015 14:30:12.952 *INFO*  << Content-Type: text/html;charset=UTF-8 13.10.2015 14:30:12.952 *INFO*  << Date: Tue, 13 Oct 2015 12:30:12 GMT 13.10.2015 14:30:12.952 *INFO*  << Transfer-Encoding: chunked 13.10.2015 14:30:12.952 *INFO*  << 13.10.2015 14:30:12.952 *INFO*  << <html> 13.10.2015 14:30:12.952 *INFO*  << <head> 13.10.2015 14:30:12.952 *INFO*  <<     <title>Content modified /services/gimbupdatepab</title> 13.10.2015 14:30:12.952 *INFO*  << </head> 13.10.2015 14:30:12.952 *INFO*  <<     <body> 13.10.2015 14:30:12.952 *INFO*  <<     <h1>Content modified /services/gimbupdatepab</h1> 13.10.2015 14:30:12.952 *INFO*  <<     <table> 13.10.2015 14:30:12.952 *INFO*  <<         <tbody> 13.10.2015 14:30:12.952 *INFO*  <<             <tr> 13.10.2015 14:30:12.952 *INFO*  <<                 <td>Status</td> 13.10.2015 14:30:12.952 *INFO*  <<                 <td><div id="Status">200</div></td> 13.10.2015 14:30:12.952 *INFO*  <<             </tr> 13.10.2015 14:30:12.952 *INFO*  <<             <tr> 13.10.2015 14:30:12.952 *INFO*  <<                 <td>Message</td> 13.10.2015 14:30:12.952 *INFO*  <<                 <td><div id="Message">OK</div></td> 13.10.2015 14:30:12.952 *INFO*  <<             </tr> 13.10.2015 14:30:12.952 *INFO*  <<             <tr> 13.10.2015 14:30:12.952 *INFO*  <<                 <td>Location</td> 13.10.2015 14:30:12.952 *INFO*  <<                 <td><a href="https://forums.adobe.com/services/gimbupdatepab" id="Location">/services/gimbupdatepab</a></td> 13.10.2015 14:30:12.952 *INFO*  <<             </tr> 13.10.2015 14:30:12.952 *INFO*  <<             <tr> 13.10.2015 14:30:12.952 *INFO*  <<                 <td>Parent Location</td> 13.10.2015 14:30:12.952 *INFO*  <<                 <td><a href="https://forums.adobe.com/services" id="ParentLocation">/services</a></td> 13.10.2015 14:30:12.952 *INFO*  <<             </tr> 13.10.2015 14:30:12.952 *INFO*  <<             <tr> 13.10.2015 14:30:12.952 *INFO*  <<                 <td>Path</td> 13.10.2015 14:30:12.952 *INFO*  <<                 <td><div id="Path">/services/gimbupdatepab</div></td> 13.10.2015 14:30:12.968 *INFO*  <<             </tr> 13.10.2015 14:30:12.968 *INFO*  <<             <tr> 13.10.2015 14:30:12.968 *INFO*  <<                 <td>Referer</td> 13.10.2015 14:30:12.968 *INFO*  <<                 <td><a href="" id="Referer"></a></td> 13.10.2015 14:30:12.968 *INFO*  <<             </tr> 13.10.2015 14:30:12.968 *INFO*  <<             <tr> 13.10.2015 14:30:12.968 *INFO*  <<                 <td>ChangeLog</td> 13.10.2015 14:30:12.968 *INFO*  <<                 <td><div id="ChangeLog">&lt;pre&gt;&lt;/pre&gt;</div></td> 13.10.2015 14:30:12.968 *INFO*  <<             </tr> 13.10.2015 14:30:12.968 *INFO*  <<         </tbody> 13.10.2015 14:30:12.968 *INFO*  <<     </table> 13.10.2015 14:30:12.968 *INFO*  <<     <p><a href="">Go Back</a></p> 13.10.2015 14:30:12.968 *INFO*  <<     <p><a href="https://forums.adobe.com/services/gimbupdatepab">Modified Resource</a></p> 13.10.2015 14:30:12.968 *INFO*  <<     <p><a href="https://forums.adobe.com/services">Parent of Modified Resource</a></p> 13.10.2015 14:30:12.968 *INFO*  <<     </body> 13.10.2015 14:30:12.968 *INFO*  Message sent. 13.10.2015 14:30:12.968 *INFO*  ------------------------------------------------ 13.10.2015 14:30:12.968 *INFO*  Replication (ACTIVATE) of /content/gimb_it/it/minisite/services successful. 13.10.2015 14:30:12.968 *INFO* [pool-6-thread-9-com/day/cq/replication/job/gimbreplicationagent(com/day/cq/replication/job/gimbreplicationagent)] com.day.cq.replication.impl.AgentManagerImpl Job for agent gimbreplicationagent processed in 16ms. Ok.

it works but i can't see the print inside the post method, why?

Avatar

Correct answer by
Level 10

Thats because, the #3 and #4 are the events that happens in publish instance and hence its in not captured in the servlet in the author mode. Publish the same servlet on the publish instance and see the logs in the publish server

Avatar

Level 10

In 1st step why don't you deactivate the page before deleting, it will remove page from publish directly, 

use https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/replication/Replicator.html api

Avatar

Level 4

I'm using cq5.5 with this path @SlingServlet(paths={"/services/gimbupdatepab/"})

if the replicator point to http://localhost:4502/services/gimbupdatepab the request is 200 OK but the log inside get/post doesn't appear

With the same url inside the browser toolbar i have 403 Forbidden

if the replicator point to http://localhost:4502/crx/repository/crx.default/services/gimbupdatepab the request is 415 Unsupported Media Type

The same url inside the browser toolbar seems to work

Which is correct?