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());
}
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) {
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations