Package javax.xml.soap

Examples of javax.xml.soap.AttachmentPart


        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage msg = factory.createMessage();
        java.net.URL url1 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.html");
        java.net.URL url2 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.txt");

        AttachmentPart a1 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
        a1.setContentType("text/xml");
        msg.addAttachmentPart(a1);
        AttachmentPart a2 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
        a2.setContentType("text/xml");
        msg.addAttachmentPart(a2);
        AttachmentPart a3 = msg.createAttachmentPart(new javax.activation.DataHandler(url2));
        a3.setContentType("text/plain");
        msg.addAttachmentPart(a3);

        assertTrue(msg.countAttachments() == 3);

        javax.xml.soap.MimeHeaders mimeHeaders = new javax.xml.soap.MimeHeaders();
        mimeHeaders.addHeader("Content-Type", "text/xml");

        int nAttachments = 0;
        java.util.Iterator iterator = msg.getAttachments(mimeHeaders);
        while (iterator.hasNext()) {
            nAttachments++;
            AttachmentPart ap = (AttachmentPart)iterator.next();
            assertTrue(ap.equals(a1) || ap.equals(a2));
        }
        assertTrue(nAttachments == 2);
    }
View Full Code Here


        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();

        ByteArrayInputStream ins = new ByteArrayInputStream(new byte[5]);
        DataHandler dh = new DataHandler(new Src(ins, "text/plain"));
        AttachmentPart part = message.createAttachmentPart(dh);
        assertEquals("Size should match", 5, part.getSize());
    }
View Full Code Here

            InputStream in1 = new FileInputStream(new File(System.getProperty("basedir", ".") +
                    "/test-resources" + File.separator + "attach.xml"));

            MessageFactory factory = MessageFactory.newInstance();
            SOAPMessage message = factory.createMessage();
            AttachmentPart ap = message.createAttachmentPart();
            MimeHeader mh = null;

            //Setting Mime Header
            ap.setMimeHeader("Content-Description", "some text");

            //Setting Content Id Header
            ap.setContentId("id@abc.com");

            //Setting Content
            ap.setContent(new StreamSource(in1), "text/xml");

            //Clearing Content
            ap.clearContent();

            try {

                //Getting Content
                InputStream is = (InputStream)ap.getContent();
                fail("Error: SOAPException should have been thrown");
            } catch (SOAPException e) {
                //Error thrown.(expected)
            }

            Iterator iterator = ap.getAllMimeHeaders();
            int cnt = 0;
            boolean foundHeader1 = false;
            boolean foundHeader2 = false;
            boolean foundDefaultHeader = false;
            while (iterator.hasNext()) {
View Full Code Here

    public void testGetContent() throws Exception {
        try {
            MessageFactory factory = MessageFactory.newInstance();
            SOAPMessage msg = factory.createMessage();
            AttachmentPart ap = msg.createAttachmentPart();
            Image image = javax.imageio.ImageIO.read(new File(System.getProperty("basedir", ".") +
                    "/test-resources" + File.separator + "attach.gif"));
            ap = msg.createAttachmentPart(image, "image/gif");

            //Getting Content should return an Image object
            Object o = ap.getContent();
            if (o != null) {
                if (o instanceof Image) {
                    //Image object was returned (ok)
                } else {
                    fail("Unexpected object was returned");
View Full Code Here

    public void testGetRawContents() {
        try {
            MessageFactory factory = MessageFactory.newInstance();
            SOAPMessage msg = factory.createMessage();
            AttachmentPart ap = msg.createAttachmentPart();
            ap = msg.createAttachmentPart();
            byte data1[] = null;
            data1 = ap.getRawContentBytes();

        } catch (SOAPException e) {
            //Caught expected SOAPException
        } catch (NullPointerException e) {
            //Caught expected NullPointerException
View Full Code Here

     */
    public void removeAttachments(MimeHeaders headers) {
        Collection newAttachmentParts = new ArrayList();
        Iterator attachmentPartsItr = attachmentParts.iterator();
        for (Iterator iter = attachmentPartsItr; iter.hasNext();) {
            AttachmentPart attachmentPart = (AttachmentPart)iter.next();

            //Get all the headers
            Iterator allMIMEHeaders = headers.getAllHeaders();
            for (Iterator iterator = allMIMEHeaders; iterator.hasNext();) {
                MimeHeader mimeHeader = (MimeHeader)iterator.next();
                String[] headerValues = attachmentPart.getMimeHeader(mimeHeader.getName());
                //if values for this header name, do not remove it
                if (headerValues.length != 0) {
                    if (!(headerValues[0].equals(mimeHeader.getValue()))) {
                        newAttachmentParts.add(attachmentPart);
                    }
View Full Code Here

        // if there are unrefferenced attachments, add that to response
        if (!unaccessedAttachments.isEmpty()) {
            Collection attachments = unaccessedAttachments.values();
            Iterator attachementsIterator = attachments.iterator();
            while (attachementsIterator.hasNext()) {
                AttachmentPart attachment = (AttachmentPart)attachementsIterator.next();
                response.addAttachmentPart(attachment);
            }
        }

        return response;
View Full Code Here

                    // check whether the omtext refers to an attachment

                    final OMText omText = (OMText)omChildNode;
                    if (omText.isOptimized()) { // is this an attachment?
                        final DataHandler datahandler = (DataHandler)omText.getDataHandler();
                        AttachmentPart attachment = saajSOAPMsg.createAttachmentPart(datahandler);
                        final String id = IDGenerator.generateID();
                        attachment.setContentId(id);
                        attachment.setContentType(datahandler.getContentType());
                        saajSOAPMsg.addAttachmentPart(attachment);

                        saajEle.addAttribute(
                                saajSOAPMsg.getSOAPPart().getEnvelope().createName("href"),
                                "cid:" + id);
View Full Code Here


        Map attachmentMap = new HashMap();
        final Iterator attachments = saajSOAPMsg.getAttachments();
        while (attachments.hasNext()) {
            final AttachmentPart attachment = (AttachmentPart)attachments.next();
            if (attachment.getContentId() == null ||
                    attachment.getContentId().trim().length() == 0) {
                attachment.setContentId(IDGenerator.generateID());
            }
            if (attachment.getDataHandler() == null) {
                throw new SOAPException("Attachment with NULL DataHandler");
            }
            attachmentMap.put(attachment.getContentId(), attachment);
        }

        //Get keys of attachments to a hashmap
        //This hashmap will be updated when attachment is accessed atleast once.
        //Doing this here instead of inside insertAttachmentNodes()is much simpler
View Full Code Here

            final OMAttribute hrefAttr = child.getAttribute(new QName("href"));
            String contentID = getContentID(hrefAttr);

            if (contentID != null) {//This is an omEnvelope referencing an attachment
                child.build();
                AttachmentPart ap = ((AttachmentPart)attachments.get(contentID.trim()));
                //update the key status as accessed
                keyAccessStatus.put(contentID.trim(), "accessed");
                OMText text = new OMTextImpl(ap.getDataHandler(), true,
                                             omEnvelope.getOMFactory());
                child.removeAttribute(hrefAttr);
                child.addChild(text);
            } else {
                //possibly there can be references in the children of this omEnvelope
View Full Code Here

TOP

Related Classes of javax.xml.soap.AttachmentPart

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.