Hi I am trying to listen for node creation events and use WebDav connection:
session.getWorkspace().getObservationManager().addEventListener() Unfortunately I cannot make this work neither in AEM 6.1 nor in Sling 8. What I see is that I get a DavException: (200) OK which is cause by XML parsing error. Looking at the content that is returned from the SlingDavExServlet is containing “<jcr:primaryType/>” which is not defined in the XML header as namespace and therefore the parsing fails (see DavMethodBase.getResponseBodyAsDocument()). This is the content I receive from the server: [ Change Polling] content DEBUG << "<dcr:eventdiscovery xmlns:dcr="http://www.day.com/jcr/webdav/1.0 <http://www.day.com/jcr/webdav/1.0>"><dcr:eventbundle><dcr:event><D:href xmlns:D="DAV:">http://localhost:4502/crx/server/crx.default/jcr%3aroot/var/discovery/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-e90febf7e6de/lastHeartbeat</D:href><dcr:eventtype><dcr:propertychanged/></dcr:eventtype><dcr:eventuserid>admin</dcr:eventuserid> <http://localhost:4502/crx/server/crx.default/jcr%3aroot/var/discovery/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-e90febf7e6de/lastHeartbeat%3C/D:href%3E%3Cdcr:eventtype%3E%3Cdcr:propertychanged/%3E%3C/dcr:eventtype%3E%3Cdcr:eventuserid%3Eadmin%3C/dcr:eventuserid%3E><dcr:eventuserdata/><dcr:eventdate>1462220040858</dcr:eventdate><dcr:eventidentifier>/var/discovery/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-e90febf7e6de</dcr:eventidentifier><dcr:eventinfo><jcr:primaryType>sling:Folder</jcr:primaryType><beforeValue>2016-05-02T13:13:30.856-07:00</beforeValue><afterValue>2016-05-02T13:14:00.858-07:00</afterValue></dcr:eventinfo></dcr:event></dcr:eventbundle></dcr:eventdiscovery>” This is an exception I see: java.io.IOException: XML parsing error at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponseBodyAsDocument(DavMethodBase.java:130) at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getRootElement(DavMethodBase.java:150) at org.apache.jackrabbit.webdav.client.methods.PollMethod.processResponseBody(PollMethod.java:101) at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1749) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.poll(RepositoryServiceImpl.java:2378) at org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.getEvents(RepositoryServiceImpl.java:2179) at org.apache.jackrabbit.jcr2spi.WorkspaceManager$ChangePolling.run(WorkspaceManager.java:1240) at java.lang.Thread.run(Thread.java:745) Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 628; The prefix "jcr" for element "jcr:primaryType" is not bound. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:289) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) at org.apache.jackrabbit.webdav.xml.DomUtil.parseDocument(DomUtil.java:127) at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponseBodyAsDocument(DavMethodBase.java:121) ... 12 more I use Jackrabbit 2.10.0 to connect to the server. This is my test code: import org.apache.jackrabbit.commons.JcrUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.jcr.LoginException; import javax.jcr.NoSuchWorkspaceException; import javax.jcr.Node; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.SimpleCredentials; import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; public class TestCamelMain { private final Logger LOG = LoggerFactory.getLogger(TestCamelMain.class); // public static final String URL = "http://localhost:8080/server"; public static final String URL = "http://localhost:4502/crx/server"; // public static final String URL = "http://localhost:4502/crx/repository"; public static final String user = "admin"; public static final String path = "/etc/framemaker/inbox"; private static final String WORKSPACE = "crx.default"; // private static final String WORKSPACE = "default"; private TestCamelMain main; public static void main(String[] args) throws Exception { TestCamelMain example = new TestCamelMain(); example.boot(); } public void boot() throws Exception { Session session = null; try { LOG.info("Getting repository."); final Repository repository = JcrUtils.getRepository(URL); LOG.info("Getting Session."); session = repository.login( new SimpleCredentials(user, user.toCharArray()), WORKSPACE); LOG.info("Getting parent node."); Node parent = session.getNode(path); if (null == parent) { LOG.error("Node not found at {}", path); return; } String[] uuid = null; // String uuids = getJcrEndpoint().getUuids(); // // if (uuids != null) { // uuids = uuids.trim(); // // if (!"".equals(uuids)) { // uuid = uuids.split(","); // } // } String[] nodeTypeName = null; // String nodeTypeNames = getJcrEndpoint().getNodeTypeNames(); // // if (nodeTypeNames != null) { // nodeTypeNames = nodeTypeNames.trim(); // // if (!"".equals(nodeTypeNames)) { // nodeTypeName = nodeTypeNames.split(","); // } // } session.getWorkspace().getObservationManager().addEventListener( new MyEventListener(), 3, path, true, uuid, nodeTypeName, false ); Thread.sleep(3600 * 1000); } catch (LoginException e) { LOG.error("Cannot login.", e); } catch (NoSuchWorkspaceException e) { LOG.error("No such workspace.", e); } catch (RepositoryException e) { LOG.error("Cannot connect to repository.", e); } finally { if (null != session) { session.logout(); LOG.info("Closing session."); } } } public class MyEventListener implements EventListener { @Override public void onEvent(EventIterator events) { if(events != null) { while(events.hasNext()) { LOG.info("Got Event: " + events.next()); } } else { LOG.info("Events Iterator is null"); } } } }