Examples of ByteArrayDataSource


Examples of javax.mail.util.ByteArrayDataSource

    @Test
    public void testBadSOAPEnvelopeNamespace() throws Exception {
        soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
        InputStream in = getClass().getResourceAsStream("test-bad-env.xml");
        assertNotNull(in);
        ByteArrayDataSource bads = new ByteArrayDataSource(in, "test/xml");
        soapMessage.setContent(InputStream.class, bads.getInputStream());

        ReadHeadersInterceptor r = new ReadHeadersInterceptor(BusFactory.getDefaultBus());
        try {
            r.handleMessage(soapMessage);
            fail("Did not throw exception");
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

    }

    private void prepareSoapMessage(String message) throws IOException {

        soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
        ByteArrayDataSource bads = new ByteArrayDataSource(this.getClass().getResourceAsStream(message),
                                                           "Application/xop+xml");
        String cid = AttachmentUtil.createContentID("http://cxf.apache.org");
        soapMessage.setContent(Attachment.class, new AttachmentImpl(cid, new DataHandler(bads)));
        soapMessage.setContent(InputStream.class, bads.getInputStream());

    }
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

                    @Override
                    public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
                        SoapMessage soapMessage = (SoapMessage) message;
                        final String attachmentContent = "content";
                        soapMessage.addAttachment("attachment-1",
                                new DataHandler(new ByteArrayDataSource(attachmentContent, "text/plain")));
                    }
                }, new StringResult());
    }
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

                    @Override
                    public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
                        SoapMessage soapMessage = (SoapMessage) message;
                        final String attachmentContent = "content";
                        soapMessage.addAttachment("attachment-1",
                                new DataHandler(new ByteArrayDataSource(attachmentContent, "text/plain")));
                    }
                }, new StringResult());
    }
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

            if(conn.getResponseCode() == 404 || conn.getResponseCode() == 408) {
                return null;
            }

            // Buffer the result into a string
            ByteArrayDataSource ds = new ByteArrayDataSource(conn.getInputStream(),
                                                             "multipart/mixed");
            MimeMultipart mp = new MimeMultipart(ds);
            assertEquals("The number of body parts expected is not 1", 1, mp.getCount());

            MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(0);
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

        try {
            // Build the multipart object
            byte[] bytes = new byte[entity.length()];
            entity.copyBytes(bytes, 0);

            ByteArrayDataSource ds = new ByteArrayDataSource(bytes, "multipart/mixed");
            MimeMultipart mp = new MimeMultipart(ds);
            for(int i = 0; i < mp.getCount(); i++) {
                MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);
                String serializedVC = part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];
                int contentLength = Integer.parseInt(part.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

            // Build the multipart object
            byte[] bytes = new byte[entity.length()];
            entity.copyBytes(bytes, 0);

            // Get the outer multipart object
            ByteArrayDataSource ds = new ByteArrayDataSource(bytes, "multipart/mixed");
            MimeMultipart mp = new MimeMultipart(ds);
            for(int i = 0; i < mp.getCount(); i++) {

                // Get an individual part. This contains all the versioned
                // values for a particular key referenced by content-location
                MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);

                // Get the key
                String contentLocation = part.getHeader("Content-Location")[0];
                String base64Key = contentLocation.split("/")[2];
                ByteArray key = new ByteArray(RestUtils.decodeVoldemortKey(base64Key));

                if(logger.isDebugEnabled()) {
                    logger.debug("Content-Location : " + contentLocation);
                    logger.debug("Base 64 key : " + base64Key);
                }

                // Create an array list for holding all the (versioned values)
                List<Versioned<byte[]>> valueResultList = new ArrayList<Versioned<byte[]>>();

                /*
                 * Get the nested Multi-part object. This contains one part for each unique versioned value.
                 *
                 * GetContent method can corrupt the embedded data, for example 0x8c be converted to 0xc2, 0x8c,
                 * hence use getInputStream.
                 *
                 * This thread tracks this question
                 * http://stackoverflow.com/questions/23023583/mimebodypart-getcontent-corrupts-binary-data
                 *
                 * getInputStream() : Return a decoded input stream for this Message's "content.
                 *
                 * getRawInputStream() : Return an InputStream to the raw data with any Content-Transfer-Encoding
                 * intact. This method is useful if the "Content-Transfer-Encoding" header is incorrect or corrupt,
                 * which would prevent the getInputStream method from returning the correct data. In such a case
                 * the application may use this method and attempt to decode the raw data itself.
                 *
                 */

                ByteArrayDataSource nestedDS = new ByteArrayDataSource(part.getInputStream(),
                                                                       "multipart/mixed");
                MimeMultipart valueParts = new MimeMultipart(nestedDS);

                for(int valueId = 0; valueId < valueParts.getCount(); valueId++) {

View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

        if (body == null) {
            body = "";
        }

        // always store content in a byte array data store to avoid various content type and charset issues
        DataSource ds = new ByteArrayDataSource(body, contentType);
        part.setDataHandler(new DataHandler(ds));

        // set the content type header afterwards
        part.setHeader("Content-Type", contentType);
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

            // always store content in a byte array data store to avoid various content type and charset issues
            String data = exchange.getContext().getTypeConverter().tryConvertTo(String.class, exchange.getIn().getBody());
            // use empty data if the body was null for some reason (otherwise there is a NPE)
            data = data != null ? data : "";

            DataSource ds = new ByteArrayDataSource(data, contentType);
            part.setDataHandler(new DataHandler(ds));

            // set the content type header afterwards
            part.setHeader("Content-Type", contentType);
        }
View Full Code Here

Examples of javax.mail.util.ByteArrayDataSource

        XopType xop = new XopType();
        xop.setName("xopName");
        InputStream is =
            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/book.xsd");
        byte[] data = IOUtils.readBytesFromStream(is);
        xop.setAttachinfo(new DataHandler(new ByteArrayDataSource(data, "application/octet-stream")));
       
        String bookXsd = IOUtils.readStringFromStream(getClass().getResourceAsStream(
            "/org/apache/cxf/systest/jaxrs/resources/book.xsd"));
        xop.setAttachinfo2(bookXsd.getBytes());
    
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.