Search in sources :

Example 51 with ProcessingException

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

the class ParsingFailedStatusTest method testConstructorCopiesCode.

@Test
public void testConstructorCopiesCode() {
    ProcessingException veto = new VetoException("Foo").withCode(123);
    ParsingFailedStatus status = new ParsingFailedStatus(veto, "Bar");
    assertEquals("Foo", status.getMessage());
    assertEquals(123, status.getCode());
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 52 with ProcessingException

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

the class IOUtilityTest method testReadLinesNonExistingFile.

@Test
public void testReadLinesNonExistingFile() {
    try {
        IOUtility.readLines(new File("doesNotExist"), StandardCharsets.UTF_8.name());
        fail("Exptected a ProcessingException for non existing file.");
    } catch (ProcessingException expected) {
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 53 with ProcessingException

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

the class IOUtilityTest method testAppendNonExistingFile.

@Test
public void testAppendNonExistingFile() throws FileNotFoundException {
    File tempFile = null;
    File tempFile2 = new File("doesNotExist");
    PrintWriter pw = null;
    try {
        tempFile = createTextTempFile();
        pw = new PrintWriter(new FileOutputStream(tempFile, true));
        try {
            IOUtility.appendFile(pw, tempFile2);
            fail("Exptected a ProcessingException for non existing file.");
        } catch (ProcessingException expected) {
        } finally {
            pw.close();
        }
    } finally {
        IOUtility.deleteFile(tempFile);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) PrintWriter(java.io.PrintWriter) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 54 with ProcessingException

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

the class MailHelper method createDataSource.

/**
 * @param inStream
 * @param fileName
 *          e.g. "file.txt"
 * @param fileExtension
 *          e.g. "txt", "jpg"
 * @return
 */
public DataSource createDataSource(InputStream inStream, String fileName, String fileExtension) {
    try {
        String mimeType = getContentTypeForExtension(fileExtension);
        if (mimeType == null) {
            mimeType = "application/octet-stream";
        }
        ByteArrayDataSource item = new ByteArrayDataSource(inStream, mimeType);
        item.setName(fileName);
        return item;
    } catch (Exception e) {
        throw new ProcessingException("Unexpected: ", e);
    }
}
Also used : ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) MessagingException(javax.mail.MessagingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) AddressException(javax.mail.internet.AddressException) IOException(java.io.IOException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 55 with ProcessingException

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

the class MailHelper method addAttachmentsToMimeMessage.

/**
 * Adds the provided attachments to the existing mime message.
 * <p>
 * When working with {@link BinaryResource}, use {@link #addResourcesAsAttachments(MimeMessage, List)} instead.
 *
 * @param msg
 *          Mime message to attach files to
 * @param attachments
 *          List of attachments (files).
 * @since 4.1
 */
public void addAttachmentsToMimeMessage(MimeMessage msg, List<File> attachments) {
    if (CollectionUtility.isEmpty(attachments)) {
        return;
    }
    try {
        Multipart multiPart = prepareMessageForAttachments(msg);
        for (File attachment : attachments) {
            MimeBodyPart bodyPart = new MimeBodyPart();
            DataSource source = new FileDataSource(attachment);
            bodyPart.setDataHandler(new DataHandler(source));
            bodyPart.setFileName(MimeUtility.encodeText(attachment.getName(), "UTF-8", null));
            multiPart.addBodyPart(bodyPart);
        }
        msg.saveChanges();
    } catch (MessagingException e) {
        throw new ProcessingException("Failed to add attachment to existing mime message", e);
    } catch (IOException e) {
        throw new ProcessingException("Failed to add attachment to existing mime message", e);
    }
}
Also used : Multipart(javax.mail.Multipart) MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) MimeBodyPart(javax.mail.internet.MimeBodyPart) File(java.io.File) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource) 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