Search in sources :

Example 1 with ExceptionInputStream

use of org.apache.axiom.testutils.io.ExceptionInputStream in project webservices-axiom by apache.

the class AttachmentsTest method testIOExceptionInPartHeaders.

public void testIOExceptionInPartHeaders() throws Exception {
    InputStream in = MTOMSample.SAMPLE1.getInputStream();
    try {
        Attachments attachments = new Attachments(new ExceptionInputStream(in, 1050), MTOMSample.SAMPLE1.getContentType());
        // TODO: decide what exception should be thrown exactly here
        try {
            attachments.getDataHandler("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
            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)

Example 2 with ExceptionInputStream

use of org.apache.axiom.testutils.io.ExceptionInputStream 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 3 with ExceptionInputStream

use of org.apache.axiom.testutils.io.ExceptionInputStream in project webservices-axiom by apache.

the class TestIOExceptionInGetText method runTest.

@Override
protected void runTest() throws Throwable {
    // Construct a stream that will throw an exception in the middle of a text node.
    // We need to create a very large document, because some parsers (such as some
    // versions of XLXP) have a large input buffer and would throw an exception already
    // when the XMLStreamReader is created.
    StringBuffer xml = new StringBuffer("<root>");
    for (int i = 0; i < 100000; i++) {
        xml.append('x');
    }
    InputStream in = new ExceptionInputStream(new ByteArrayInputStream(xml.toString().getBytes("ASCII")));
    XMLStreamReader originalReader = StAXUtils.createXMLStreamReader(in);
    InvocationCounter invocationCounter = new InvocationCounter();
    XMLStreamReader reader = (XMLStreamReader) invocationCounter.createProxy(originalReader);
    OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader).getDocumentElement();
    try {
        element.getNextOMSibling();
        fail("Expected exception");
    } catch (Exception ex) {
    // Expected
    }
    assertTrue(invocationCounter.getInvocationCount() > 0);
    invocationCounter.reset();
    try {
        element.getNextOMSibling();
        fail("Expected exception");
    } catch (Exception ex) {
    // Expected
    }
    assertEquals(0, invocationCounter.getInvocationCount());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) InputStream(java.io.InputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) OMElement(org.apache.axiom.om.OMElement) InvocationCounter(org.apache.axiom.testutils.InvocationCounter)

Example 4 with ExceptionInputStream

use of org.apache.axiom.testutils.io.ExceptionInputStream in project webservices-axiom by apache.

the class TestReadFromWithError method runTest.

@Override
protected void runTest(WritableBlob blob) throws Throwable {
    ExceptionInputStream in = new ExceptionInputStream(new NullInputStream(1000), 500);
    try {
        blob.readFrom(in);
        fail("Expected StreamCopyException");
    } catch (StreamCopyException ex) {
        assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
        assertThat(ex.getCause()).isSameAs(in.getException());
    }
}
Also used : ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) NullInputStream(org.apache.commons.io.input.NullInputStream)

Aggregations

ExceptionInputStream (org.apache.axiom.testutils.io.ExceptionInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 PipedInputStream (java.io.PipedInputStream)2 MIMEException (org.apache.axiom.mime.MIMEException)2 DataHandler (javax.activation.DataHandler)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 StreamCopyException (org.apache.axiom.ext.io.StreamCopyException)1 OMElement (org.apache.axiom.om.OMElement)1 InvocationCounter (org.apache.axiom.testutils.InvocationCounter)1 NullInputStream (org.apache.commons.io.input.NullInputStream)1