Custom Replication Agent problem | Community
Skip to main content
New Participant
March 5, 2019
Solved

Custom Replication Agent problem

  • March 5, 2019
  • 6 replies
  • 9668 views

Hi everyone! Im new with adobe aem, actually Im working with 6.4 and Im trying to create a custom replication agent.

My problem is that when I build the code into aem and select the "Serialization Type" into the agent it fail and I receiving
"Agent is not valid. ContentBuilder not available"

I have following the next steps:

>I have tried creating a new agent, add the serialization type (custom) and fail.

>Copying from an existing agent, and also fails.

Im implementing ContentBuilder and TransportHandler, I just have only some logs into the implemented methods,I already have looked into Nate Yolles example

http://www.nateyolles.com/blog/2016/01/aem-akamai-custom-replication-agent

Im not copying the code because I want to understand how it works, also I have noticed there are some deprecated features in the annotations used in this example,

I have fix that, but Im not sure at all if the new annotations are causing the problem, also I have checked some documentation but so far it was not very helpful.

Im only using the @component annotation as you can see in the following code Im currently using:

Any sort of help highly appreciated.

Thanks in advance!.

------------------------------- TRANSPORT HANDLER ------------------------------------------------

@Component(name = "Custom Agent",immediate = true, enabled = true)

public class MyTransportHandler implements TransportHandler {

public boolean canHandle(AgentConfig config) {

log.info("+++++FROM CANHANDLE!!++++++");

return true;

}

public ReplicationResult deliver(TransportContext ctx, ReplicationTransaction tx) throws ReplicationException {

        ReplicationActionType replicationType = tx.getAction().getType();

        log.info("+++++FROM DELIVER!!++++++");

return ReplicationResult.OK;

}

---------------------------------------------CONTENTBUILDER-----------------------------------------------

@Component (service = ContentBuilder.class, enabled = true, name = "name")

public class TestContentBuilder implements ContentBuilder{

public ReplicationContent create(Session arg0, ReplicationAction arg1, ReplicationContentFactory arg2)

            throws ReplicationException {

        // TODO Auto-generated method stub

        return create(arg0,arg1,null);

    }

    @Override

    public ReplicationContent create(Session session, ReplicationAction action, ReplicationContentFactory factory,

            Map<String, Object> parameters) throws ReplicationException {

  log.info("---- FROM CONTENT BUILDER -----");

return ReplicationContent.VOID;

    }

@Override

    public String getName() {

        // TODO Auto-generated method stub

        return "Test AK";

    }

    @Override

    public String getTitle() {

        // TODO Auto-generated method stub

        return "Test AK Description";

    }   

--------------------------------------------------------------------------------------------------------------------

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Gaurav-Behl

My recommendation would be to copy-paste code and make it compile without any issues to isolate multiple issues (libraries vs AEM-version vs archetype vs your own source code related issues) that you're trying to deal with in a single shot. Once it compiles and you're able to test it then tweak per your requirements.

I copied that code as-is, modified a couple of libs in pom.xml and I don't see any ContentBuilder related error.

6 replies

Employee
December 6, 2019

This is correct answer. The agent must have this - property = { "name=akamai", "service.ranking:Integer=1001" }

New Participant
March 30, 2019

Thank you Airtash. It worked.

smacdonald2008
New Participant
March 29, 2019
AirtashAuthor
New Participant
March 29, 2019

Just add the following annotation in the class ContentBuilder.

@Component (service = ContentBuilder.class, enabled = true,property={"name=akamai",Constants.SERVICE_RANKING +":Integer=1001"})

public class AkamaiContentBuilder implements ContentBuilder {

}

for TransportHandler

@Component(service = TransportHandler.class,immediate = true, enabled = true,property={Constants.SERVICE_RANKING +":Integer=1001"})

public class AkamaiTransportHandler implements TransportHandler {

}

Also there are other helpful links that explain the new annotations.

https://forums.adobe.com/message/10671360#10671360

http://www.sgaemsolutions.com/2017/07/migration-of-scr-annotations-to-osgi-r6.html

http://www.nateyolles.com/blog/2017/05/osgi-declarative-services-annotations-in-aem

Re: AEM 6.4 beta, Apache Sling JCR Resource Resolver not present

New Participant
March 28, 2019

Hi,

I am also facing same issue,

  • Agent is not valid. ContentBuilder not available

created multi module aem project using archetype 15. Below is my content builder code

@Component(name="Custom Content Builder", service=ContentBuilder.class)

public class CustomContentBuilder implements ContentBuilder {

private static final Logger LOGGER = LoggerFactory.getLogger(CustomContentBuilder.class);

@Reference

    private ResourceResolverFactory resolverFactory;

public static final String NAME = "Custom Content Builder";

public static final String TITLE = "Custom Content Builder";

  public ReplicationContent create(Session session, ReplicationAction action,

   ReplicationContentFactory factory) throws ReplicationException {

  LOGGER.info("Inside create!!!");

  return ReplicationContent.VOID; 

}

public String getName() {

LOGGER.info("Inside getName!!!");

  return TITLE;

}

public String getTitle() {

LOGGER.info("Inside getTitle!!!");

  return TITLE;

}

public ReplicationContent create(Session session, ReplicationAction action,

   ReplicationContentFactory factory, Map<String, Object> arg3){

LOGGER.info("Inside create new!!!");

LOGGER.info("Action type ::: "+action.getType());

String pagePath = action.getPath();

LOGGER.info("Page Path ::: "+pagePath);

try {

Map<String, Object> authenticationInfo = new HashMap<>();

authenticationInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session);

ResourceResolver resourceResolver = resolverFactory.getResourceResolver(authenticationInfo);

Page page = resourceResolver.getResource(pagePath).adaptTo(Page.class);

LOGGER.info("Page original path ::: "+page.getPath());

} catch(Exception ex) {

LOGGER.error("Error in create ::: ", ex);

}

  return ReplicationContent.VOID;

}

}

Please advise what dependencies you have modified to make it working?

Thanks,

Pradeep

Gaurav-Behl
Gaurav-BehlAccepted solution
New Participant
March 7, 2019

My recommendation would be to copy-paste code and make it compile without any issues to isolate multiple issues (libraries vs AEM-version vs archetype vs your own source code related issues) that you're trying to deal with in a single shot. Once it compiles and you're able to test it then tweak per your requirements.

I copied that code as-is, modified a couple of libs in pom.xml and I don't see any ContentBuilder related error.

New Participant
February 18, 2021
What libs did you modify in the pom.xml?