Search in sources :

Example 81 with DataHandler

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

the class DataHandlerWrapperTest method test.

public void test() {
    DataHandler dataHandler = new DataHandler("<root/>", "text/plain; charset=UTF-8");
    DataHandler wrapper = new DataHandlerWrapper(dataHandler);
    assertEquals(dataHandler.getContentType(), wrapper.getContentType());
    assertEquals(dataHandler.getName(), wrapper.getName());
    assertSame(dataHandler.getDataSource(), wrapper.getDataSource());
}
Also used : DataHandler(javax.activation.DataHandler)

Example 82 with DataHandler

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

the class XMLStreamReaderUtilsTest method testGetDataHandlerFromElementWithZeroLength.

private void testGetDataHandlerFromElementWithZeroLength(boolean useDHR) throws Exception {
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test/>"));
    if (useDHR) {
        reader = new XMLStreamReaderWithDataHandlerReader(reader);
    }
    try {
        reader.next();
        // Check precondition
        assertTrue(reader.isStartElement());
        DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);
        // Check postcondition
        assertTrue(reader.isEndElement());
        assertEquals(-1, dh.getInputStream().read());
    } finally {
        reader.close();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) DataHandler(javax.activation.DataHandler)

Example 83 with DataHandler

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

the class TestDataHandlerExpansion method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    DataHandler dh = new DataHandler("some content", "text/plain");
    DocumentBean object = new DocumentBean();
    object.setId("123456");
    object.setContent(dh);
    OMElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
    OMElement child = (OMElement) element.getFirstOMChild();
    assertEquals("id", child.getLocalName());
    assertEquals("123456", child.getText());
    child = (OMElement) child.getNextOMSibling();
    assertEquals("content", child.getLocalName());
    OMText content = (OMText) child.getFirstOMChild();
    assertTrue(content.isBinary());
    assertTrue(content.isOptimized());
    assertSame(dh, content.getDataHandler());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) OMText(org.apache.axiom.om.OMText) JAXBContext(javax.xml.bind.JAXBContext) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 84 with DataHandler

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

the class TestDataHandlerSerializationWithoutMTOM method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFactory factory = metaFactory.getSOAP11Factory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    // Construct the original message
    DocumentBean orgObject = new DocumentBean();
    orgObject.setId("123456");
    orgObject.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
    SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
    OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, orgObject));
    orgEnvelope.getBody().addChild(element);
    // Serialize the message
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    orgEnvelope.serialize(out);
    assertFalse(element.isExpanded());
    SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(new ByteArrayInputStream(out.toByteArray()), null).getSOAPEnvelope();
    DocumentBean object = (DocumentBean) context.createUnmarshaller().unmarshal(envelope.getBody().getFirstElement().getXMLStreamReader(false));
    assertEquals("some content", IOUtils.toString(object.getContent().getInputStream(), "utf-8"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) JAXBContext(javax.xml.bind.JAXBContext) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPFactory(org.apache.axiom.soap.SOAPFactory) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 85 with DataHandler

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

the class BufferUtilsTest method testByteArrayDataSourceBackedDataHandlerExceedLimit.

public void testByteArrayDataSourceBackedDataHandlerExceedLimit() throws Exception {
    String str = "This is a test String";
    byte[] b = str.getBytes();
    ByteArrayDataSource bads = new ByteArrayDataSource(b, "text/plain");
    DataHandler dh = new DataHandler(bads);
    int unsupported = BufferUtils.doesDataHandlerExceedLimit(dh, 0);
    assertEquals(-1, unsupported);
    int doesExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 10);
    assertEquals(1, doesExceed);
    int doesNotExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 100);
    assertEquals(0, doesNotExceed);
}
Also used : DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

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