Search in sources :

Example 76 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class RecordXmlTransformer method getXml.

protected String getXml(List parsedRecord) {
    XmlBuilder record = new XmlBuilder(getRootTag());
    int ndx = 0;
    for (Iterator it = outputFields.iterator(); it.hasNext(); ) {
        // get tagname
        String tagName = (String) it.next();
        // get value
        String value = "";
        if (ndx < parsedRecord.size()) {
            value = (String) parsedRecord.get(ndx++);
            if (!it.hasNext() && !StringUtils.isEmpty(endOfRecord)) {
                if (value.endsWith(endOfRecord)) {
                    int ei = value.length() - endOfRecord.length();
                    value = value.substring(0, ei);
                }
            }
        }
        // if tagname is empty, then it is not added to the XML
        if (!StringUtils.isEmpty(tagName)) {
            XmlBuilder field = new XmlBuilder(tagName);
            field.setValue(value, true);
            record.addSubElement(field);
        }
    }
    return record.toXML();
}
Also used : Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 77 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class ExchangeMailListener method getStringFromRawMessage.

public String getStringFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
    Item item = (Item) rawMessage;
    try {
        XmlBuilder emailXml = new XmlBuilder("email");
        EmailMessage emailMessage;
        PropertySet ps;
        if (isSimple()) {
            ps = new PropertySet(EmailMessageSchema.Subject);
            emailMessage = EmailMessage.bind(exchangeService, item.getId(), ps);
            addEmailInfoSimple(emailMessage, emailXml);
        } else {
            ps = new PropertySet(EmailMessageSchema.DateTimeReceived, EmailMessageSchema.From, EmailMessageSchema.Subject, EmailMessageSchema.Body, EmailMessageSchema.DateTimeSent);
            emailMessage = EmailMessage.bind(exchangeService, item.getId(), ps);
            addEmailInfo(emailMessage, emailXml);
        }
        if (StringUtils.isNotEmpty(getStoreEmailAsStreamInSessionKey())) {
            emailMessage.load(new PropertySet(ItemSchema.MimeContent));
            MimeContent mc = emailMessage.getMimeContent();
            ByteArrayInputStream bis = new ByteArrayInputStream(mc.getContent());
            threadContext.put(getStoreEmailAsStreamInSessionKey(), bis);
        }
        return emailXml.toXML();
    } catch (Exception e) {
        throw new ListenerException(e);
    }
}
Also used : Item(microsoft.exchange.webservices.data.core.service.item.Item) EmailMessage(microsoft.exchange.webservices.data.core.service.item.EmailMessage) ListenerException(nl.nn.adapterframework.core.ListenerException) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeContent(microsoft.exchange.webservices.data.property.complex.MimeContent) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) PropertySet(microsoft.exchange.webservices.data.core.PropertySet) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 78 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class ExchangeMailListener method addEmailInfo.

private void addEmailInfo(EmailMessage emailMessage, XmlBuilder emailXml) throws Exception {
    XmlBuilder recipientsXml = new XmlBuilder("recipients");
    EmailAddressCollection eacTo = emailMessage.getToRecipients();
    if (eacTo != null) {
        for (Iterator it = eacTo.iterator(); it.hasNext(); ) {
            XmlBuilder recipientXml = new XmlBuilder("recipient");
            EmailAddress ea = (EmailAddress) it.next();
            recipientXml.addAttribute("type", "to");
            recipientXml.setValue(ea.getAddress());
            recipientsXml.addSubElement(recipientXml);
        }
    }
    EmailAddressCollection eacCc = emailMessage.getCcRecipients();
    if (eacCc != null) {
        for (Iterator it = eacCc.iterator(); it.hasNext(); ) {
            XmlBuilder recipientXml = new XmlBuilder("recipient");
            EmailAddress ea = (EmailAddress) it.next();
            recipientXml.addAttribute("type", "cc");
            recipientXml.setValue(ea.getAddress());
            recipientsXml.addSubElement(recipientXml);
        }
    }
    EmailAddressCollection eacBcc = emailMessage.getBccRecipients();
    if (eacBcc != null) {
        for (Iterator it = eacBcc.iterator(); it.hasNext(); ) {
            XmlBuilder recipientXml = new XmlBuilder("recipient");
            EmailAddress ea = (EmailAddress) it.next();
            recipientXml.addAttribute("type", "bcc");
            recipientXml.setValue(ea.getAddress());
            recipientsXml.addSubElement(recipientXml);
        }
    }
    emailXml.addSubElement(recipientsXml);
    XmlBuilder fromXml = new XmlBuilder("from");
    fromXml.setValue(emailMessage.getFrom().getAddress());
    emailXml.addSubElement(fromXml);
    XmlBuilder subjectXml = new XmlBuilder("subject");
    subjectXml.setCdataValue(emailMessage.getSubject());
    emailXml.addSubElement(subjectXml);
    XmlBuilder messageXml = new XmlBuilder("message");
    messageXml.setCdataValue(MessageBody.getStringFromMessageBody(emailMessage.getBody()));
    emailXml.addSubElement(messageXml);
    XmlBuilder attachmentsXml = new XmlBuilder("attachments");
    AttachmentCollection ac = emailMessage.getAttachments();
    if (ac != null) {
        for (Iterator it = ac.iterator(); it.hasNext(); ) {
            XmlBuilder attachmentXml = new XmlBuilder("attachment");
            Attachment att = (Attachment) it.next();
            att.load();
            attachmentXml.addAttribute("name", att.getName());
            if (att instanceof ItemAttachment) {
                ItemAttachment ia = (ItemAttachment) att;
                Item aItem = ia.getItem();
                if (aItem instanceof EmailMessage) {
                    EmailMessage em;
                    em = (EmailMessage) aItem;
                    addEmailInfo(em, attachmentXml);
                }
            }
            attachmentsXml.addSubElement(attachmentXml);
        }
    }
    emailXml.addSubElement(attachmentsXml);
    XmlBuilder headersXml = new XmlBuilder("headers");
    InternetMessageHeaderCollection imhc = null;
    try {
        imhc = emailMessage.getInternetMessageHeaders();
    } catch (Exception e) {
        log.info("error occurred during getting internet message headers: " + e.getMessage());
    }
    if (imhc != null) {
        for (Iterator it = imhc.iterator(); it.hasNext(); ) {
            XmlBuilder headerXml = new XmlBuilder("header");
            InternetMessageHeader imh = (InternetMessageHeader) it.next();
            headerXml.addAttribute("name", imh.getName());
            headerXml.setCdataValue(imh.getValue());
            headersXml.addSubElement(headerXml);
        }
    }
    emailXml.addSubElement(headersXml);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    Date dateTimeSend = emailMessage.getDateTimeSent();
    XmlBuilder dateTimeSentXml = new XmlBuilder("dateTimeSent");
    dateTimeSentXml.setValue(sdf.format(dateTimeSend));
    emailXml.addSubElement(dateTimeSentXml);
    Date dateTimeReceived = emailMessage.getDateTimeReceived();
    XmlBuilder dateTimeReceivedXml = new XmlBuilder("dateTimeReceived");
    dateTimeReceivedXml.setValue(sdf.format(dateTimeReceived));
    emailXml.addSubElement(dateTimeReceivedXml);
}
Also used : EmailMessage(microsoft.exchange.webservices.data.core.service.item.EmailMessage) ItemAttachment(microsoft.exchange.webservices.data.property.complex.ItemAttachment) Attachment(microsoft.exchange.webservices.data.property.complex.Attachment) ItemAttachment(microsoft.exchange.webservices.data.property.complex.ItemAttachment) AttachmentCollection(microsoft.exchange.webservices.data.property.complex.AttachmentCollection) EmailAddress(microsoft.exchange.webservices.data.property.complex.EmailAddress) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Date(java.util.Date) InternetMessageHeaderCollection(microsoft.exchange.webservices.data.property.complex.InternetMessageHeaderCollection) InternetMessageHeader(microsoft.exchange.webservices.data.property.complex.InternetMessageHeader) Item(microsoft.exchange.webservices.data.core.service.item.Item) EmailAddressCollection(microsoft.exchange.webservices.data.property.complex.EmailAddressCollection) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 79 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class SchedulerAdapter method getSchedulerMetaDataToXml.

public XmlBuilder getSchedulerMetaDataToXml(Scheduler theScheduler) {
    XmlBuilder xbRoot = new XmlBuilder("schedulerMetaData");
    try {
        SchedulerMetaData smd = theScheduler.getMetaData();
        xbRoot.addAttribute("schedulerName", smd.getSchedulerName());
        xbRoot.addAttribute("schedulerInstanceId", smd.getSchedulerInstanceId().toString());
        xbRoot.addAttribute("version", smd.getVersion());
        xbRoot.addAttribute("isPaused", (smd.isInStandbyMode() ? "True" : "False"));
        xbRoot.addAttribute("isSchedulerRemote", (smd.isSchedulerRemote() ? "True" : "False"));
        xbRoot.addAttribute("isShutdown", (smd.isShutdown() ? "True" : "False"));
        xbRoot.addAttribute("isStarted", (smd.isStarted() ? "True" : "False"));
        xbRoot.addAttribute("jobStoreSupportsPersistence", (smd.jobStoreSupportsPersistence() ? "True" : "False"));
        xbRoot.addAttribute("numJobsExecuted", Integer.toString(smd.getNumberOfJobsExecuted()));
        try {
            Date runningSince = smd.getRunningSince();
            xbRoot.addAttribute("runningSince", (null == runningSince ? "unknown" : DateUtils.format(runningSince, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        xbRoot.addAttribute("jobStoreClass", smd.getJobStoreClass().getName());
        xbRoot.addAttribute("schedulerClass", smd.getSchedulerClass().getName());
        xbRoot.addAttribute("threadPoolClass", smd.getThreadPoolClass().getName());
        xbRoot.addAttribute("threadPoolSize", Integer.toString(smd.getThreadPoolSize()));
    } catch (SchedulerException se) {
        log.error(se);
    }
    return xbRoot;
}
Also used : SchedulerException(org.quartz.SchedulerException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) SchedulerMetaData(org.quartz.SchedulerMetaData) Date(java.util.Date) SchedulerException(org.quartz.SchedulerException)

Example 80 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class SchedulerAdapter method getJobMessages.

public XmlBuilder getJobMessages(JobDef jobdef) {
    XmlBuilder jobMessages = new XmlBuilder("jobMessages");
    if (jobdef != null) {
        MessageKeeper jobMessageKeeper = jobdef.getMessageKeeper();
        if (jobMessageKeeper != null) {
            for (int t = 0; t < jobMessageKeeper.size(); t++) {
                XmlBuilder jobMessage = new XmlBuilder("jobMessage");
                jobMessage.setValue(jobMessageKeeper.getMessage(t).getMessageText(), true);
                jobMessage.addAttribute("date", DateUtils.format(jobMessageKeeper.getMessage(t).getMessageDate(), DateUtils.FORMAT_FULL_GENERIC));
                jobMessage.addAttribute("level", jobMessageKeeper.getMessage(t).getMessageLevel());
                jobMessages.addSubElement(jobMessage);
            }
        }
    }
    return jobMessages;
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) MessageKeeper(nl.nn.adapterframework.util.MessageKeeper)

Aggregations

XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)108 IOException (java.io.IOException)18 Iterator (java.util.Iterator)17 ArrayList (java.util.ArrayList)12 Date (java.util.Date)12 SenderException (nl.nn.adapterframework.core.SenderException)12 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)10 Configuration (nl.nn.adapterframework.configuration.Configuration)9 SchedulerException (org.quartz.SchedulerException)8 ServletException (javax.servlet.ServletException)7 TransformerException (javax.xml.transform.TransformerException)7 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 PipeRunException (nl.nn.adapterframework.core.PipeRunException)6 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)6 JmsException (nl.nn.adapterframework.jms.JmsException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Adapter (nl.nn.adapterframework.core.Adapter)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Map (java.util.Map)4