问题描述
我正在尝试为CQ5.6编写自定义文件上传组件,但遇到反向复制问题.在发布实例中创建但未复制到作者实例的节点.复制器调用之后,下一行出现在error.log中:
I'm trying to write custom file upload component for CQ5.6, but I meet the problem with reverse replication. Node created in Publish instance, but not replicated to Author instance. After replicator call, next line appears in error.log:
com.day.cq.replication.impl.ReplicatorImpl Replication triggered, but no agent found or selected.
复制代理已打开.在其他情况下,例如用户窗体,复制成功完成,因此我认为问题出在我的代码中.有我使用的代码:
Replication agents are turned on. In other cases, userforms for example, replication works successfully, so I'm think the problem is somewhere in my code. There is the code I use:
Node node = session.getNode(path);
ValueFactory valueFactory = session.getValueFactory();
Binary contentValue = valueFactory.createBinary(is);
Node parent = node.addNode(fileName, "nt:unstructured");
parent.setProperty(DELETED, false);
parent.setProperty(DESCRIPTION, description);
Node fileNode = parent.addNode(fileName, "nt:file");
fileNode.addMixin("mix:referenceable");
Node resNode = fileNode.addNode("jcr:content", "nt:resource");
resNode.setProperty(Property.JCR_DATA, contentValue);
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(lastModified.getTimeInMillis());
resNode.setProperty(Property.JCR_LAST_MODIFIED, lastModified);
parent.setProperty("cq:distribute", true);
parent.setProperty("cq:lastModified", Calendar.getInstance());
parent.setProperty("cq:lastModifiedBy", session.getUserID());
session.save();
replicator.replicate(session, ReplicationActionType.ACTIVATE, parent.getPath());
session.logout();
对于在servlet中创建的该节点,应该如何使反向复制起作用?
What should I do to make reverse replication works for this nodes I create in servlet?
更新:根据TomekRękawek的回答,我更新了代码,但问题仍然没有解决.这是新代码:
UPDATE:According to Tomek Rękawek answer I updated my code, but problem still not solved. Here is new code:
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Session session = resourceResolver.adaptTo(Session.class);
String path = (String) componentContext.getProperties().get(SAVEPATH);
Node node = session.getNode(path);
ValueFactory valueFactory = session.getValueFactory();
Binary contentValue = valueFactory.createBinary(is);
Node parent = node.addNode(fileName, "cq:Page");
Node jcrContent = parent.addNode("jcr:content", "cq:PageContent");
jcrContent.setProperty("cq:distribute", true);
jcrContent.setProperty("cq:lastModified", Calendar.getInstance());
jcrContent.setProperty("cq:lastModifiedBy", session.getUserID());
Node fileNode = jcrContent.addNode(fileName, "nt:file");
fileNode.addMixin("mix:referenceable");
Node resNode = fileNode.addNode("jcr:content", "nt:resource");
resNode.setProperty(Property.JCR_DATA, contentValue);
session.save();
session.logout();
推荐答案
反向复制是作者实例(而不是发布)执行的操作.负责此操作的代理是作者上的反向复制代理.它每30秒连接一次发布,并收集设置了cq:distribute
属性的页面节点.
Reverse replication is action performed by the author instance, not the publish. Agent responsible for this is Reverse Replication Agent on the author. It connects to the publish every 30 seconds and gathers page nodes with cq:distribute
property set.
要反向复制图像,您需要:
In order to reverse replicate the image you need to:
- 创建
cq:Page
节点 - 在其下创建
cq:PageContent
节点,并将其命名为jcr:content
. - 在
jcr:content
下创建您的图像节点并保存您的会话 [已编辑] - 在
jcr:content
节点上设置cq:distribute
,cq:lastModified
和cq:lastModifiedBy
属性. - 保存会话
- Create
cq:Page
node - Create
cq:PageContent
node under it and name itjcr:content
. - Create your image node under the
jcr:content
and save your session [edited] - Set
cq:distribute
,cq:lastModified
andcq:lastModifiedBy
properties on thejcr:content
node. - Save the session
创建页面包装输入流并对其进行反向复制的示例方法:
Sample method that creates page wrapping input stream and reverse-replicates it:
private void reverseReplicateBinary(Session session, String parentPath, String name, InputStream is)
throws RepositoryException {
ValueFactory valueFactory = session.getValueFactory();
Node parent = session.getNode(parentPath);
Node page = JcrUtils.getOrCreateUniqueByPath(parent, name, "cq:Page");
Node jcrContent = page.addNode(Property.JCR_CONTENT, "cq:PageContent");
Node file = jcrContent.addNode("file", "nt:file");
Node resource = file.addNode(Property.JCR_CONTENT, "nt:resource");
resource.setProperty(Property.JCR_DATA, valueFactory.createBinary(is));
session.save();
jcrContent.setProperty("cq:lastModified", Calendar.getInstance());
jcrContent.setProperty("cq:lastModifiedBy", session.getUserID());
jcrContent.setProperty("cq:distribute", false);
session.save();
}
完整示例可在要点上找到.
仅此而已.您无需手动调用复制器,作者实例将自动收集页面.
That's all. You don't need to call replicator manually, author instance will gather page automatically.
这篇关于CQ 5.6反向复制:触发了复制,但是未找到或未选择代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!