Package org.apache.cxf.message

Examples of org.apache.cxf.message.Attachment


        assertNotNull(atts);

        Iterator<Attachment> itr = atts.iterator();
        assertTrue(itr.hasNext());

        Attachment a = itr.next();
        assertNotNull(a);

        InputStream attIs = a.getDataHandler().getInputStream();

        // check the cached output stream
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(attBody, out);
        assertTrue(out.toString().startsWith("<env:Envelope"));
View Full Code Here


        assertNotNull(atts);
       
        Iterator<Attachment> itr = atts.iterator();
        assertTrue(itr.hasNext());
       
        Attachment a = itr.next();
        assertNotNull(a);
       
        InputStream attIs = a.getDataHandler().getInputStream();

        // check the cached output stream
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(attBody, out);
        assertTrue(out.toString().startsWith("<?xml"));
View Full Code Here

        assertNotNull(atts);
       
        Iterator<Attachment> itr = atts.iterator();
        assertTrue(itr.hasNext());
       
        Attachment a = itr.next();
        assertNotNull(a);
       
        InputStream attIs = a.getDataHandler().getInputStream();
       
        // check the cached output stream
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(attBody, out);
        assertTrue(out.toString().startsWith("<?xml"));
View Full Code Here

        assertNotNull(atts);
       
        Iterator<Attachment> itr = atts.iterator();
        assertTrue(itr.hasNext());
       
        Attachment a = itr.next();
        assertNotNull(a);
       
        InputStream attIs = a.getDataHandler().getInputStream();
       
        assertFalse(itr.hasNext());
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(attIs, out);
View Full Code Here

    public <T> T[] toArray(T[] a) {
        T[] copy = a.length == attachments.size()
            ? a : (T[])Array.newInstance(a.getClass(), attachments.size());
        int i = 0;
        for (Map.Entry<String, DataHandler> entry : attachments.entrySet()) {
            Attachment o = cache.get(entry.getKey());
            if (o == null) {
                o = new AttachmentImpl(entry.getKey(), entry.getValue());
                cache.put(entry.getKey(), o);
            }
            copy[i++] = (T)o;
View Full Code Here

    }

    public boolean addAll(Collection<? extends Attachment> c) {
        boolean b = false;
        for (Iterator<? extends Attachment> it = c.iterator(); it.hasNext();) {
            Attachment o = it.next();
            if (!attachments.containsKey(o.getId())) {
                b = true;
                attachments.put(o.getId(), o.getDataHandler());
                cache.put(o.getId(), o);
            }
        }
        return b;
    }
View Full Code Here

        }

        public Attachment next() {
            Map.Entry<String, DataHandler> e = iterator.next();
            key = e.getKey();
            Attachment o = cache.get(key);
            if (o == null) {
                o = new AttachmentImpl(key, e.getValue());
                cache.put(key, o);
            }
            return o;
View Full Code Here

   
   
    public String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNS,
                                    String elementLocalName) {
       
        Attachment att = AttachmentUtil.createMtomAttachment(
                             isXop, mimeType, elementNS, data, offset, length, threshold);
        if (att != null) {
            atts.add(att);
            return "cid:" + att.getId();
        } else {
            return null;
        }
       
    }
View Full Code Here

       
    }

    public String addMtomAttachment(DataHandler handler, String elementNS, String elementLocalName) {

        Attachment att = AttachmentUtil.createMtomAttachmentFromDH(isXop, handler, elementNS, threshold);
        if (att != null) {
            atts.add(att);
            return "cid:" + att.getId();
        } else {
            return null;
        }
    }
View Full Code Here

    public void testCreateAndModify() {
        Map<String, DataHandler> content = new HashMap<String, DataHandler>();
        content.put("att-1", new DataHandler(new ByteArrayDataSource("Hello world!".getBytes(), "text/plain")));
        content.put("att-2", new DataHandler(new ByteArrayDataSource("Hola mundo!".getBytes(), "text/plain")));
        WrappedAttachments attachments = new WrappedAttachments(content);
        Attachment att3 = new AttachmentImpl("att-3",
            new DataHandler(new ByteArrayDataSource("Bonjour tout le monde!".getBytes(), "text/plain")));

        assertEquals(2, attachments.size());
        assertFalse(attachments.isEmpty());
       
        attachments.add(att3);
        assertEquals(3, attachments.size());

        attachments.add(att3);
        assertEquals(3, attachments.size());
       
        attachments.remove(att3);
       
        assertEquals(2, attachments.size());
       
        Attachment attx = attachments.iterator().next();
       
        attachments.remove(attx);
       
        assertEquals(1, attachments.size());
       
        Attachment[] atts = attachments.toArray(new Attachment[attachments.size()]);
        assertEquals(1, atts.length);
        assertEquals("att-1".equals(attx.getId()) ? "att-2" : "att-1", atts[0].getId());
       
        attachments.clear();
        assertTrue(attachments.isEmpty());
        assertTrue(content.isEmpty());
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.message.Attachment

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.