Search in sources :

Example 16 with UserException

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());
    }
}
Also used : UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 17 with UserException

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());
    }
}
Also used : Message(com.dexels.navajo.document.Message) UserException(com.dexels.navajo.script.api.UserException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) NavajoException(com.dexels.navajo.document.NavajoException)

Example 18 with UserException

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;
    }
}
Also used : Message(com.dexels.navajo.document.Message) UserException(com.dexels.navajo.script.api.UserException)

Example 19 with UserException

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);
    }
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) InternetAddress(javax.mail.internet.InternetAddress) MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) MessagingException(javax.mail.MessagingException) AttachmentMapInterface(com.dexels.navajo.adapter.mailmap.AttachmentMapInterface) DataHandler(javax.activation.DataHandler) BinaryDataSource(com.dexels.navajo.datasource.BinaryDataSource) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) AddressException(javax.mail.internet.AddressException) FileDataSource(javax.activation.FileDataSource) UserException(com.dexels.navajo.script.api.UserException) Binary(com.dexels.navajo.document.types.Binary) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 20 with UserException

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());
    }
}
Also used : Access(com.dexels.navajo.script.api.Access) UserException(com.dexels.navajo.script.api.UserException) Date(java.util.Date) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

UserException (com.dexels.navajo.script.api.UserException)113 MappableException (com.dexels.navajo.script.api.MappableException)54 IOException (java.io.IOException)33 NavajoException (com.dexels.navajo.document.NavajoException)25 Message (com.dexels.navajo.document.Message)22 SQLException (java.sql.SQLException)19 SystemException (com.dexels.navajo.script.api.SystemException)18 Binary (com.dexels.navajo.document.types.Binary)14 ConditionErrorException (com.dexels.navajo.server.ConditionErrorException)13 Property (com.dexels.navajo.document.Property)12 ArrayList (java.util.ArrayList)12 Navajo (com.dexels.navajo.document.Navajo)11 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)11 ResultSet (java.sql.ResultSet)11 MappingException (com.dexels.navajo.script.api.MappingException)10 ResultSetMetaData (java.sql.ResultSetMetaData)9 Element (org.w3c.dom.Element)8 CompilationException (com.dexels.navajo.script.api.CompilationException)7 File (java.io.File)7 NodeList (org.w3c.dom.NodeList)7