use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class XMLStreamMap method setStartElement.
public void setStartElement(String name) throws UserException {
try {
indent();
xtw.writeStartElement(docSpecUrl, name);
current_indentation += indent;
newLineFlag = false;
} catch (Exception e) {
throw new UserException(452, e.getMessage());
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class MessageMap method getMessages.
public MessageMap[] getMessages() throws UserException {
try {
List<Message> all = msg.getMessages(messagePointer);
if ((all == null))
throw new UserException(-1, "Could not find messages: " + messagePointer + " in response document (" + msg.getName() + ")");
messages = new MessageMap[all.size()];
for (int i = 0; i < all.size(); i++) {
MessageMap m = new MessageMap();
m.setMsg(all.get(i));
messages[i] = m;
}
return messages;
} catch (Exception e) {
throw new UserException(-1, e.getMessage());
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class MessageMap method getMessage.
public MessageMap getMessage() throws UserException {
Message m = msg.getMessage(messagePointer);
if (m == null)
throw new UserException(-1, "Could not find message: " + messagePointer + " in response document (" + msg.getName() + ")");
else {
MessageMap mm = new MessageMap();
mm.setMsg(m);
return mm;
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class ResourceComponent method send.
@Override
public void send(String from, String[] to, String[] cc, String[] bcc, String subject, String body, List<AttachmentMapInterface> attachments, String contentType, boolean relatedMultipart) throws UserException {
javax.mail.Message msg = new MimeMessage(session);
if (from == null || "".equals(from)) {
throw new UserException(-1, "Error: Required sender address not set!");
}
try {
msg.setFrom(new InternetAddress(from));
InternetAddress[] addresses = new InternetAddress[to.length];
for (int i = 0; i < to.length; i++) {
addresses[i] = new InternetAddress(to[i]);
}
msg.setRecipients(javax.mail.Message.RecipientType.TO, addresses);
if (cc != null) {
InternetAddress[] extra = new InternetAddress[cc.length];
for (int i = 0; i < cc.length; i++) {
extra[i] = new InternetAddress(cc[i]);
}
msg.setRecipients(javax.mail.Message.RecipientType.CC, extra);
}
if (bcc != null) {
InternetAddress[] extra = new InternetAddress[bcc.length];
for (int i = 0; i < bcc.length; i++) {
extra[i] = new InternetAddress(bcc[i]);
}
msg.setRecipients(javax.mail.Message.RecipientType.BCC, extra);
}
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());
if (attachments == null && contentType.equals("text/plain")) {
msg.setText(body);
} else {
Multipart multipart = (relatedMultipart ? new MimeMultipart("related") : new MimeMultipart());
BodyPart textBody = new MimeBodyPart();
textBody.setContent(body, contentType);
multipart.addBodyPart(textBody);
if (attachments != null) {
for (int i = 0; i < attachments.size(); i++) {
AttachmentMapInterface am = attachments.get(i);
String file = am.getAttachFile();
String userFileName = am.getAttachFileName();
Binary content = am.getAttachFileContent();
String encoding = am.getEncoding();
MimeBodyPart bp = new MimeBodyPart();
if (file != null) {
if (userFileName == null) {
userFileName = file;
}
FileDataSource fileDatasource = new FileDataSource(file);
bp.setDataHandler(new DataHandler(fileDatasource));
} else if (content != null) {
BinaryDataSource bds = new BinaryDataSource(content, "");
DataHandler dh = new DataHandler(bds);
bp.setDataHandler(dh);
if (encoding != null) {
bp.setHeader("Content-Transfer-Encoding", encoding);
encoding = null;
}
}
bp.setFileName(userFileName);
if (relatedMultipart) {
bp.setHeader("Content-ID", "<attach-nr-" + i + ">");
}
// iPhone headers
// bp.setDisposition("attachment");
bp.setDisposition(am.getAttachContentDisposition());
multipart.addBodyPart(bp);
}
}
msg.setContent(multipart);
}
Transport.send(msg);
} catch (AddressException e) {
throw new UserException("Error sending mail:", e);
} catch (MessagingException e) {
throw new UserException("Error sending mail:", e);
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class TestMailResource method testSimple.
@Test
@Ignore
public void testSimple() throws MappableException {
ResourceMailAdapter rma = new ResourceMailAdapter();
try {
rma.load(new Access());
rma.setRecipients("dexels@gmail.com");
rma.setSender("dexels@gmail.com");
rma.setSubject("Mail at " + new Date());
rma.setResourceName("junit.mail");
rma.store();
} catch (UserException e) {
Assert.assertEquals("javax.mail.AuthenticationFailedException", e.getCause().toString());
}
}
Aggregations