Search in sources :

Example 61 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class XMLTestRunner method run.

@Override
public void run(final RunNotifier notifier) {
    try {
        final String pkgName = getClass().getPackage().getName().replace('.', '/');
        final Source query = new ClassLoaderSource(pkgName + "/xml-test-runner.xq");
        final List<java.util.function.Function<XQueryContext, Tuple2<String, Object>>> externalVariableDeclarations = Arrays.asList(context -> new Tuple2<>("doc", doc), context -> new Tuple2<>("id", Sequence.EMPTY_SEQUENCE), // set callback functions for notifying junit!
        context -> new Tuple2<>("test-ignored-function", new FunctionReference(new FunctionCall(context, new ExtTestIgnoredFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-started-function", new FunctionReference(new FunctionCall(context, new ExtTestStartedFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-failure-function", new FunctionReference(new FunctionCall(context, new ExtTestFailureFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-assumption-failed-function", new FunctionReference(new FunctionCall(context, new ExtTestAssumptionFailedFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-error-function", new FunctionReference(new FunctionCall(context, new ExtTestErrorFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-finished-function", new FunctionReference(new FunctionCall(context, new ExtTestFinishedFunction(context, getSuiteName(), notifier)))));
        // NOTE: at this stage EXIST_EMBEDDED_SERVER_CLASS_INSTANCE in XSuite will be usable
        final BrokerPool brokerPool = XSuite.EXIST_EMBEDDED_SERVER_CLASS_INSTANCE.getBrokerPool();
        executeQuery(brokerPool, query, externalVariableDeclarations);
    } catch (final DatabaseConfigurationException | IOException | EXistException | PermissionDeniedException | XPathException e) {
        // TODO(AR) what to do here?
        throw new RuntimeException(e);
    }
}
Also used : ClassLoaderSource(org.exist.source.ClassLoaderSource) XPathException(org.exist.xquery.XPathException) IOException(java.io.IOException) EXistException(org.exist.EXistException) ClassLoaderSource(org.exist.source.ClassLoaderSource) Source(org.exist.source.Source) InputSource(org.xml.sax.InputSource) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) FunctionReference(org.exist.xquery.value.FunctionReference) PermissionDeniedException(org.exist.security.PermissionDeniedException) FunctionCall(org.exist.xquery.FunctionCall) BrokerPool(org.exist.storage.BrokerPool)

Example 62 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class XQueryTestRunner method run.

@Override
public void run(final RunNotifier notifier) {
    try {
        final String pkgName = getClass().getPackage().getName().replace('.', '/');
        final Source query = new ClassLoaderSource(pkgName + "/xquery-test-runner.xq");
        final URI testModuleUri = path.toAbsolutePath().toUri();
        final String suiteName = getSuiteName();
        final List<java.util.function.Function<XQueryContext, Tuple2<String, Object>>> externalVariableDeclarations = Arrays.asList(context -> new Tuple2<>("test-module-uri", new AnyURIValue(testModuleUri)), // set callback functions for notifying junit!
        context -> new Tuple2<>("test-ignored-function", new FunctionReference(new FunctionCall(context, new ExtTestIgnoredFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-started-function", new FunctionReference(new FunctionCall(context, new ExtTestStartedFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-failure-function", new FunctionReference(new FunctionCall(context, new ExtTestFailureFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-assumption-failed-function", new FunctionReference(new FunctionCall(context, new ExtTestAssumptionFailedFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-error-function", new FunctionReference(new FunctionCall(context, new ExtTestErrorFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-finished-function", new FunctionReference(new FunctionCall(context, new ExtTestFinishedFunction(context, suiteName, notifier)))));
        // NOTE: at this stage EXIST_EMBEDDED_SERVER_CLASS_INSTANCE in XSuite will be usable
        final BrokerPool brokerPool = XSuite.EXIST_EMBEDDED_SERVER_CLASS_INSTANCE.getBrokerPool();
        executeQuery(brokerPool, query, externalVariableDeclarations);
    } catch (final DatabaseConfigurationException | IOException | EXistException | PermissionDeniedException | XPathException e) {
        // TODO(AR) what to do here?
        throw new RuntimeException(e);
    }
}
Also used : URI(java.net.URI) ClassLoaderSource(org.exist.source.ClassLoaderSource) Source(org.exist.source.Source) FileSource(org.exist.source.FileSource) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) FunctionReference(org.exist.xquery.value.FunctionReference) ClassLoaderSource(org.exist.source.ClassLoaderSource) AnyURIValue(org.exist.xquery.value.AnyURIValue) IOException(java.io.IOException) EXistException(org.exist.EXistException) java.util(java.util) PermissionDeniedException(org.exist.security.PermissionDeniedException) BrokerPool(org.exist.storage.BrokerPool)

Example 63 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class RpcConnection method backup.

@Override
public boolean backup(final String userbackup, final String password, final String destcollection, final String collection) throws EXistException, PermissionDeniedException {
    try {
        final Backup backup = new Backup(userbackup, password, Paths.get(destcollection + "-backup"), XmldbURI.xmldbUriFor(XmldbURI.EMBEDDED_SERVER_URI.toString() + collection));
        backup.backup(false, null);
    } catch (final URISyntaxException | IOException | SAXException | XMLDBException e) {
        throw new EXistException(e);
    }
    return true;
}
Also used : Backup(org.exist.backup.Backup) URISyntaxException(java.net.URISyntaxException) EXistException(org.exist.EXistException) SAXException(org.xml.sax.SAXException)

Example 64 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class RpcConnection method retrieve.

@Override
public byte[] retrieve(final int resultId, final int num, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
    final Charset encoding = getEncoding(parameters);
    final boolean compression = useCompression(parameters);
    final String xml = retrieveAsString(resultId, num, parameters);
    if (compression) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("retrieve with compression");
        }
        try {
            return Compressor.compress(xml.getBytes(encoding));
        } catch (final IOException ioe) {
            throw new EXistException(ioe);
        }
    } else {
        return xml.getBytes(encoding);
    }
}
Also used : Charset(java.nio.charset.Charset) EXistException(org.exist.EXistException)

Example 65 with EXistException

use of org.exist.EXistException in project exist by eXist-db.

the class RpcConnection method retrieveFirstChunk.

@Override
public Map<String, Object> retrieveFirstChunk(final int resultId, final int num, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
    final boolean compression = useCompression(parameters);
    return withDb((broker, transaction) -> {
        final QueryResult qr = factory.resultSets.getResult(resultId);
        if (qr == null) {
            throw new EXistException("result set unknown or timed out: " + resultId);
        }
        qr.touch();
        final Item item = qr.result.itemAt(num);
        if (item == null) {
            throw new EXistException("index out of range");
        }
        final Map<String, Object> result = new HashMap<>();
        final TemporaryFileManager temporaryFileManager = TemporaryFileManager.getInstance();
        final Path tempFile = temporaryFileManager.getTemporaryFile();
        if (compression && LOG.isDebugEnabled()) {
            LOG.debug("retrieveFirstChunk with compression");
        }
        try (final OutputStream os = compression ? new DeflaterOutputStream(new BufferedOutputStream(Files.newOutputStream(tempFile))) : new BufferedOutputStream(Files.newOutputStream(tempFile));
            final Writer writer = new OutputStreamWriter(os, getEncoding(parameters))) {
            if (Type.subTypeOf(item.getType(), Type.NODE)) {
                final NodeValue nodeValue = (NodeValue) item;
                for (final Map.Entry<Object, Object> entry : qr.serialization.entrySet()) {
                    parameters.put(entry.getKey().toString(), entry.getValue().toString());
                }
                serialize(broker, toProperties(parameters), saxSerializer -> saxSerializer.toSAX(nodeValue), writer);
            } else {
                writer.write(item.getStringValue());
            }
        } catch (final XPathException e) {
            throw new EXistException(e);
        }
        final byte[] firstChunk = getChunk(tempFile, 0);
        result.put("data", firstChunk);
        int offset = 0;
        if (Files.size(tempFile) > MAX_DOWNLOAD_CHUNK_SIZE) {
            offset = firstChunk.length;
            final int handle = factory.resultSets.add(new SerializedResult(tempFile));
            result.put("handle", Integer.toString(handle));
            result.put("supports-long-offset", Boolean.TRUE);
        } else {
            temporaryFileManager.returnTemporaryFile(tempFile);
        }
        result.put("offset", offset);
        return result;
    });
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) EXistException(org.exist.EXistException) TemporaryFileManager(org.exist.util.io.TemporaryFileManager) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) LockedDocumentMap(org.exist.storage.lock.LockedDocumentMap)

Aggregations

EXistException (org.exist.EXistException)218 PermissionDeniedException (org.exist.security.PermissionDeniedException)80 IOException (java.io.IOException)63 DBBroker (org.exist.storage.DBBroker)58 Txn (org.exist.storage.txn.Txn)46 XmldbURI (org.exist.xmldb.XmldbURI)42 Collection (org.exist.collections.Collection)41 SAXException (org.xml.sax.SAXException)32 LockException (org.exist.util.LockException)31 DocumentImpl (org.exist.dom.persistent.DocumentImpl)28 Subject (org.exist.security.Subject)23 XPathException (org.exist.xquery.XPathException)22 LockedDocument (org.exist.dom.persistent.LockedDocument)21 TriggerException (org.exist.collections.triggers.TriggerException)20 Path (java.nio.file.Path)19 URISyntaxException (java.net.URISyntaxException)18 BrokerPool (org.exist.storage.BrokerPool)18 TransactionManager (org.exist.storage.txn.TransactionManager)18 InputSource (org.xml.sax.InputSource)18 Sequence (org.exist.xquery.value.Sequence)17