Search in sources :

Example 36 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class NodeCorruptionTest method testCopyMultiSingleValue.

public void testCopyMultiSingleValue() throws Exception {
    Node root = superuser.getRootNode();
    String nodeName = "testCopyMulti" + System.currentTimeMillis();
    if (root.hasNode(nodeName)) {
        root.getNode(nodeName).remove();
        superuser.save();
    }
    Node test = root.addNode(nodeName);
    test.setProperty("x", "Hi");
    superuser.save();
    String wsp = superuser.getWorkspace().getName();
    String workspace2 = getAlternativeWorkspaceName();
    if (workspace2 == null) {
        throw new NotExecutableException();
    }
    Session s2 = getHelper().getSuperuserSession(workspace2);
    s2.getWorkspace().clone(wsp, "/" + nodeName, "/" + nodeName, true);
    Node test2 = s2.getRootNode().getNode(nodeName);
    test2.setProperty("x", (Value) null);
    test2.setProperty("x", new String[] {});
    s2.save();
    test.update(workspace2);
    try {
        Value[] values = test.getProperty("x").getValues();
        assertEquals(0, values.length);
    } catch (RepositoryException e) {
        // if we get here, it's a bug, as it is a multi-valued property now
        // anyway, let's see what happens if we try to read it as a single valued property
        test.getProperty("x").getValue();
        // even if that works: it's still a bug
        throw e;
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 37 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class AutoFixCorruptNode method testAutoFix.

public void testAutoFix() throws Exception {
    // new repository
    TransientRepository rep = new TransientRepository(new File(TEST_DIR));
    Session s = openSession(rep, false);
    Node root = s.getRootNode();
    // add nodes /test and /test/missing
    Node test = root.addNode("test");
    Node missing = test.addNode("missing");
    missing.addMixin("mix:referenceable");
    UUID id = UUID.fromString(missing.getIdentifier());
    s.save();
    s.logout();
    destroyBundle(id, "workspaces/default");
    // login and try the operation
    s = openSession(rep, false);
    test = s.getRootNode().getNode("test");
    // try to add a node with the same name
    try {
        test.addNode("missing");
        s.save();
    } catch (RepositoryException e) {
    // expected
    }
    s.logout();
    s = openSession(rep, true);
    test = s.getRootNode().getNode("test");
    // iterate over all child nodes fixes the corruption
    NodeIterator it = test.getNodes();
    while (it.hasNext()) {
        it.nextNode();
    }
    // try to add a node with the same name
    test.addNode("missing");
    s.save();
    // try to delete the parent node
    test.remove();
    s.save();
    s.logout();
    rep.shutdown();
    FileUtils.deleteDirectory(new File("repository"));
}
Also used : NodeIterator(javax.jcr.NodeIterator) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) UUID(java.util.UUID) File(java.io.File) Session(javax.jcr.Session)

Example 38 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class ClientSession method getImportContentHandler.

/** {@inheritDoc} */
public ContentHandler getImportContentHandler(final String path, final int mode) throws RepositoryException {
    // Check that the path exists
    getItem(path);
    try {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ContentHandler handler = SerializingContentHandler.getSerializer(buffer);
        return new DefaultContentHandler(handler) {

            public void endDocument() throws SAXException {
                super.endDocument();
                try {
                    remote.importXML(path, buffer.toByteArray(), mode);
                } catch (Exception e) {
                    throw new SAXException("XML import failed", e);
                }
            }
        };
    } catch (SAXException e) {
        throw new RepositoryException("XML serialization failed", e);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContentHandler(org.xml.sax.ContentHandler) TransformerException(javax.xml.transform.TransformerException) RepositoryException(javax.jcr.RepositoryException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) SAXException(org.xml.sax.SAXException) AccessControlException(java.security.AccessControlException) SAXException(org.xml.sax.SAXException)

Example 39 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class DefaultHandler method exportProperties.

public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException {
    if (!canExport(exportContext, isCollection)) {
        throw new RepositoryException("PropertyHandler " + getName() + " failed to export properties.");
    }
    Node cn = getContentNode(exportContext, isCollection);
    try {
        // export the properties common with normal I/O handling
        exportProperties(exportContext, isCollection, cn);
        // export all other properties as well
        PropertyIterator it = cn.getProperties();
        while (it.hasNext()) {
            Property p = it.nextProperty();
            String name = p.getName();
            PropertyDefinition def = p.getDefinition();
            if (def.isMultiple() || isDefinedByFilteredNodeType(def)) {
                log.debug("Skip property '" + name + "': not added to webdav property set.");
                continue;
            }
            if (JcrConstants.JCR_DATA.equals(name) || JcrConstants.JCR_MIMETYPE.equals(name) || JcrConstants.JCR_ENCODING.equals(name) || JcrConstants.JCR_LASTMODIFIED.equals(name)) {
                continue;
            }
            DavPropertyName davName = getDavName(name, p.getSession());
            exportContext.setProperty(davName, p.getValue().getString());
        }
        return true;
    } catch (IOException e) {
        // should not occur (log output see 'exportProperties')
        return false;
    }
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Property(javax.jcr.Property) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 40 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class DefaultHandler method exportContent.

/**
     * Retrieves the content node that will be used for exporting properties and
     * data and calls the corresponding methods.
     *
     * @param context the export context
     * @param isCollection <code>true</code> if collection
     * @see #exportProperties(ExportContext, boolean, Node)
     * @see #exportData(ExportContext, boolean, Node)
     */
public boolean exportContent(ExportContext context, boolean isCollection) throws IOException {
    if (!canExport(context, isCollection)) {
        throw new IOException(getName() + ": Cannot export " + context.getExportRoot());
    }
    try {
        Node contentNode = getContentNode(context, isCollection);
        exportProperties(context, isCollection, contentNode);
        if (context.hasStream()) {
            exportData(context, isCollection, contentNode);
        }
        // else: missing stream. ignore.
        return true;
    } catch (RepositoryException e) {
        // node must be asserted in the 'canExport' call.
        throw new IOException(e.getMessage());
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50