Search in sources :

Example 21 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class MalwareScannerTest method testEmptyContent.

@Test
public void testEmptyContent() {
    BinaryResource res = new BinaryResource("safe-test.txt", new byte[0]);
    new MalwareScanner().scan(res);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) Test(org.junit.Test)

Example 22 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class MalwareScannerTest method testSafeContent.

@Test
public void testSafeContent() {
    BinaryResource res = new BinaryResource("safe-test.txt", SAFE_CONTENT.getBytes());
    new MalwareScanner().scan(res);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) Test(org.junit.Test)

Example 23 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class MalwareScannerTest method testEicarVirus.

@Ignore("Typically there is no on-site malware scanner on xnix-based systems")
@Test
public void testEicarVirus() {
    thrown.expect(PlatformException.class);
    thrown.expectMessage("Resource 'virus-test.txt' is not safe");
    BinaryResource res = new BinaryResource("virus-test.txt", EICAR_TEST_VIRUS.getBytes());
    new MalwareScanner().scan(res);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class MalwareScannerTest method testNullContent.

@Test
public void testNullContent() {
    BinaryResource res = new BinaryResource("safe-test.txt", null);
    new MalwareScanner().scan(res);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) Test(org.junit.Test)

Example 25 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class MailHelper method addResourcesAsAttachments.

/**
 * Adds the provided attachments to the existing mime message.
 * <p>
 * When working with {@link File}, use {@link #addAttachmentsToMimeMessage(MimeMessage, List)} instead.
 *
 * @param msg
 *          Mime message to attach files to
 * @param attachments
 *          List of attachments (binary resources).
 * @since 6.0
 */
public void addResourcesAsAttachments(MimeMessage msg, List<BinaryResource> attachments) {
    if (CollectionUtility.isEmpty(attachments)) {
        return;
    }
    try {
        Multipart multiPart = prepareMessageForAttachments(msg);
        for (BinaryResource attachment : attachments) {
            MimeBodyPart bodyPart = new MimeBodyPart();
            DataSource source = new BinaryResourceDataSource(attachment);
            bodyPart.setDataHandler(new DataHandler(source));
            bodyPart.setFileName(MimeUtility.encodeText(attachment.getFilename(), "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) BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) MessagingException(javax.mail.MessagingException) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) MimeBodyPart(javax.mail.internet.MimeBodyPart) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)46 Test (org.junit.Test)26 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)19 HttpCacheKey (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey)15 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)4 BinaryResourceHolder (org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder)4 InputStream (java.io.InputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 JSONObject (org.json.JSONObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Field (java.lang.reflect.Field)1