Package javax.activation

Examples of javax.activation.DataHandler


    public void testUnmarshalWithDataHandler() throws Exception {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
        DocumentBean orgBean = new DocumentBean();
        orgBean.setId("AB23498");
        orgBean.setContent(new DataHandler("test content", "text/plain"));
        OMElement element = factory.createOMElement(new JAXBOMDataSource(context, orgBean));
        DocumentBean bean = (DocumentBean)JAXBUtils.unmarshal(context, element, true);
        assertEquals(orgBean.getId(), bean.getId());
        assertEquals(orgBean.getContent(), bean.getContent());
    }
View Full Code Here


        OMNamespace dataName = fac.createOMNamespace(
                "http://www.example.org/stuff", "m");
        OMElement data = fac.createOMElement("data", dataName);

        DataSource dataSource = getTestResourceDataSource(imageInFileName);
        expectedDH = new DataHandler(dataSource);
        OMText binaryNode = fac.createOMText(expectedDH, true);

        envelope.addChild(body);
        body.addChild(data);
        data.addChild(binaryNode);
View Full Code Here

         * OBBlob User has to know the object type & whether it is serializable.
         * If it is not he has to use a Custom Defined DataSource to get the
         * Object.
         */

        DataHandler actualDH;
        actualDH = (DataHandler) blob.getDataHandler();
        BufferedImage bufferedImage = ImageIO.read(actualDH.getDataSource().getInputStream());
        this.saveImage("image/jpeg", bufferedImage, new FileOutputStream(imageOutFileName));
       
        root.close(false);
    }
View Full Code Here

         * If it is not he has to use a Custom Defined DataSource to get the
         * Object.
         */
        byte[] expectedObject = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2,
                -1, 98 };
        DataHandler actualDH;
        actualDH = (DataHandler) blob.getDataHandler();
        //ByteArrayInputStream object = (ByteArrayInputStream) actualDH
        //.getContent();
        //byte[] actualObject= null;
        //  object.read(actualObject,0,10);
View Full Code Here

        // Use tree as input to XMLStreamReader
        // Issue XOP:Include events for optimized MTOM text nodes
        XOPEncodedStream xopEncodedStream = XOPUtils.getXOPEncodedStream(root.getXMLStreamReader());
        XMLStreamReader xmlStreamReader = xopEncodedStream.getReader();
       
        DataHandler dh = null;
        while(xmlStreamReader.hasNext() && dh == null) {
            xmlStreamReader.next();
            if (xmlStreamReader.isStartElement()) {
                QName qName =xmlStreamReader.getName();
                if (XOP_INCLUDE.equals(qName)) {
View Full Code Here

            if (contentID == null) {
                throw new XMLStreamException("Encountered an xop:Include element without " +
                    "href attribute");
            }
            // TODO: we should create a DataHandlerProvider if isLoaded returns false for the given contentID
            DataHandler dh;
            try {
                dh = mimePartProvider.getDataHandler(contentID);
            } catch (IOException ex) {
                throw new XMLStreamException("Error while fetching data handler", ex);
            }
View Full Code Here

import junit.framework.TestCase;

public class DataHandlerWrapperTest extends TestCase {
    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());
    }
View Full Code Here

     */
    @Test
    public void testDataHandlerExpansion() throws Exception {
        OMFactory factory = OMAbstractFactory.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();
View Full Code Here

        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
View Full Code Here

        JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
       
        // Construct the original message
        DocumentBean object = new DocumentBean();
        object.setId("123456");
        object.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
        SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
        OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
        orgEnvelope.getBody().addChild(element);
       
        // Serialize the message
        OMOutputFormat format = new OMOutputFormat();
        format.setDoOptimize(true);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        orgEnvelope.serialize(out, format);
        assertFalse(element.isExpanded());
       
        // Parse the serialized message
        Attachments att = new Attachments(new ByteArrayInputStream(out.toByteArray()), format.getContentType());
        assertEquals(2, att.getAllContentIDs().length);
        SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(att).getSOAPEnvelope();
        OMElement contentElement = envelope.getBody().getFirstElement().getFirstChildWithName(
                new QName("http://ws.apache.org/axiom/test/jaxb", "content"));
        OMText content = (OMText)contentElement.getFirstOMChild();
        assertTrue(content.isBinary());
        assertTrue(content.isOptimized());
        DataHandler dh = (DataHandler)content.getDataHandler();
        assertEquals("some content", dh.getContent());
    }
View Full Code Here

TOP

Related Classes of javax.activation.DataHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.