Package org.apache.axiom.attachments

Examples of org.apache.axiom.attachments.Attachments


     *                    will be the content ID of the MIME part (without the "cid:" prefix)
     * @param dataHandler
     */
    public void addAttachment(String contentID, DataHandler dataHandler) {
        if (attachments == null) {
            attachments = new Attachments();
        }
        attachments.addDataHandler(contentID, dataHandler);
    }
View Full Code Here


     *                  Content ID of the MIME attachment (without the "cid:" prefix)
     * @return Data handler of the attachment
     */
    public DataHandler getAttachment(String contentID) {
        if (attachments == null) {
            attachments = new Attachments();
        }
        return attachments.getDataHandler(contentID);
    }
View Full Code Here

                contentType = SAAJUtil.normalizeContentType(tmpContentType);
            }
        }
        if (HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED.equals(contentType)) {
            try {
                Attachments attachments =
                        new Attachments(inputstream, tmpContentType, false, "", "");
               
                // Axiom doesn't give us access to the MIME headers of the individual
                // parts of the SOAP message package. We need to reconstruct them from
                // the available information.
                MimeHeaders soapPartHeaders = new MimeHeaders();
                soapPartHeaders.addHeader(HTTPConstants.HEADER_CONTENT_TYPE,
                        attachments.getSOAPPartContentType());
                String soapPartContentId = attachments.getSOAPPartContentID();
                soapPartHeaders.addHeader("Content-ID", "<" + soapPartContentId + ">");
               
                soapPart = new SOAPPartImpl(this, attachments.getSOAPPartInputStream(),
                        soapPartHeaders, processMTOM ? attachments : null);
               
                for (String contentId : attachments.getAllContentIDs()) {
                    if (!contentId.equals(soapPartContentId)) {
                        AttachmentPart ap =
                                createAttachmentPart(attachments.getDataHandler(contentId));
                        ap.setContentId("<" + contentId + ">");
                        attachmentParts.add(ap);
                    }
                }
            } catch (OMException e) {
View Full Code Here

    private MTOMStAXSOAPModelBuilder createBuilderForTestMTOMMessage() throws Exception {
        String contentTypeString =
                "multipart/Related; charset=\"UTF-8\"; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";
        String inFileName = "mtom/MTOMBuilderTestIn.txt";
        InputStream inStream = getTestResource(inFileName);
        Attachments attachments = new Attachments(inStream, contentTypeString);
        XMLStreamReader reader = StAXUtils.createXMLStreamReader(new BufferedReader(
                new InputStreamReader(attachments.getSOAPPartInputStream())));
        return new MTOMStAXSOAPModelBuilder(reader, attachments,
                                               SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    }
View Full Code Here

    
     * @throws Exception
     */
    public void testDeferredLoadingOfAttachments() throws Exception {
        MTOMStAXSOAPModelBuilder builder = createBuilderForTestMTOMMessage();
        Attachments attachments = builder.getAttachments();
        OMDocument doc = builder.getDocument();
        // Find all the binary nodes
        List/*<OMText>*/ binaryNodes = new ArrayList();
        for (Iterator it = new OMDescendantsIterator(doc.getFirstOMChild()); it.hasNext(); ) {
            OMNode node = (OMNode)it.next();
            if (node instanceof OMText) {
                OMText text = (OMText)node;
                if (text.isBinary()) {
                    binaryNodes.add(text);
                }
            }
        }
        assertFalse(binaryNodes.isEmpty());
        // At this moment only the SOAP part should have been loaded
        assertEquals(1, attachments.getContentIDList().size());
        for (Iterator it = binaryNodes.iterator(); it.hasNext(); ) {
            // Request the DataHandler and do something with it to make sure
            // the part is loaded
            ((DataHandler)((OMText)it.next()).getDataHandler()).getInputStream().close();
        }
        assertEquals(binaryNodes.size() + 1, attachments.getContentIDList().size());
    }
View Full Code Here

        byte[] bytes3 = xmlPlusMime3.getBytes();
        byte[] full = append(bytes1, bytes2);
        full = append(full, bytes3);
       
        InputStream inStream = new BufferedInputStream(new ByteArrayInputStream(full));
        Attachments attachments = new Attachments(inStream, contentTypeString);
        XMLStreamReader reader = StAXUtils.createXMLStreamReader(
                attachments.getSOAPPartInputStream(), "UTF-16");
        MTOMStAXSOAPModelBuilder builder = new MTOMStAXSOAPModelBuilder(reader, attachments,
                                               SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
        OMElement root = builder.getDocumentElement();
        root.build();
    }
View Full Code Here

       
        // Get a new builder.  Use an xop aware builder if the original
        // builder is xop aware
        StAXOMBuilder newBuilder = null;
        if (builder instanceof XOPBuilder) {
            Attachments attachments = ((XOPBuilder)builder).getAttachments();
            attachments.getAllContentIDs();
            if (xmlStreamReader instanceof OMXMLStreamReader) {
                if (log.isDebugEnabled()) {
                    log.debug("  read optimized xop:include");
                }
                ((OMXMLStreamReader)xmlStreamReader).setInlineMTOM(false);
View Full Code Here

            getFirstChildWithName(new QName("http://www.apache-synapse.org/test", "uploadFileUsingSwAResponse")).
            getFirstChildWithName(new QName("http://www.apache-synapse.org/test", "response")).
            getFirstChildWithName(new QName("http://www.apache-synapse.org/test", "imageId")).
            getText();

        Attachments attachment  = response.getAttachmentMap();
        dataHandler = attachment.getDataHandler(imageContentId);
        File tempFile = File.createTempFile("swa-", ".gif");
        FileOutputStream fos = new FileOutputStream(tempFile);
        dataHandler.writeTo(fos);
    fos.flush();
    fos.close();
View Full Code Here

            getFirstChildWithName(new QName("http://www.apache-synapse.org/test", "request")).
            getFirstChildWithName(new QName("http://www.apache-synapse.org/test", "imageId")).
            getText();

        MessageContext msgCtx   = MessageContext.getCurrentMessageContext();
        Attachments attachment  = msgCtx.getAttachmentMap();
        DataHandler dataHandler = attachment.getDataHandler(imageContentId);
        File tempFile = File.createTempFile("swa-", ".gif");
        FileOutputStream fos = new FileOutputStream(tempFile);
        dataHandler.writeTo(fos);
    fos.flush();
    fos.close();
View Full Code Here

        newMC.setDoingMTOM(ori.isDoingMTOM());
        newMC.setDoingSwA(ori.isDoingSwA());

        // if the original request carries any attachments, copy them to the clone
        // as well, except for the soap part if any
        Attachments attachments = ori.getAttachmentMap();
        if (attachments != null && attachments.getAllContentIDs().length > 0) {
            String[] cIDs = attachments.getAllContentIDs();
            String soapPart = attachments.getSOAPPartContentID();
            for (int i=0; i<cIDs.length; i++) {
                if (!cIDs[i].equals(soapPart)) {
                    newMC.addAttachment(cIDs[i], attachments.getDataHandler(cIDs[i]));
                }
            }
        }

        newMC.setServerSide(false);
View Full Code Here

TOP

Related Classes of org.apache.axiom.attachments.Attachments

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.