Search in sources :

Example 1 with SaxElementBuilder

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);
        }
    }
}
Also used : SaxElementBuilder(nl.nn.adapterframework.xml.SaxElementBuilder)

Example 2 with SaxElementBuilder

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());
            }
        }
    }
}
Also used : SaxElementBuilder(nl.nn.adapterframework.xml.SaxElementBuilder) IOException(java.io.IOException) Map(java.util.Map) AddressException(javax.mail.internet.AddressException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with SaxElementBuilder

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());
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Message(nl.nn.adapterframework.stream.Message) SaxElementBuilder(nl.nn.adapterframework.xml.SaxElementBuilder) IOException(java.io.IOException) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) SAXException(org.xml.sax.SAXException)

Example 4 with SaxElementBuilder

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();
                }
            }
        }
    }
}
Also used : SaxElementBuilder(nl.nn.adapterframework.xml.SaxElementBuilder)

Example 5 with SaxElementBuilder

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);
    }
}
Also used : SaxElementBuilder(nl.nn.adapterframework.xml.SaxElementBuilder) SenderException(nl.nn.adapterframework.core.SenderException) SQLException(java.sql.SQLException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

SaxElementBuilder (nl.nn.adapterframework.xml.SaxElementBuilder)15 Test (org.junit.Test)7 SAXException (org.xml.sax.SAXException)5 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 SenderException (nl.nn.adapterframework.core.SenderException)2 SaxDocumentBuilder (nl.nn.adapterframework.xml.SaxDocumentBuilder)2 XmlWriter (nl.nn.adapterframework.xml.XmlWriter)2 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 Map (java.util.Map)1 AddressException (javax.mail.internet.AddressException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 Message (nl.nn.adapterframework.stream.Message)1 MessageOutputStream (nl.nn.adapterframework.stream.MessageOutputStream)1 PrettyPrintFilter (nl.nn.adapterframework.xml.PrettyPrintFilter)1