javajcrjackrabbit

Can't load Nodetypes in JackRabbit through RMI


I'm trying to load a CND file with the definition of some custom nodetypes. The file looks like this

<ca = 'http://www.stuff.com/training'>
[ca:article]
- ca:headline (string)
mandatory
- ca:body (string)
mandatory

Here's the class to load the nodetypes

public class JcrRegisterNodeTypes {

    public static void RegisterCustomNodeTypes(Session session, String cndFileName){

        NodeType[] nodeTypes;
        try {
            File file = new File(cndFileName);
            FileReader fr = new FileReader(file);
            nodeTypes = CndImporter.registerNodeTypes(fr, session);
            for (NodeType nt : nodeTypes) {
                System.out.println("Registered: " + nt.getName());
            }
        } catch (InvalidNodeTypeDefinitionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NodeTypeExistsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedRepositoryOperationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RepositoryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Then "parse exception" is raised, with this message

10:37:23,052 ERROR [stderr] (default task-48) org.apache.jackrabbit.commons.cnd.ParseException: javax.jcr.UnsupportedRepositoryOperationException: TODO: JCR-3206 (cnd input stream, line 2)

It seems that the method is not implemented for RMI. Is there an alternative method to generate the /node types/custom_node_types.xml?


I've deployed jackrabbit-webapp-2.18.4.war over WildFly 14 and i can upload/download files, so i think the installation is running ok.

The jars included on the project are the last stable release

jackrabbit-api-2.18.4.jar jackrabbit-core-2.18.4.jar jackrabbit-jcr-commons-2.18.4.jar jackrabbit-jcr-rmi-2.18.4.jar jcr-2.0.jar


Solution

  • So, i've follow Julian's recommendation and tried to modify NodeTypes directly on the server.

    The method CndImporter.registerNodeTypes(fr, session) transforms a CND file into a custom_nodetypes.xml file. This XML file is read by the repository manager when it loads. The syntax of CND and XML is different, but it's easy to figure out how to go from one to another.

    I've created manually an xml based on

    https://github.com/onehippo/essentials/blob/master/plugin-sdk/implementation/src/test/resources/custom_nodetypes.xml

    I've changed the namespace tag of the xml ( xmlns:ocm="http://jackrabbit.apache.org/ocm" ) and add it manually to the namespaces/ns_reg.properties

    After that, i've started the server and solved a few typos and it finally started. I've coded this little method to check it out and it seems to be ok.

    public void showNodeTypes(){
    
            NodeTypeManager manager;
            try {
                manager = (NodeTypeManager)jcrSession.getWorkspace().getNodeTypeManager();
    
                NodeTypeIterator nodeTypeIterator = manager.getAllNodeTypes();
                NodeType actual;
    
                while (nodeTypeIterator.hasNext()){
                    System.out.println("----------------");
                    actual= (NodeType)nodeTypeIterator.next();
                    System.out.println(actual.getName());
                    for(PropertyDefinition propertyDef:actual.getPropertyDefinitions()) {
                        System.out.println(propertyDef.getName() +" --> Mandatory: " + propertyDef.isMandatory());
                    }
                }
    
            } catch (RepositoryException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
    

    This is the custom_nodetypes.xml i've used

    <?xml version="1.0" encoding="UTF-8"?>
    <nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
               xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
               xmlns:spi="http://www.example.ad/spi">
    
      <nodeType name="spi:cmsobjectimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
        <supertypes>
          <supertype>nt:base</supertype>
        </supertypes>
        <propertyDefinition name="spi:name" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
      </nodeType>
    
     <nodeType name="spi:contentimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
        <supertypes>
          <supertype>spi:cmsobjectimpl</supertype>
        </supertypes>
      </nodeType>
    
     <nodeType name="spi:documentstream" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
        <supertypes>
          <supertype>mix:versionable</supertype>
          <supertype>nt:base</supertype>
        </supertypes>
        <propertyDefinition name="spi:encoding" requiredType="String"               autoCreated="false" mandatory="true"    onParentVersion="COPY" protected="false" multiple="false"/>
        <propertyDefinition name="spi:binarycontent" requiredType="Binary"          autoCreated="false" mandatory="true"    onParentVersion="COPY" protected="false" multiple="false"/> 
      </nodeType>
    
      <nodeType name="spi:Expedient" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
        <supertypes>
          <supertype>spi:contentimpl</supertype>
        </supertypes>
        <propertyDefinition name="spi:contenttype" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
        <propertyDefinition name="spi:size" requiredType="Long" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
        <propertyDefinition name="spi:numExpedient" requiredType="Long"             autocreated="true"  mandatory="true"    onParentVersion="COPY" protected="false" multiple="false"/>
        <childNodeDefinition name="*" defaultPrimaryType="spi:documentstream" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="false">
          <requiredPrimaryTypes>
            <requiredPrimaryType>spi:documentstream</requiredPrimaryType>
          </requiredPrimaryTypes>
        </childNodeDefinition>
      </nodeType>
    
    </nodeTypes>