Jackrabbit Content Repository
  1. Jackrabbit Content Repository
  2. JCR-1852

session.exportDocumentView() does not work with jaxb 2.1.x UnmarshallerHandler

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.5
    • Component/s: jackrabbit-jcr-commons
    • Labels:
      None
    • Environment:
      jdk 1.6.10 Linux

      Description

      I tried to update my project from Jackrabbit 1.4 to 1.5 and found following error, that is critical for my app.
      Project uses Import/Export features of JCR and JAXB to map XML from JCR to java objects.

      exportDocumentView() works with streams when I call it like this:

      Unmarshaller umr = getUnmarshaller();
      ...
      fo = new FileOutputStream("/tmp/export-node.xml");
      jcrs.exportDocumentView(path,fo , false, false);
      fi = new FileInputStream("/tmp/export-node.xml");
      umr.unmarshal(new InputSource(fi));

      But it does not work when I call it using SAX event handler:

      UnmarshallerHandler ctxh = umr.getUnmarshallerHandler();
      jcrs.exportDocumentView(path, ctxh, false, false);

      giving following exception:

      java.lang.NullPointerException
      at org.xml.sax.helpers.AttributesImpl.getIndex(AttributesImpl.java:203)
      at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor$AttributesImpl.getIndex(InterningXmlVisitor.java:112)
      at com.sun.xml.bind.v2.runtime.unmarshaller.XsiNilLoader.selectLoader(XsiNilLoader.java:62)
      at com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:53)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:449)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:427)
      at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
      at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
      at org.apache.jackrabbit.commons.xml.Exporter.startElement(Exporter.java:438)
      at org.apache.jackrabbit.commons.xml.DocumentViewExporter.exportNode(DocumentViewExporter.java:76)
      at org.apache.jackrabbit.commons.xml.Exporter.exportNode(Exporter.java:298)
      at org.apache.jackrabbit.commons.xml.Exporter.exportNodes(Exporter.java:214)
      at org.apache.jackrabbit.commons.xml.DocumentViewExporter.exportNode(DocumentViewExporter.java:77)
      at org.apache.jackrabbit.commons.xml.Exporter.exportNode(Exporter.java:298)
      at org.apache.jackrabbit.commons.xml.Exporter.exportNodes(Exporter.java:214)
      at org.apache.jackrabbit.commons.xml.DocumentViewExporter.exportNode(DocumentViewExporter.java:77)
      at org.apache.jackrabbit.commons.xml.Exporter.exportNode(Exporter.java:298)
      at org.apache.jackrabbit.commons.xml.Exporter.export(Exporter.java:144)
      at org.apache.jackrabbit.commons.AbstractSession.export(AbstractSession.java:461)
      at org.apache.jackrabbit.commons.AbstractSession.exportDocumentView(AbstractSession.java:241)
      at ua.org.dg.semaril.helpers.AbstractTypeResolver.getContent(AbstractTypeResolver.java:31

      Version 1.4. works fine.

      Jukka, please check your changes to org.apache.jackrabbit.commons.xml.Exporter.

        Activity

        Hide
        Alex Lukin added a comment -

        I checked it with native java 1.6 jaxb implementation, result is the same.

        Show
        Alex Lukin added a comment - I checked it with native java 1.6 jaxb implementation, result is the same.
        Hide
        Alex Lukin added a comment -

        I found that NPE is caused by namespace with empty prefix and empty uri. This namespace exists even in newly created repository.

        Code to discover it:
        String[] nsp = ses.getNamespacePrefixes();
        for (String ns : nsp)

        { System.out.println( "namespace: " + ns + " uri: " + ses.getNamespaceURI(ns)); }
        Show
        Alex Lukin added a comment - I found that NPE is caused by namespace with empty prefix and empty uri. This namespace exists even in newly created repository. Code to discover it: String[] nsp = ses.getNamespacePrefixes(); for (String ns : nsp) { System.out.println( "namespace: " + ns + " uri: " + ses.getNamespaceURI(ns)); }
        Hide
        Jukka Zitting added a comment -

        I looked at this and I think I found the cause of the problem. In the Exported class I used null instead of the correct empty string for the default namespace. The normal JAXP libraries seem to accept both cases, but JAXB apparently does not.

        I committed a fix to trunk in revision 718566. Can you check whether this fix works for you? If yes, I'll get it included in 1.5.

        Show
        Jukka Zitting added a comment - I looked at this and I think I found the cause of the problem. In the Exported class I used null instead of the correct empty string for the default namespace. The normal JAXP libraries seem to accept both cases, but JAXB apparently does not. I committed a fix to trunk in revision 718566. Can you check whether this fix works for you? If yes, I'll get it included in 1.5.
        Hide
        Alex Lukin added a comment -

        Thak you very much, my app works as it should. I just moved file from trunk to 1.5 branch, compiled commons and replaced in my app libs. Everything works fine. Pleas include this fix in 1.5 release.

        Show
        Alex Lukin added a comment - Thak you very much, my app works as it should. I just moved file from trunk to 1.5 branch, compiled commons and replaced in my app libs. Everything works fine. Pleas include this fix in 1.5 release.
        Hide
        Jukka Zitting added a comment -

        Merged to the 1.5 branch in revision 719573. Thanks for the help!

        Show
        Jukka Zitting added a comment - Merged to the 1.5 branch in revision 719573. Thanks for the help!

          People

          • Assignee:
            Jukka Zitting
            Reporter:
            Alex Lukin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3h
              3h
              Remaining:
              Remaining Estimate - 3h
              3h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development