use of org.exist.EXistException in project exist by eXist-db.
the class XQueryURLRewrite method configure.
private void configure() throws ServletException {
if (pool != null) {
return;
}
try {
final Class<?> driver = Class.forName(DRIVER);
final Database database = (Database) driver.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);
if (LOG.isDebugEnabled()) {
LOG.debug("Initialized database");
}
} catch (final Exception e) {
final String errorMessage = "Failed to initialize database driver";
LOG.error(errorMessage, e);
throw new ServletException(errorMessage + ": " + e.getMessage(), e);
}
try {
pool = BrokerPool.getInstance();
} catch (final EXistException e) {
throw new ServletException("Could not initialize db: " + e.getMessage(), e);
}
defaultUser = pool.getSecurityManager().getGuestSubject();
final String username = config.getInitParameter("user");
if (username != null) {
final String password = config.getInitParameter("password");
try {
final Subject user = pool.getSecurityManager().authenticate(username, password);
if (user != null && user.isAuthenticated()) {
defaultUser = user;
}
} catch (final AuthenticationException e) {
LOG.error("User can not be authenticated ({}), using default user.", username);
}
}
authenticator = new BasicAuthenticator(pool);
}
use of org.exist.EXistException in project exist by eXist-db.
the class FileLockService method prepare.
@Override
public void prepare(final BrokerPool brokerPool) throws BrokerPoolServiceException {
// try to acquire lock on the data dir
final FileLock fileLock = new FileLock(brokerPool, dataDir.resolve(lockFileName));
this.dataLock.compareAndSet(null, fileLock);
try {
final boolean locked = fileLock.tryLock();
if (!locked) {
throw new BrokerPoolServiceException(new EXistException("The directory seems to be locked by another " + "database instance. Found a valid lock file: " + fileLock.getFile().toAbsolutePath().toString()));
}
} catch (final ReadOnlyException e) {
LOG.warn(e);
writable = false;
}
if (!writable) {
brokerPool.setReadOnly();
}
}
use of org.exist.EXistException in project exist by eXist-db.
the class JournalManager method prepare.
@Override
public synchronized void prepare(final BrokerPool pool) throws BrokerPoolServiceException {
if (!journallingDisabled) {
try {
this.journal = new Journal(pool, journalDir);
this.journal.initialize();
this.initialized = true;
} catch (final EXistException | ReadOnlyException e) {
throw new BrokerPoolServiceException(e);
}
}
}
use of org.exist.EXistException in project exist by eXist-db.
the class RpcConnection method describeResource.
private Map<String, Object> describeResource(final XmldbURI resourceUri) throws EXistException, PermissionDeniedException {
try {
return this.<Map<String, Object>>readDocument(resourceUri).apply((document, broker, transaction) -> {
final Map<String, Object> hash = new HashMap<>(11);
final Permission perms = document.getPermissions();
hash.put("name", resourceUri.toString());
hash.put("owner", perms.getOwner().getName());
hash.put("group", perms.getGroup().getName());
hash.put("permissions", perms.getMode());
if (perms instanceof ACLPermission) {
hash.put("acl", getACEs(perms));
}
hash.put("type", document.getResourceType() == DocumentImpl.BINARY_FILE ? "BinaryResource" : "XMLResource");
final long resourceLength = document.getContentLength();
hash.put("content-length", (resourceLength > (long) Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) resourceLength);
hash.put("content-length-64bit", Long.toString(resourceLength));
hash.put("mime-type", document.getMimeType());
hash.put("created", new Date(document.getCreated()));
hash.put("modified", new Date(document.getLastModified()));
if (document.getResourceType() == DocumentImpl.BINARY_FILE) {
hash.put("blob-id", ((BinaryDocument) document).getBlobId().getId());
final MessageDigest messageDigest = broker.getBinaryResourceContentDigest(transaction, (BinaryDocument) document, DigestType.BLAKE_256);
hash.put("digest-algorithm", messageDigest.getDigestType().getCommonNames()[0]);
hash.put("digest", messageDigest.getValue());
}
return hash;
});
} catch (final EXistException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
return new HashMap<>();
}
}
use of org.exist.EXistException in project exist by eXist-db.
the class RpcConnection method getContentDigest.
@Override
public Map<String, Object> getContentDigest(final String path, final String digestAlgorithm) throws EXistException, PermissionDeniedException {
try {
final DigestType digestType = DigestType.forCommonName(digestAlgorithm);
final MessageDigest messageDigest = this.<MessageDigest>readDocument(XmldbURI.xmldbUriFor(path)).apply((document, broker, transaction) -> {
if (document instanceof BinaryDocument) {
return broker.getBinaryResourceContentDigest(transaction, (BinaryDocument) document, digestType);
} else {
throw new EXistException("Only supported for binary documents");
}
});
final Map<String, Object> result = new HashMap<>();
result.put("digest-algorithm", messageDigest.getDigestType().getCommonNames()[0]);
result.put("digest", messageDigest.getValue());
return result;
} catch (final IllegalArgumentException | URISyntaxException e) {
throw new EXistException(e);
}
}
Aggregations