use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class MailFileSystemUtils method addAttachmentInfo.
public static <M, A> void addAttachmentInfo(IMailFileSystem<M, A> fileSystem, A attachment, SaxElementBuilder attachmentsXml) throws FileSystemException, SAXException {
try (SaxElementBuilder attachmentXml = attachmentsXml.startElement("attachment")) {
attachmentXml.addAttribute("name", fileSystem.getAttachmentName(attachment));
String filename = fileSystem.getAttachmentFileName(attachment);
if (filename != null) {
attachmentXml.addAttribute("filename", filename);
}
M emailMessage = fileSystem.getFileFromAttachment(attachment);
if (emailMessage != null) {
fileSystem.extractEmail(emailMessage, attachmentXml);
}
}
}
use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class MailFileSystemUtils method addEmailInfo.
public static <M, A> void addEmailInfo(IMailFileSystem<M, A> fileSystem, M emailMessage, SaxElementBuilder emailXml) throws FileSystemException, SAXException {
Map<String, Object> properties = fileSystem.getAdditionalFileProperties(emailMessage);
try (SaxElementBuilder recipientsXml = emailXml.startElement("recipients")) {
addRecipientProperty(recipientsXml, properties, IMailFileSystem.TO_RECEPIENTS_KEY);
addRecipientProperty(recipientsXml, properties, IMailFileSystem.CC_RECEPIENTS_KEY);
addRecipientProperty(recipientsXml, properties, IMailFileSystem.BCC_RECEPIENTS_KEY);
}
addPropertyAsHeader(emailXml, IMailFileSystem.FROM_ADDRESS_KEY, properties.get(IMailFileSystem.FROM_ADDRESS_KEY));
addPropertyAsHeader(emailXml, IMailFileSystem.SENDER_ADDRESS_KEY, properties.get(IMailFileSystem.SENDER_ADDRESS_KEY));
addPropertyAsHeader(emailXml, IMailFileSystem.REPLY_TO_RECEPIENTS_KEY, properties.get(IMailFileSystem.REPLY_TO_RECEPIENTS_KEY));
addPropertyAsHeader(emailXml, IMailFileSystem.BEST_REPLY_ADDRESS_KEY, properties.get(IMailFileSystem.BEST_REPLY_ADDRESS_KEY));
emailXml.addElement("subject", fileSystem.getSubject(emailMessage));
addPropertyAsHeader(emailXml, IMailFileSystem.DATETIME_SENT_KEY, properties.get(IMailFileSystem.DATETIME_SENT_KEY));
addPropertyAsHeader(emailXml, IMailFileSystem.DATETIME_RECEIVED_KEY, properties.get(IMailFileSystem.DATETIME_RECEIVED_KEY));
try {
emailXml.addElement("message", fileSystem.readFile(emailMessage, null).asString());
} catch (IOException e) {
throw new FileSystemException("Cannot read message body", e);
}
try (SaxElementBuilder attachmentsXml = emailXml.startElement("attachments")) {
for (Iterator<A> it = fileSystem.listAttachments(emailMessage); it != null && it.hasNext(); ) {
fileSystem.extractAttachment(it.next(), attachmentsXml);
}
} catch (Exception e) {
throw new FileSystemException("Cannot extract attachment", e);
}
try (SaxElementBuilder headersXml = emailXml.startElement("headers")) {
for (Map.Entry<String, Object> header : properties.entrySet()) {
if (!specialHeaders.contains(header.getKey())) {
addPropertyAsHeader(headersXml, "header", "name", header.getKey(), header.getValue());
}
}
}
}
use of nl.nn.adapterframework.xml.SaxElementBuilder 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.SaxElementBuilder in project iaf by ibissource.
the class JdbcUtil method warningsToXml.
public static void warningsToXml(SQLWarning warnings, SaxElementBuilder parent) throws SAXException {
if (warnings != null) {
try (SaxElementBuilder elementBuilder = parent.startElement("warnings")) {
while (warnings != null) {
try (SaxElementBuilder warning = elementBuilder.startElement("warning")) {
warning.addAttribute("errorCode", "" + warnings.getErrorCode());
warning.addAttribute("sqlState", "" + warnings.getSQLState());
String message = warnings.getMessage();
Throwable cause = warnings.getCause();
if (cause != null) {
warning.addAttribute("cause", cause.getClass().getName());
if (message == null) {
message = cause.getMessage();
} else {
message = message + ": " + cause.getMessage();
}
}
warning.addAttribute("message", message);
warnings = warnings.getNextWarning();
}
}
}
}
}
use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class DB2XMLWriter method getRowXml.
public static void getRowXml(SaxElementBuilder rows, IDbmsSupport dbmsSupport, ResultSet rs, int rowNumber, ResultSetMetaData rsmeta, String blobCharset, boolean decompressBlobs, String nullValue, boolean trimSpaces, boolean getBlobSmart) throws SenderException, SQLException, SAXException {
try (SaxElementBuilder row = rows.startElement("row")) {
row.addAttribute("number", "" + rowNumber);
for (int i = 1; i <= rsmeta.getColumnCount(); i++) {
try (SaxElementBuilder resultField = row.startElement("field")) {
String columnName = "" + rsmeta.getColumnName(i);
if (convertFieldnamesToUppercase)
columnName = columnName.toUpperCase();
resultField.addAttribute("name", columnName);
try {
String value = JdbcUtil.getValue(dbmsSupport, rs, i, rsmeta, blobCharset, decompressBlobs, nullValue, trimSpaces, getBlobSmart, false);
if (rs.wasNull()) {
resultField.addAttribute("null", "true");
}
resultField.addValue(value);
} catch (Exception e) {
throw new SenderException("error getting fieldvalue column [" + i + "] fieldType [" + getFieldType(rsmeta.getColumnType(i)) + "]", e);
}
}
}
JdbcUtil.warningsToXml(rs.getWarnings(), row);
}
}
Aggregations