Search in sources :

Example 96 with RepositoryException

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

the class RetentionPolicyTest method testSetInvalidRetentionPolicy.

public void testSetInvalidRetentionPolicy() {
    try {
        RetentionPolicy invalidRPolicy = new RetentionPolicy() {

            public String getName() throws RepositoryException {
                return "anyName";
            }
        };
        retentionMgr.setRetentionPolicy(testNodePath, invalidRPolicy);
        fail("Setting an invalid retention policy must fail.");
    } catch (RepositoryException e) {
    // success
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) RetentionPolicy(javax.jcr.retention.RetentionPolicy)

Example 97 with RepositoryException

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

the class AccessManagerTest method testCanReadNewId.

public void testCanReadNewId() throws Exception {
    Session s = getHelper().getReadOnlySession();
    try {
        NodeImpl n = (NodeImpl) testRootNode.addNode(nodeName1);
        PropertyImpl p = (PropertyImpl) n.setProperty(propertyName1, "somevalue");
        try {
            AccessManager acMgr = getAccessManager(s);
            acMgr.canRead(null, n.getId());
            fail("expected repositoryexception");
        } catch (RepositoryException e) {
        // success
        }
        try {
            AccessManager acMgr = getAccessManager(s);
            acMgr.canRead(null, p.getId());
            fail("expected repositoryexception");
        } catch (RepositoryException e) {
        // success
        }
    } finally {
        s.logout();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 98 with RepositoryException

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

the class CachingDataStore method init.

/**
     * Initialized the data store. If the path is not set, <repository
     * home>/repository/datastore is used. This directory is automatically
     * created if it does not yet exist. During first initialization, it upload
     * all files from local datastore to backed and local datastore act as a
     * local cache.
     */
@Override
public void init(String homeDir) throws RepositoryException {
    try {
        if (path == null) {
            path = homeDir + "/repository/datastore";
        }
        // create tmp inside path
        tmpDir = new File(path, "tmp");
        LOG.info("path=[{}],  tmpPath=[{}]", path, tmpDir.getAbsolutePath());
        directory = new File(path);
        mkdirs(directory);
        mkdirs(new File(homeDir));
        if (!mkdirs(tmpDir)) {
            FileUtils.cleanDirectory(tmpDir);
            LOG.info("tmp=[{}] cleaned.", tmpDir.getPath());
        }
        boolean asyncWriteCacheInitStatus = true;
        try {
            asyncWriteCache = new AsyncUploadCache();
            asyncWriteCache.init(homeDir, path, asyncUploadLimit);
        } catch (Exception e) {
            LOG.warn("Failed to initialize asyncWriteCache", e);
            asyncWriteCacheInitStatus = false;
        }
        backend = createBackend();
        backend.init(this, path, config);
        String markerFileName = getMarkerFile();
        if (markerFileName != null && !"".equals(markerFileName.trim())) {
            // create marker file in homeDir to avoid deletion in cache
            // cleanup.
            File markerFile = new File(homeDir, markerFileName);
            if (!markerFile.exists()) {
                LOG.info("load files from local cache");
                uploadFilesFromCache();
                try {
                    markerFile.createNewFile();
                } catch (IOException e) {
                    throw new DataStoreException("Could not create marker file " + markerFile.getAbsolutePath(), e);
                }
            } else {
                LOG.info("marker file = [{}] exists ", markerFile.getAbsolutePath());
                if (!asyncWriteCacheInitStatus) {
                    LOG.info("Initialization of asyncWriteCache failed. " + "Re-loading all files from local cache");
                    uploadFilesFromCache();
                    asyncWriteCache.reset();
                }
            }
        } else {
            throw new DataStoreException("Failed to intialized DataStore." + " MarkerFileName is null or empty. ");
        }
        // upload any leftover async uploads to backend during last shutdown
        Set<String> fileList = asyncWriteCache.getAll();
        if (fileList != null && !fileList.isEmpty()) {
            List<String> errorFiles = new ArrayList<String>();
            LOG.info("Uploading [{}] and size=[{}] from AsyncUploadCache.", fileList, fileList.size());
            long totalSize = 0;
            List<File> files = new ArrayList<File>(fileList.size());
            for (String fileName : fileList) {
                File f = new File(path, fileName);
                if (!f.exists()) {
                    errorFiles.add(fileName);
                    LOG.error("Cannot upload pending file [{}]. File doesn't exist.", f.getAbsolutePath());
                } else {
                    totalSize += f.length();
                    files.add(new File(path, fileName));
                }
            }
            new FilesUploader(files, totalSize, concurrentUploadsThreads, true).upload();
            if (!continueOnAsyncUploadFailure && errorFiles.size() > 0) {
                LOG.error("Pending uploads of files [{}] failed. Files do not exist in Local cache.", errorFiles);
                LOG.error("To continue set [continueOnAsyncUploadFailure] " + "to true in Datastore configuration in " + "repository.xml. There would be inconsistent data " + "in repository due the missing files. ");
                throw new RepositoryException("Cannot upload async uploads from local cache. Files not found.");
            } else {
                if (errorFiles.size() > 0) {
                    LOG.error("Pending uploads of files [{}] failed. Files do" + " not exist in Local cache. Continuing as " + "[continueOnAsyncUploadFailure] is set to true.", errorFiles);
                }
                LOG.info("Reseting AsyncWrite Cache list.");
                asyncWriteCache.reset();
            }
        }
        downloadExecService = Executors.newFixedThreadPool(5, new NamedThreadFactory("backend-file-download-worker"));
        cache = new LocalCache(path, tmpDir.getAbsolutePath(), cacheSize, cachePurgeTrigFactor, cachePurgeResizeFactor, asyncWriteCache);
        /*
             * Initialize LRU cache of size {@link #recLengthCacheSize}
             */
        recLenCache = Collections.synchronizedMap(new LinkedHashMap<DataIdentifier, Long>(recLengthCacheSize, 0.75f, true) {

            private static final long serialVersionUID = -8752749075395630485L;

            @Override
            protected boolean removeEldestEntry(Map.Entry<DataIdentifier, Long> eldest) {
                if (size() > recLengthCacheSize) {
                    LOG.trace("evicted from recLengthCache [{}]", eldest.getKey());
                    return true;
                }
                return false;
            }
        });
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : NamedThreadFactory(org.apache.jackrabbit.core.data.util.NamedThreadFactory) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LinkedHashMap(java.util.LinkedHashMap) File(java.io.File)

Example 99 with RepositoryException

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

the class DbDataStore method initDatabaseType.

protected void initDatabaseType() throws DataStoreException {
    boolean failIfNotFound = false;
    if (databaseType == null) {
        if (dataSourceName != null) {
            try {
                databaseType = connectionFactory.getDataBaseType(dataSourceName);
            } catch (RepositoryException e) {
                throw new DataStoreException(e);
            }
        } else {
            if (!url.startsWith("jdbc:")) {
                return;
            }
            int start = "jdbc:".length();
            int end = url.indexOf(':', start);
            databaseType = url.substring(start, end);
        }
    } else {
        failIfNotFound = true;
    }
    InputStream in = DbDataStore.class.getResourceAsStream(databaseType + ".properties");
    if (in == null) {
        if (failIfNotFound) {
            String msg = "Configuration error: The resource '" + databaseType + ".properties' could not be found;" + " Please verify the databaseType property";
            log.debug(msg);
            throw new DataStoreException(msg);
        } else {
            return;
        }
    }
    Properties prop = new Properties();
    try {
        try {
            prop.load(in);
        } finally {
            in.close();
        }
    } catch (IOException e) {
        String msg = "Configuration error: Could not read properties '" + databaseType + ".properties'";
        log.debug(msg);
        throw new DataStoreException(msg, e);
    }
    if (driver == null) {
        driver = getProperty(prop, "driver", driver);
    }
    tableSQL = getProperty(prop, "table", tableSQL);
    createTableSQL = getProperty(prop, "createTable", createTableSQL);
    insertTempSQL = getProperty(prop, "insertTemp", insertTempSQL);
    updateDataSQL = getProperty(prop, "updateData", updateDataSQL);
    updateLastModifiedSQL = getProperty(prop, "updateLastModified", updateLastModifiedSQL);
    updateSQL = getProperty(prop, "update", updateSQL);
    deleteSQL = getProperty(prop, "delete", deleteSQL);
    deleteOlderSQL = getProperty(prop, "deleteOlder", deleteOlderSQL);
    selectMetaSQL = getProperty(prop, "selectMeta", selectMetaSQL);
    selectAllSQL = getProperty(prop, "selectAll", selectAllSQL);
    selectDataSQL = getProperty(prop, "selectData", selectDataSQL);
    storeStream = getProperty(prop, "storeStream", storeStream);
    if (!STORE_SIZE_MINUS_ONE.equals(storeStream) && !STORE_TEMP_FILE.equals(storeStream) && !STORE_SIZE_MAX.equals(storeStream)) {
        String msg = "Unsupported Stream store mechanism: " + storeStream + " supported are: " + STORE_SIZE_MINUS_ONE + ", " + STORE_TEMP_FILE + ", " + STORE_SIZE_MAX;
        log.debug(msg);
        throw new DataStoreException(msg);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 100 with RepositoryException

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

the class ExportDocViewTest method readDocument.

/**
     * Reads a DOM document from the given XML stream.
     *
     * @param xml XML stream
     * @return DOM document
     * @throws RepositoryException if the document could not be read
     */
private Document readDocument(InputStream xml) throws RepositoryException {
    try {
        StreamSource source = new StreamSource(xml);
        DOMResult result = new DOMResult();
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.transform(source, result);
        return (Document) result.getNode();
    } catch (TransformerException e) {
        throw new RepositoryException("Unable to read xml file", e);
    }
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamSource(javax.xml.transform.stream.StreamSource) RepositoryException(javax.jcr.RepositoryException) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException)

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