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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations