6 Replies Latest reply on May 28, 2013 1:08 AM by matthias02

    How to return .xml file with requested and formatted data  as Replication process result?

    Pawko Level 1

      Hi,

      As described in the title I'd like to send formatted xml to given url after replication process. I see that there are 3 types of serialization by default (Default, Dispatcher Flush and Static Content Builder). How can I provide my own Serialization Type to build xml file in the requested format with requested data?

       

      BR,

      Pawos

        • 1. Re: How to return .xml file with requested and formatted data  as Replication process result?
          Sham HC Level 7

          See if replication listener [1] fullfill your requirements otherwise pseudo steps for own custom agent would be [2].

           

          [1]   http://dev.day.com/content/kb/home/cq5/Development/CQ5Replication/ReplicationListener.html

           

          [2]

          Here are the steps to create a custom agent :

           

          1) Create a custom transport handler class that implement com.day.cq.replication.TransportHandler. Make it an OSGi service with com.day.cq.replication.TransportHandler as a service interface.

          * Implement the deliver(TransportContext ctx, ReplicationTransaction tx) method to communicate with given url

          * Implement canHandle(AgentConfig config) method. This method will be called by the replication service to determine if this agent should handle the content being activated before calling deliver() method.

          http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/replication/TransportHandler.html

           

          2) Create a Content Builder class by implementing com.day.cq.replication.ContentBuilder interface. Make this an OSGi component as well with com.day.cq.replication.ContentBuilder as it's service interface. This class would be responsible for building content to be replicated. This class should create ReplicationContent object that would represent content to be replicated. You will be able to retrieve ReplicationContent object from ReplicationTransaction in the deliver() method of your transport handler from ReplicationTransaction.

          http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/replication/ContentBuilder.html

           

          3) Create an agent page component and template. This would be used to configure the agent. As a starting point you can simply copy the page component and template for the default replication agent.

          * see /libs/cq/replication/components/agent and /libs/cq/replication/templates/agent.

           

          For your TransportHandler and ContentBuilder implementation you will need to create an OSGi bundle.

          • 2. Re: How to return .xml file with requested and formatted data  as Replication process result?
            Pawko Level 1

            Thank you for this solution. I have another question connected with this issue. I was able to create my own Content Builder. Unfortunately when I chose it as Serialization Type with default agent an error occured:

             

             

            ERROR - my-agent : << HTTP/1.1 400 Bad Request

            ERROR - my-agent : << Connection: Close

            ERROR - my-agent : << Server: Day-Servlet-Engine/4.1.24

            ERROR - my-agent : << Content-Type: text/plain;charset=utf-8

            ERROR - my-agent : << Content-Length: 114

            ERROR - my-agent : <<

            ERROR - my-agent : << error: com.day.cq.replication.ReplicationException: Repository error during page import: Protocol Header expected.

            ERROR - my-agent : Message sent.

             

            Additionally test connection works perfect.

            • 3. Re: How to return .xml file with requested and formatted data  as Replication process result?
              Sham HC Level 7

              It might be different isssue. Clean all your queue & reverify.  Also at end point of agent verify what is the Content-Length header size.

              • 4. Re: How to return .xml file with requested and formatted data  as Replication process result?
                matthias02 Level 1

                Hello Sham HC,

                 

                As far as I can see, this is the only description about how to write your own costum replication agent. Thanks for that!

                 

                Anyway, I'm facing a problem following your descriptions:

                I implemented the interfaces com.day.cq.replication.TransportHandler + com.day.cq.replication.ContentBuilder and registered both as OSGi components. The Web Console tells me, everything is fine, as both classes occure as components in the corresponding tab. In addition, I can create a new replication agent (using the standard template "Replication Agent") and assign my ContentBuilder to this agent by setting it's Serialization Type to the value I retrieve in my method ContentBuilder.getTitle() ("XML ContentBuilder"). (The URI on tab "Transport" is set too.)

                Using CRXDE Lite I can browse to /etc/replication/agents.author/myAgent/jcr:content and see, that the property serializationType is set to the value I provide in my method ContentBuilder.getName() ("xmlContent").

                 

                Everything seems fine. But when I try to enable my agent I always get the following error on the agent's settings page:

                Agent is not valid. ContentBuilder not available

                 

                In addition, the error.log shows the following message:

                *ERROR* [ObservationManager] com.day.cq.replication.Agent.myAgent Agent not valid yet. No content builder for xmlContent

                *INFO* [ObservationManager] com.day.cq.replication.Agent.myAgent Agent updated. State is enabled and invalid

                 

                What am I doing wrong?

                Shouldn't this work perfectly?

                Do I miss something?

                 

                 

                Thanks in advance for any hints and advices!

                Matthias

                • 5. Re: How to return .xml file with requested and formatted data  as Replication process result?
                  Sham HC Level 7

                  Hi Matthias,

                   

                      The steps I have provided are correct.  As an sample implementation refer "Refetch flush agent" source code at [1]. Te details of the agent is covered for five minutes at [2].

                   

                  [1]  https://github.com/cqsupport/webinar-dispatchercache

                   

                  [2]   http://my.adobeconnect.com/p7th2gf8k43/

                   

                  Thanks,

                  Sham

                  1 person found this helpful
                  • 6. Re: How to return .xml file with requested and formatted data  as Replication process result?
                    matthias02 Level 1

                    Thanks Sham,

                     

                    I now came across my problem:

                     

                    In order for CQ to find the ContentBuilder it needs a service property name that has exactly the same value as the method getName() returns.

                     

                    So in my example (as I use scr annotations) I just added the following line to my ContenBuilder class:

                    @Property(name = "name", value = "xmlContent")

                     

                    Cheers,

                    Matthias