Search in sources :

Example 76 with OMException

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

the class ParserInputStreamDataSource method copy.

/**
 * Return a InputStreamDataSource backed by a ByteArrayInputStream
 */
@Override
public OMDataSourceExt copy() {
    if (log.isDebugEnabled()) {
        log.debug("Enter ParserInputStreamDataSource.copy()");
    }
    try {
        BAAOutputStream baaos = new BAAOutputStream();
        BufferUtils.inputStream2OutputStream(data.readParserInputStream(), baaos);
        BAAInputStream baais = new BAAInputStream(baaos.buffers(), baaos.length());
        if (log.isDebugEnabled()) {
            log.debug("Exit ParserInputStreamDataSource.copy()");
        }
        return new ParserInputStreamDataSource(baais, data.encoding, data.behavior);
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug("Error ParserInputStreamDataSource.copy(): ", t);
        }
        throw new OMException(t);
    }
}
Also used : BAAInputStream(org.apache.axiom.attachments.utils.BAAInputStream) OMException(org.apache.axiom.om.OMException) BAAOutputStream(org.apache.axiom.attachments.utils.BAAOutputStream)

Example 77 with OMException

use of org.apache.axiom.om.OMException 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)

Example 78 with OMException

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

the class MIMEOutputUtils method writeDataHandlerWithAttachmentsMessage.

/**
 * @deprecated Use {@link OMMultipartWriter} instead.
 */
public static void writeDataHandlerWithAttachmentsMessage(DataHandler rootDataHandler, final String contentType, OutputStream outputStream, Map attachments, OMOutputFormat format, Collection ids) {
    try {
        if (!rootDataHandler.getContentType().equals(contentType)) {
            rootDataHandler = new DataHandlerWrapper(rootDataHandler) {

                @Override
                public String getContentType() {
                    return contentType;
                }
            };
        }
        OMMultipartWriter mpw = new OMMultipartWriter(outputStream, format);
        mpw.writePart(rootDataHandler, format.getRootContentId());
        Iterator idIterator = null;
        if (ids == null) {
            // If ids are not provided, use the attachment map
            // to get the keys
            idIterator = attachments.keySet().iterator();
        } else {
            // if ids are provided (normal case), iterate
            // over the ids so that the attachments are
            // written in the same order as the id keys.
            idIterator = ids.iterator();
        }
        while (idIterator.hasNext()) {
            String key = (String) idIterator.next();
            mpw.writePart((DataHandler) attachments.get(key), key);
        }
        mpw.complete();
        outputStream.flush();
    } catch (IOException e) {
        throw new OMException("Error while writing to the OutputStream.", e);
    }
}
Also used : Iterator(java.util.Iterator) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException) DataHandlerWrapper(org.apache.axiom.util.activation.DataHandlerWrapper)

Example 79 with OMException

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

the class MIMEOutputUtils method writeSOAPWithAttachmentsMessage.

/**
 * @deprecated Use {@link OMMultipartWriter} instead.
 */
public static void writeSOAPWithAttachmentsMessage(StringWriter writer, OutputStream outputStream, Attachments attachments, OMOutputFormat format) {
    try {
        OMMultipartWriter mpw = new OMMultipartWriter(outputStream, format);
        Writer rootPartWriter = new OutputStreamWriter(mpw.writeRootPart(), format.getCharSetEncoding());
        rootPartWriter.write(writer.toString());
        rootPartWriter.close();
        // Get the collection of ids associated with the attachments
        Collection ids = Arrays.asList(attachments.getAllContentIDs());
        for (Iterator it = ids.iterator(); it.hasNext(); ) {
            String id = (String) it.next();
            mpw.writePart(attachments.getDataHandler(id), id);
        }
        mpw.complete();
    } catch (IOException ex) {
        throw new OMException("Error writing SwA message", ex);
    }
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 80 with OMException

use of org.apache.axiom.om.OMException in project wso2-synapse by wso2.

the class NashornJavaScriptXmlHelper method toOMElement.

/**
 * This method will convert the message payload in to xml.
 *
 * @param scriptXML from java script
 * @return XML content as OMElement
 * @throws ScriptException when error
 */
public OMElement toOMElement(Object scriptXML) throws ScriptException {
    OMElement omElement;
    if (scriptXML == null) {
        return null;
    } else if (scriptXML instanceof String) {
        try {
            String xmlString = scriptXML.toString();
            omElement = AXIOMUtil.stringToOM(xmlString);
        } catch (XMLStreamException | OMException e) {
            ScriptException scriptException = new ScriptException("Failed to create OMElement with provided " + "payload");
            scriptException.initCause(e);
            throw scriptException;
        }
    } else if (scriptXML instanceof Document) {
        try {
            Element element = ((Document) scriptXML).getDocumentElement();
            omElement = XMLUtils.toOM(element);
        } catch (Exception e) {
            ScriptException scriptException = new ScriptException("Failed to create OMElement with provided " + "payload");
            scriptException.initCause(e);
            throw scriptException;
        }
    } else if (scriptXML instanceof OMElement) {
        omElement = (OMElement) scriptXML;
    } else {
        throw new ScriptException("Unsupported type provide for XML. type: " + scriptXML.getClass());
    }
    return omElement;
}
Also used : ScriptException(javax.script.ScriptException) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) Document(org.w3c.dom.Document) OMException(org.apache.axiom.om.OMException) XMLStreamException(javax.xml.stream.XMLStreamException) ScriptException(javax.script.ScriptException)

Aggregations

OMException (org.apache.axiom.om.OMException)89 OMElement (org.apache.axiom.om.OMElement)35 XMLStreamException (javax.xml.stream.XMLStreamException)31 IOException (java.io.IOException)30 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)21 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)18 InputStream (java.io.InputStream)16 QName (javax.xml.namespace.QName)13 OMFactory (org.apache.axiom.om.OMFactory)12 ArrayList (java.util.ArrayList)11 MalformedURLException (java.net.MalformedURLException)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 ParseException (org.json.simple.parser.ParseException)9 APIMgtResourceAlreadyExistsException (org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException)9 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)9 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)9 MonetizationException (org.wso2.carbon.apimgt.api.MonetizationException)9 UnsupportedPolicyTypeException (org.wso2.carbon.apimgt.api.UnsupportedPolicyTypeException)9