use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class PermissionsFunctionChmodTest method cleanupDb.
@AfterClass
public static void cleanupDb() throws EXistException, PermissionDeniedException, IOException, TriggerException {
final BrokerPool pool = existWebServer.getBrokerPool();
final SecurityManager sm = pool.getSecurityManager();
try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
removeUser(sm, USER2_NAME);
removeUser(sm, USER1_NAME);
removeCollection(broker, transaction, TestConstants.TEST_COLLECTION_URI);
transaction.commit();
}
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class AccountManagementFunctionRemoveAccountTest method xqueryRemoveAccount.
private Sequence xqueryRemoveAccount(final String username, final Optional<Subject> asUser) throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = existWebServer.getBrokerPool();
final String query = "import module namespace sm = 'http://exist-db.org/xquery/securitymanager';\n" + "sm:remove-account('" + username + "')";
try (final DBBroker broker = pool.get(asUser)) {
final XQuery xquery = existWebServer.getBrokerPool().getXQueryService();
final Sequence result = xquery.execute(broker, query, null);
return result;
}
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class Util method withCompiledQuery.
static <T> T withCompiledQuery(final DBBroker broker, final Source source, final Function2E<CompiledXQuery, T, XPathException, PermissionDeniedException> op) throws XPathException, PermissionDeniedException, IOException {
final BrokerPool pool = broker.getBrokerPool();
final XQuery xqueryService = pool.getXQueryService();
final XQueryPool xqueryPool = pool.getXQueryPool();
final CompiledXQuery compiledQuery = compileQuery(broker, xqueryService, xqueryPool, source);
try {
return op.apply(compiledQuery);
} finally {
if (compiledQuery != null) {
xqueryPool.returnCompiledXQuery(source, compiledQuery);
}
}
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class SendEmailIT method sendEmailJavaMail.
@Test
public void sendEmailJavaMail() throws EXistException, XPathException, PermissionDeniedException, IOException, MessagingException {
final String from = "sender@place1.com";
final String to = "recipient@place2.com";
final String subject = "some email subject";
final String messageText = UUIDGenerator.getUUIDversion4();
final String query = "import module namespace mail = \"http://exist-db.org/xquery/mail\";\n" + "let $session := mail:get-mail-session(\n" + " <properties>\n" + " <property name=\"mail.transport.protocol\" value=\"smtp\"/>\n" + " <property name=\"mail.smtp.port\" value=\"" + smtpPort + "\"/>\n" + " <property name=\"mail.smtp.host\" value=\"127.0.0.1\"/>\n" + " </properties>\n" + ")\n" + "return\n" + " mail:send-email(\n" + " $session,\n" + " <mail><from>" + from + "</from><to>" + to + "</to><subject>" + subject + "</subject><message><text>" + messageText + "</text></message></mail>\n" + " )";
// send the email from XQuery via SMTP
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final Source source = new StringSource(query);
try (final DBBroker broker = pool.getBroker();
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
// execute query
final Boolean sendResult = withCompiledQuery(broker, source, compiledXQuery -> {
executeQuery(broker, compiledXQuery);
return true;
});
transaction.commit();
assertTrue(sendResult.booleanValue());
}
// check the SMTP server received the email
final MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertEquals(1, receivedMessages.length);
final MimeMessage receivedMessage = receivedMessages[0];
// final Address sender = receivedMessage.getSender();
// assertEquals(from, sender.toString());
final Address[] recipients = receivedMessage.getRecipients(Message.RecipientType.TO);
assertEquals(1, recipients.length);
assertEquals(to, recipients[0].toString());
assertEquals(subject, receivedMessage.getSubject());
assertEquals(messageText, GreenMailUtil.getBody(receivedMessage));
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class SendEmailIT method sendEmailSmtpDirect.
@Test
public void sendEmailSmtpDirect() throws EXistException, XPathException, PermissionDeniedException, IOException, MessagingException {
final String from = "sender@place1.com";
final String to = "recipient@place2.com";
final String subject = "some email subject";
final String messageText = UUIDGenerator.getUUIDversion4();
final String query = "import module namespace mail = \"http://exist-db.org/xquery/mail\";\n" + "mail:send-email(\n" + " <mail><from>" + from + "</from><to>" + to + "</to><subject>" + subject + "</subject><message><text>" + messageText + "</text></message></mail>,\n" + " '127.0.0.1:" + smtpPort + "',\n" + " ()\n" + ")";
// send the email from XQuery via SMTP
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final Source source = new StringSource(query);
try (final DBBroker broker = pool.getBroker();
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
// execute query
final Boolean sendResult = withCompiledQuery(broker, source, compiledXQuery -> {
final Sequence result = executeQuery(broker, compiledXQuery);
return result.itemAt(0).toJavaObject(boolean.class);
});
transaction.commit();
assertTrue(sendResult.booleanValue());
}
// check the SMTP server received the email
final MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertEquals(1, receivedMessages.length);
final MimeMessage receivedMessage = receivedMessages[0];
// final Address sender = receivedMessage.getSender();
// assertEquals(from, sender.toString());
final Address[] recipients = receivedMessage.getRecipients(Message.RecipientType.TO);
assertEquals(1, recipients.length);
assertEquals(to, recipients[0].toString());
assertEquals(subject, receivedMessage.getSubject());
assertEquals(messageText, GreenMailUtil.getBody(receivedMessage));
}
Aggregations