use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class MailListener method extractMessage.
@Override
public Message extractMessage(M rawMessage, Map<String, Object> threadContext) throws ListenerException {
if (MIME_MESSAGE_TYPE.equals(getMessageType())) {
try {
return getFileSystem().getMimeContent(rawMessage);
} catch (FileSystemException e) {
throw new ListenerException("cannot get MimeContents", e);
}
}
if (!EMAIL_MESSAGE_TYPE.equals(getMessageType())) {
return super.extractMessage(rawMessage, threadContext);
}
XmlWriter writer = new XmlWriter();
try (SaxElementBuilder emailXml = new SaxElementBuilder("email", writer)) {
if (isSimple()) {
MailFileSystemUtils.addEmailInfoSimple(getFileSystem(), rawMessage, emailXml);
} else {
getFileSystem().extractEmail(rawMessage, emailXml);
}
if (StringUtils.isNotEmpty(getStoreEmailAsStreamInSessionKey())) {
Message mimeContent = getFileSystem().getMimeContent(rawMessage);
threadContext.put(getStoreEmailAsStreamInSessionKey(), mimeContent.asInputStream());
}
} catch (SAXException | IOException | FileSystemException e) {
throw new ListenerException(e);
}
return new Message(writer.toString());
}
use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class MessageOutputStream method captureBinaryStream.
@SuppressWarnings("resource")
public void captureBinaryStream(OutputStream outputStream, int maxSize) {
log.debug("creating capture of " + ClassUtils.nameOf(requestStream));
closeOnClose(outputStream);
if (requestStream instanceof OutputStream) {
requestStream = StreamUtil.captureOutputStream((OutputStream) requestStream, outputStream, maxSize);
return;
}
if (requestStream instanceof ContentHandler) {
requestStream = new XmlTee((ContentHandler) requestStream, new PrettyPrintFilter(new XmlWriter(StreamUtil.limitSize(outputStream, maxSize))));
return;
}
if (requestStream instanceof JsonEventHandler) {
requestStream = new JsonTee((JsonEventHandler) requestStream, new JsonWriter(StreamUtil.limitSize(outputStream, maxSize)));
return;
}
if (requestStream instanceof Writer) {
requestStream = StreamUtil.captureWriter((Writer) requestStream, new OutputStreamWriter(outputStream, StreamUtil.DEFAULT_CHARSET), maxSize);
return;
}
log.warn("captureBinaryStream() called before stream is installed.");
}
use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class MessageOutputStream method asContentHandler.
public ContentHandler asContentHandler() throws StreamingException {
if (requestStream instanceof ContentHandler) {
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "returning ContentHandler as ContentHandler");
return (ContentHandler) requestStream;
}
if (requestStream instanceof JsonEventHandler) {
throw new StreamingException("Cannot handle XML as JSON");
}
if (requestStream instanceof OutputStream) {
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "returning OutputStream as ContentHandler");
XmlWriter xmlWriter = new XmlWriter((OutputStream) requestStream);
xmlWriter.setIncludeXmlDeclaration(true);
return xmlWriter;
}
if (requestStream instanceof Writer) {
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "returning Writer as ContentHandler");
return new XmlWriter((Writer) requestStream);
}
return null;
}
use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class MessageOutputStream method captureCharacterStream.
@SuppressWarnings("resource")
public void captureCharacterStream(Writer writer, int maxSize) {
log.debug("creating capture of " + ClassUtils.nameOf(requestStream));
closeOnClose(writer);
if (requestStream instanceof Writer) {
requestStream = StreamUtil.captureWriter((Writer) requestStream, writer, maxSize);
return;
}
if (requestStream instanceof ContentHandler) {
requestStream = new XmlTee((ContentHandler) requestStream, new PrettyPrintFilter(new XmlWriter(StreamUtil.limitSize(writer, maxSize))));
return;
}
if (requestStream instanceof JsonEventHandler) {
requestStream = new JsonTee((JsonEventHandler) requestStream, new JsonWriter(StreamUtil.limitSize(writer, maxSize)));
return;
}
if (requestStream instanceof OutputStream) {
requestStream = StreamUtil.captureOutputStream((OutputStream) requestStream, new WriterOutputStream(writer, StreamUtil.DEFAULT_CHARSET), maxSize);
return;
}
log.warn("captureCharacterStream() called before stream is installed.");
}
use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class XmlBuilder method toXML.
public String toXML(boolean xmlHeader) {
XmlWriter writer = new XmlWriter();
PrettyPrintFilter ppf = new PrettyPrintFilter(writer);
try {
toXML(ppf);
} catch (SAXException | IOException e) {
log.warn("cannot write XML", e);
return e.getMessage();
}
return writer.toString();
}
Aggregations