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

Custom Replication Agent problem

Avatar

Level 2

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"

01.JPG

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";

    }   

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.

View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

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.

Avatar

Level 6

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

Avatar

Level 2

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

Avatar

Employee Advisor

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