Search in sources :

Example 21 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class POP3Adapter method findFolder.

protected Folder findFolder(String name, boolean createNonExisting) {
    connect();
    Folder folder = m_cachedFolders.get(name);
    if (folder == null) {
        try {
            Folder f = m_store.getFolder(name);
            if (f.exists()) {
                folder = f;
            } else if (createNonExisting) {
                f.create(Folder.HOLDS_FOLDERS | Folder.HOLDS_MESSAGES);
                folder = f;
            }
            if (folder != null) {
                folder.open(Folder.READ_WRITE);
                m_cachedFolders.put(name, folder);
            }
        } catch (MessagingException e) {
            throw new ProcessingException("could not open folder: " + name, e);
        }
    }
    return folder;
}
Also used : MessagingException(javax.mail.MessagingException) Folder(javax.mail.Folder) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 22 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class POP3Adapter method visitUnseenMessages.

public void visitUnseenMessages(String folderName, IPOP3MessageVisitor visitor) {
    connect();
    Folder folder = null;
    try {
        folder = findFolder(folderName);
        if (folder != null) {
            if (!folder.isOpen()) {
                folder.open(Folder.READ_WRITE);
            }
            int count = folder.getMessageCount();
            for (int i = 0; i < count; i++) {
                Message m = folder.getMessage(i + 1);
                if (!m.isSet(Flags.Flag.SEEN)) {
                    boolean ok = visitor.visit(m);
                    if (!ok) {
                        break;
                    }
                }
            }
            folder.close(true);
        }
    } catch (MessagingException e) {
        throw new ProcessingException("reading folder " + folderName, e);
    }
}
Also used : Message(javax.mail.Message) MessagingException(javax.mail.MessagingException) Folder(javax.mail.Folder) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 23 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class AbstractSMTPService method sendMessage.

@Override
public void sendMessage(MimeMessage message, Session session) {
    Transport transport = null;
    try {
        if (session == null) {
            session = createSession();
        }
        transport = session.getTransport(getProtocol());
        if (!StringUtility.isNullOrEmpty(getUsername())) {
            transport.connect(getHost(), getUsername(), getPassword());
        } else {
            transport.connect();
        }
        // subject prefix
        String subjectPrefix = getSubjectPrefix();
        if (!StringUtility.isNullOrEmpty(subjectPrefix)) {
            String subject = subjectPrefix + ((message.getSubject() != null) ? (message.getSubject()) : (""));
            message.setSubject(subject);
        }
        Address[] allRecipients = message.getAllRecipients();
        // check debug receiver
        String debugReceiverEmail = getDebugReceiverEmail();
        if (debugReceiverEmail != null) {
            allRecipients = new Address[] { BEANS.get(MailHelper.class).createInternetAddress(debugReceiverEmail) };
            LOG.debug("SMTP Service: debug receiver email set to: {}", debugReceiverEmail);
        }
        // from address
        Address[] fromAddresses = message.getFrom();
        if (fromAddresses == null || fromAddresses.length == 0) {
            String defaultFromEmail = getDefaultFromEmail();
            if (!StringUtility.isNullOrEmpty(defaultFromEmail)) {
                message.setFrom(BEANS.get(MailHelper.class).createInternetAddress(defaultFromEmail));
            }
        }
        if (allRecipients != null && allRecipients.length > 0) {
            transport.sendMessage(message, allRecipients);
            transport.close();
            transport = null;
        }
    } catch (Exception e) {
        throw new ProcessingException("cannot send Mime Message.", e);
    } finally {
        try {
            if (transport != null) {
                transport.close();
            }
        } catch (Exception e) {
            LOG.warn("Could not close transport", e);
        }
    }
}
Also used : Address(javax.mail.Address) Transport(javax.mail.Transport) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 24 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class AbstractSqlBookmarkStorageService method writeUserFolder.

@Override
protected void writeUserFolder(BookmarkFolder folder, Object userId) {
    try {
        byte[] data = SerializationUtility.createObjectSerializer().serialize(folder);
        execStoreUserBookmarkFolder(userId, folder.getId(), data);
    } catch (IOException e) {
        throw new ProcessingException("storing user bookmarks", e);
    }
}
Also used : IOException(java.io.IOException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 25 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class FileSystemBookmarkStorageService method writeBookmarkFolder.

/**
 * Writes a bookmark folder.
 *
 * @since 3.8.2
 */
private void writeBookmarkFolder(BookmarkFolder folder, String filename, Permission permission) {
    try {
        if (ACCESS.check(permission)) {
            byte[] bytes = SerializationUtility.createObjectSerializer().serialize(folder);
            // 
            RemoteFile spec = new RemoteFile("bookmarks", filename, 0);
            spec.readData(new ByteArrayInputStream(bytes));
            BEANS.get(IRemoteFileService.class).putRemoteFile(spec);
        }
    } catch (IOException e) {
        throw new ProcessingException("", e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) IRemoteFileService(org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)142 IOException (java.io.IOException)48 MessagingException (javax.mail.MessagingException)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)17 File (java.io.File)14 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)12 Folder (javax.mail.Folder)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)9 NoSuchProviderException (java.security.NoSuchProviderException)8 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FileOutputStream (java.io.FileOutputStream)6 Message (javax.mail.Message)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5