You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Andreas Schaefer Sr." <sc...@me.com> on 2016/05/02 22:16:08 UTC

WebDav Polling Not Working

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

}

Re: WebDav Polling Not Working

Posted by Robert Munteanu <ro...@apache.org>.
On Fri, 2016-05-06 at 08:49 -0700, Andreas Schaefer Sr. wrote:
> After I wrote the mail I realized that this is a Jackrabbit issue.
> Will post it there.
> 
> What surprises me is the fact that nobody ran into this beforehand
> even though there is a Camel JCR Endpoint that facilitates that. Did
> you ever use something like RMI, JCA to connect to a remote JCR
> repository. I cannot find any documentation that works with Sling or
> AEM.

I for one did not.

Robert

> 
> - Andy
> 
> > On May 5, 2016, at 5:06 AM, Robert Munteanu <ro...@apache.org>
> > wrote:
> > 
> > Hi,
> > 
> > On Mon, 2016-05-02 at 13:16 -0700, Andreas Schaefer Sr. wrote:
> > > 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.
> > 
> > Looking at the SlingDavExServlet code I don't see any XML
> > manipulation,
> > so this should be reported to the Jackrabbit project.
> > 
> > Thanks,
> > 
> > Robert
> > 
> > > 
> > > 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 \u201c<jcr:primaryType/>\u201d 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:h
> > > ref
> > > xmlns:D="DAV:">http://localhost:4502/crx/server/crx.default/jcr%3
> > > aroo
> > > t/var/discovery/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-
> > > e90febf7e6de/lastHeartbeat</D:href><dcr:eventtype><dcr:propertych
> > > ange
> > > d/></dcr:eventtype><dcr:eventuserid>admin</dcr:eventuserid>
> > > <http://localhost:4502/crx/server/crx.default/jcr%3aroot/var/disc
> > > over
> > > y/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-
> > > e90febf7e6de/lastHeartbeat%3C/D:href%3E%3Cdcr:eventtype%3E%3Cdcr:
> > > prop
> > > ertychanged/%3E%3C/dcr:eventtype%3E%3Cdcr:eventuserid%3Eadmin%3C/
> > > dcr:
> > > eventuserid%3E><dcr:eventuserdata/><dcr:eventdate>1462220040858</
> > > dcr:
> > > eventdate><dcr:eventidentifier>/var/discovery/impl/clusterInstanc
> > > es/2
> > > c6fc55d-ef6c-42be-b9ec-
> > > e90febf7e6de</dcr:eventidentifier><dcr:eventinfo><jcr:primaryType
> > > >sli
> > > ng: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>\u201d
> > > 
> > > This is an exception I see:
> > > 
> > > java.io.IOException: XML parsing error
> > > 	at
> > > org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResp
> > > onse
> > > BodyAsDocument(DavMethodBase.java:130)
> > > 	at
> > > org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getRoot
> > > Elem
> > > ent(DavMethodBase.java:150)
> > > 	at
> > > org.apache.jackrabbit.webdav.client.methods.PollMethod.processRes
> > > pons
> > > eBody(PollMethod.java:101)
> > > 	at
> > > org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMet
> > > hodB
> > > ase.java:1749)
> > > 	at
> > > org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBa
> > > se.j
> > > ava:1098)
> > > 	at
> > > org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry
> > > (Htt
> > > pMethodDirector.java:398)
> > > 	at
> > > org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Ht
> > > tpMe
> > > thodDirector.java:171)
> > > 	at
> > > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient
> > > .jav
> > > a:397)
> > > 	at
> > > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient
> > > .jav
> > > a:323)
> > > 	at
> > > org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.poll(Reposito
> > > rySe
> > > rviceImpl.java:2378)
> > > 	at
> > > org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.getEvents(Rep
> > > osit
> > > oryServiceImpl.java:2179)
> > > 	at
> > > org.apache.jackrabbit.jcr2spi.WorkspaceManager$ChangePolling.run(
> > > Work
> > > spaceManager.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.creat
> > > eSAX
> > > ParseException(ErrorHandlerWrapper.java:203)
> > > 	at
> > > com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatal
> > > Erro
> > > r(ErrorHandlerWrapper.java:177)
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportEr
> > > ror(
> > > XMLErrorReporter.java:441)
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportEr
> > > ror(
> > > XMLErrorReporter.java:368)
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportEr
> > > ror(
> > > XMLErrorReporter.java:325)
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.
> > > scan
> > > StartElement(XMLNSDocumentScannerImpl.java:289)
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScanne
> > > rImp
> > > l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:
> > > 2786
> > > )
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.ne
> > > xt(X
> > > MLDocumentScannerImpl.java:606)
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.
> > > next
> > > (XMLNSDocumentScannerImpl.java:117)
> > > 	at
> > > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScanne
> > > rImp
> > > l.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
> > > 	at
> > > com.sun.org.apache.xerces.internal.parsers.XML11Configuration.par
> > > se(X
> > > ML11Configuration.java:848)
> > > 	at
> > > com.sun.org.apache.xerces.internal.parsers.XML11Configuration.par
> > > se(X
> > > ML11Configuration.java:777)
> > > 	at
> > > com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLPar
> > > ser.
> > > java:141)
> > > 	at
> > > com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMPar
> > > ser.
> > > java:243)
> > > 	at
> > > com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse
> > > (Doc
> > > umentBuilderImpl.java:348)
> > > 	at
> > > javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
> > > 	at
> > > org.apache.jackrabbit.webdav.xml.DomUtil.parseDocument(DomUtil.ja
> > > va:1
> > > 27)
> > > 	at
> > > org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResp
> > > onse
> > > BodyAsDocument(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/ser
> > > ver"
> > > ;
> > > ����public static final String URL = "http://localhost:4502/crx/s
> > > erve
> > > r";
> > > //����public static final String URL = "http://localhost:4502/crx
> > > /rep
> > > ository";
> > > ����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().addEve
> > > ntLi
> > > stener(
> > > ����������������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");
> > > ������������}
> > > ��������}
> > > ����}
> > > 
> > > }
> > 
> > 
> > 
> 


Re: WebDav Polling Not Working

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Fri, May 6, 2016 at 5:49 PM, Andreas Schaefer Sr. <sc...@me.com> wrote:
> ...Did you ever use something like RMI, JCA to connect to a remote JCR repository...

I've never used those mechanisms myself and my understanding is that
JCR over RMI is quite slow due to the fine granularity of JCR methods.

I think PHPCR is or at least was using remote Jackrabbit/Oak
repositories via DavEx [1] but activity about that has slowed down on
the jackrabbit list [2].

-Bertrand

[1] https://wiki.apache.org/jackrabbit/RemoteAccess
[2] http://jackrabbit.markmail.org/search/?q=phpcr#query:phpcr%20order%3Adate-backward+page:1+state:facets

Re: WebDav Polling Not Working

Posted by "Andreas Schaefer Sr." <sc...@me.com>.
After I wrote the mail I realized that this is a Jackrabbit issue. Will post it there.

What surprises me is the fact that nobody ran into this beforehand even though there is a Camel JCR Endpoint that facilitates that. Did you ever use something like RMI, JCA to connect to a remote JCR repository. I cannot find any documentation that works with Sling or AEM.

- Andy

> On May 5, 2016, at 5:06 AM, Robert Munteanu <ro...@apache.org> wrote:
> 
> Hi,
> 
> On Mon, 2016-05-02 at 13:16 -0700, Andreas Schaefer Sr. wrote:
>> 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.
> 
> Looking at the SlingDavExServlet code I don't see any XML manipulation,
> so this should be reported to the Jackrabbit project.
> 
> Thanks,
> 
> Robert
> 
>> 
>> 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:h
>> ref
>> xmlns:D="DAV:">http://localhost:4502/crx/server/crx.default/jcr%3aroo
>> t/var/discovery/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-
>> e90febf7e6de/lastHeartbeat</D:href><dcr:eventtype><dcr:propertychange
>> d/></dcr:eventtype><dcr:eventuserid>admin</dcr:eventuserid>
>> <http://localhost:4502/crx/server/crx.default/jcr%3aroot/var/discover
>> y/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-
>> e90febf7e6de/lastHeartbeat%3C/D:href%3E%3Cdcr:eventtype%3E%3Cdcr:prop
>> ertychanged/%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/2
>> c6fc55d-ef6c-42be-b9ec-
>> e90febf7e6de</dcr:eventidentifier><dcr:eventinfo><jcr:primaryType>sli
>> ng: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.getResponse
>> BodyAsDocument(DavMethodBase.java:130)
>> 	at
>> org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getRootElem
>> ent(DavMethodBase.java:150)
>> 	at
>> org.apache.jackrabbit.webdav.client.methods.PollMethod.processRespons
>> eBody(PollMethod.java:101)
>> 	at
>> org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodB
>> ase.java:1749)
>> 	at
>> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j
>> ava:1098)
>> 	at
>> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Htt
>> pMethodDirector.java:398)
>> 	at
>> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
>> thodDirector.java:171)
>> 	at
>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
>> a:397)
>> 	at
>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
>> a:323)
>> 	at
>> org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.poll(RepositorySe
>> rviceImpl.java:2378)
>> 	at
>> org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.getEvents(Reposit
>> oryServiceImpl.java:2179)
>> 	at
>> org.apache.jackrabbit.jcr2spi.WorkspaceManager$ChangePolling.run(Work
>> spaceManager.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.createSAX
>> ParseException(ErrorHandlerWrapper.java:203)
>> 	at
>> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalErro
>> r(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.scan
>> StartElement(XMLNSDocumentScannerImpl.java:289)
>> 	at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
>> l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786
>> )
>> 	at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(X
>> MLDocumentScannerImpl.java:606)
>> 	at
>> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next
>> (XMLNSDocumentScannerImpl.java:117)
>> 	at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
>> l.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
>> 	at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
>> ML11Configuration.java:848)
>> 	at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
>> ML11Configuration.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(Doc
>> umentBuilderImpl.java:348)
>> 	at
>> javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
>> 	at
>> org.apache.jackrabbit.webdav.xml.DomUtil.parseDocument(DomUtil.java:1
>> 27)
>> 	at
>> org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponse
>> BodyAsDocument(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/serve
>> r";
>> //    public static final String URL = "http://localhost:4502/crx/rep
>> ository";
>>     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().addEventLi
>> stener(
>>                 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");
>>             }
>>         }
>>     }
>> 
>> }
> 
> 
> 


Re: WebDav Polling Not Working

Posted by Robert Munteanu <ro...@apache.org>.
Hi,

On Mon, 2016-05-02 at 13:16 -0700, Andreas Schaefer Sr. wrote:
> 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.

Looking at the SlingDavExServlet code I don't see any XML manipulation,
so this should be reported to the Jackrabbit project.

Thanks,

Robert

> 
> 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 \u201c<jcr:primaryType/>\u201d 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:h
> ref
> xmlns:D="DAV:">http://localhost:4502/crx/server/crx.default/jcr%3aroo
> t/var/discovery/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-
> e90febf7e6de/lastHeartbeat</D:href><dcr:eventtype><dcr:propertychange
> d/></dcr:eventtype><dcr:eventuserid>admin</dcr:eventuserid>
> <http://localhost:4502/crx/server/crx.default/jcr%3aroot/var/discover
> y/impl/clusterInstances/2c6fc55d-ef6c-42be-b9ec-
> e90febf7e6de/lastHeartbeat%3C/D:href%3E%3Cdcr:eventtype%3E%3Cdcr:prop
> ertychanged/%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/2
> c6fc55d-ef6c-42be-b9ec-
> e90febf7e6de</dcr:eventidentifier><dcr:eventinfo><jcr:primaryType>sli
> ng: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>\u201d
> 
> This is an exception I see:
> 
> java.io.IOException: XML parsing error
> 	at
> org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponse
> BodyAsDocument(DavMethodBase.java:130)
> 	at
> org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getRootElem
> ent(DavMethodBase.java:150)
> 	at
> org.apache.jackrabbit.webdav.client.methods.PollMethod.processRespons
> eBody(PollMethod.java:101)
> 	at
> org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodB
> ase.java:1749)
> 	at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j
> ava:1098)
> 	at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Htt
> pMethodDirector.java:398)
> 	at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
> thodDirector.java:171)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
> a:397)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
> a:323)
> 	at
> org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.poll(RepositorySe
> rviceImpl.java:2378)
> 	at
> org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.getEvents(Reposit
> oryServiceImpl.java:2179)
> 	at
> org.apache.jackrabbit.jcr2spi.WorkspaceManager$ChangePolling.run(Work
> spaceManager.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.createSAX
> ParseException(ErrorHandlerWrapper.java:203)
> 	at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalErro
> r(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.scan
> StartElement(XMLNSDocumentScannerImpl.java:289)
> 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
> l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786
> )
> 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(X
> MLDocumentScannerImpl.java:606)
> 	at
> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next
> (XMLNSDocumentScannerImpl.java:117)
> 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
> l.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
> ML11Configuration.java:848)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
> ML11Configuration.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(Doc
> umentBuilderImpl.java:348)
> 	at
> javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
> 	at
> org.apache.jackrabbit.webdav.xml.DomUtil.parseDocument(DomUtil.java:1
> 27)
> 	at
> org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponse
> BodyAsDocument(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/serve
> r";
> //����public static final String URL = "http://localhost:4502/crx/rep
> ository";
> ����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().addEventLi
> stener(
> ����������������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");
> ������������}
> ��������}
> ����}
> 
> }