Search in sources :

Example 91 with OMText

use of org.apache.axiom.om.OMText in project webservices-axiom by apache.

the class TextHelperTest method test_fromOMText.

/**
 * Test the OMText -> StringBuffer code
 * @throws Exception
 */
public void test_fromOMText() throws Exception {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    FileDataSource fds = new FileDataSource(file);
    DataHandler dh = new DataHandler(fds);
    OMText omText = factory.createOMText(dh, true);
    StringBuffer buffer = new StringBuffer();
    TextHelper.toStringBuffer(omText, buffer);
    assertTrue(buffer.length() > SIZE);
    String text = buffer.toString();
    assertTrue(text.length() == EXPECTED_BASE64_SIZE);
    assertTrue(text.startsWith(EXPECTED_STARTS_WITH));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) FileDataSource(javax.activation.FileDataSource) OMText(org.apache.axiom.om.OMText) DataHandler(javax.activation.DataHandler)

Example 92 with OMText

use of org.apache.axiom.om.OMText in project webservices-axiom by apache.

the class MIMEOutputUtils method complete.

/**
 * @deprecated Use {@link OMMultipartWriter} instead.
 */
public static void complete(OutputStream outStream, byte[] xmlData, LinkedList binaryNodeList, String boundary, String contentId, String charSetEncoding, String SOAPContentType, OMOutputFormat omOutputFormat) {
    try {
        log.debug("Start: write the SOAPPart and the attachments");
        // Write out the mime boundary
        startWritingMime(outStream, boundary);
        javax.activation.DataHandler dh = new javax.activation.DataHandler(new ByteArrayDataSource(xmlData, "text/xml; charset=" + charSetEncoding));
        MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
        rootMimeBodyPart.setDataHandler(dh);
        rootMimeBodyPart.addHeader("Content-Type", "application/xop+xml; charset=" + charSetEncoding + "; type=\"" + SOAPContentType + "\"");
        rootMimeBodyPart.addHeader("Content-Transfer-Encoding", "binary");
        rootMimeBodyPart.addHeader("Content-ID", "<" + contentId + ">");
        // Write out the SOAPPart
        writeBodyPart(outStream, rootMimeBodyPart, boundary);
        // Now write out the Attachment parts (which are represented by the
        // text nodes int the binary node list)
        Iterator binaryNodeIterator = binaryNodeList.iterator();
        while (binaryNodeIterator.hasNext()) {
            OMText binaryNode = (OMText) binaryNodeIterator.next();
            writeBodyPart(outStream, createMimeBodyPart(binaryNode.getContentID(), binaryNode.getDataHandler(), omOutputFormat), boundary);
        }
        finishWritingMime(outStream);
        outStream.flush();
        log.debug("End: write the SOAPPart and the attachments");
    } catch (IOException e) {
        throw new OMException("Error while writing to the OutputStream.", e);
    } catch (MessagingException e) {
        throw new OMException("Problem writing Mime Parts.", e);
    }
}
Also used : MessagingException(javax.mail.MessagingException) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) DataHandler(javax.activation.DataHandler) ConfigurableDataHandler(org.apache.axiom.attachments.ConfigurableDataHandler) IOException(java.io.IOException) MimeBodyPart(javax.mail.internet.MimeBodyPart) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource) OMException(org.apache.axiom.om.OMException)

Aggregations

OMText (org.apache.axiom.om.OMText)92 OMElement (org.apache.axiom.om.OMElement)62 OMFactory (org.apache.axiom.om.OMFactory)39 DataHandler (javax.activation.DataHandler)26 OMNode (org.apache.axiom.om.OMNode)21 OMNamespace (org.apache.axiom.om.OMNamespace)10 QName (javax.xml.namespace.QName)8 OMException (org.apache.axiom.om.OMException)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 InputStream (java.io.InputStream)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 Entry (org.apache.synapse.config.Entry)6 ArrayList (java.util.ArrayList)5 DataSource (javax.activation.DataSource)5 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)5 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)5 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)5 OutputStream (java.io.OutputStream)4 StringReader (java.io.StringReader)4