Search in sources :

Example 71 with DataHandler

use of javax.activation.DataHandler in project webservices-axiom by apache.

the class AttachmentsTest method testRemoveDataHandlerNonExistingWithoutStream.

/**
     * Tests that {@link Attachments#removeDataHandler(String)} returns silently if no data handler
     * with the given content ID has been added to the object.
     */
public void testRemoveDataHandlerNonExistingWithoutStream() {
    Attachments attachments = new Attachments();
    attachments.addDataHandler("id@apache.org", new DataHandler("test", "text/plain"));
    attachments.removeDataHandler("non-existing@apache.org");
    assertEquals(1, attachments.getContentIDSet().size());
}
Also used : DataHandler(javax.activation.DataHandler)

Example 72 with DataHandler

use of javax.activation.DataHandler in project webservices-axiom by apache.

the class AttachmentsTest method testGetAllContentIDsWithoutStream.

public void testGetAllContentIDsWithoutStream() {
    Attachments attachments = new Attachments();
    // The choice of content IDs here makes sure that we test that the attachments are returned
    // in the order in which they have been added (instead of sorted by content ID as in
    // earlier Axiom versions)
    attachments.addDataHandler("contentB@apache.org", new DataHandler("content1", "text/plain"));
    attachments.addDataHandler("contentA@apache.org", new DataHandler("content2", "text/plain"));
    String[] contentIDs = attachments.getAllContentIDs();
    assertEquals(2, contentIDs.length);
    assertEquals("contentB@apache.org", contentIDs[0]);
    assertEquals("contentA@apache.org", contentIDs[1]);
}
Also used : DataHandler(javax.activation.DataHandler)

Example 73 with DataHandler

use of javax.activation.DataHandler in project webservices-axiom by apache.

the class AttachmentsTest method testZeroLengthAttachment.

/**
     * Tests that {@link Attachments} can successfully read an attachment with zero length. This is
     * a regression test for
     * <a href="https://issues.apache.org/jira/browse/AXIOM-383">AXIOM-383</a>.
     * 
     * @throws Exception
     */
public void testZeroLengthAttachment() throws Exception {
    InputStream in = getTestResource("mtom/zero-length-attachment.bin");
    try {
        Attachments attachments = new Attachments(in, "multipart/related; " + "boundary=MIMEBoundaryurn_uuid_0549F3F826EC3041861188639371825; " + "type=\"application/xop+xml\"; " + "start=\"0.urn:uuid:0549F3F826EC3041861188639371826@apache.org\"; " + "start-info=\"application/soap+xml\"; action=\"urn:test\"");
        DataHandler dh = attachments.getDataHandler("1.urn:uuid:0549F3F826EC3041861188639371827@apache.org");
        InputStream content = dh.getInputStream();
        assertEquals(-1, content.read());
    } finally {
        in.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) InputStream(java.io.InputStream) DataHandler(javax.activation.DataHandler)

Example 74 with DataHandler

use of javax.activation.DataHandler in project webservices-axiom by apache.

the class AttachmentsTest method testIOExceptionInPartContent.

public void testIOExceptionInPartContent() throws Exception {
    InputStream in = MTOMSample.SAMPLE1.getInputStream();
    try {
        Attachments attachments = new Attachments(new ExceptionInputStream(in, 1500), MTOMSample.SAMPLE1.getContentType());
        DataHandler dh = attachments.getDataHandler("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
        // TODO: decide what exception should be thrown exactly here
        try {
            dh.getInputStream();
            fail("Expected exception");
        } catch (MIMEException ex) {
        // Expected
        }
    } finally {
        in.close();
    }
}
Also used : MIMEException(org.apache.axiom.mime.MIMEException) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) InputStream(java.io.InputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) DataHandler(javax.activation.DataHandler)

Example 75 with DataHandler

use of javax.activation.DataHandler in project webservices-axiom by apache.

the class TestRegisterCustomBuilderForPayloadJAXBPlain method runTest.

@Override
protected void runTest() throws Throwable {
    DataHandler dh = new DataHandler(new RandomDataSource(10000));
    MemoryBlob blob = Blobs.createMemoryBlob();
    OutputStream out = blob.getOutputStream();
    createTestDocument(dh).serialize(out);
    out.close();
    test(dh, OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), blob.getInputStream()), false);
}
Also used : RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) MemoryBlob(org.apache.axiom.blob.MemoryBlob) OutputStream(java.io.OutputStream) DataHandler(javax.activation.DataHandler)

Aggregations

DataHandler (javax.activation.DataHandler)180 Exchange (org.apache.camel.Exchange)39 MimeBodyPart (javax.mail.internet.MimeBodyPart)38 FileDataSource (javax.activation.FileDataSource)33 Test (org.junit.Test)33 DataSource (javax.activation.DataSource)32 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)29 IOException (java.io.IOException)27 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 InputStream (java.io.InputStream)25 MessagingException (javax.mail.MessagingException)25 MimeMultipart (javax.mail.internet.MimeMultipart)25 MimeMessage (javax.mail.internet.MimeMessage)23 ByteArrayInputStream (java.io.ByteArrayInputStream)22 Message (org.apache.camel.Message)21 OMElement (org.apache.axiom.om.OMElement)17 Processor (org.apache.camel.Processor)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 File (java.io.File)13 PipedInputStream (java.io.PipedInputStream)13