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);
}
}
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);
}
}
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;
}
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);
}
}
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;
});
}
Aggregations