Search in sources :

Example 16 with DomBuilderException

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

the class XmlQuerySender method sendMessage.

@Override
protected String sendMessage(Connection connection, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement;
    String tableName = null;
    Vector columns = null;
    String where = null;
    String order = null;
    String result = null;
    try {
        queryElement = XmlUtils.buildElement(message);
        String root = queryElement.getTagName();
        tableName = XmlUtils.getChildTagAsString(queryElement, "tableName");
        Element columnsElement = XmlUtils.getFirstChildTag(queryElement, "columns");
        if (columnsElement != null) {
            columns = getColumns(columnsElement);
        }
        where = XmlUtils.getChildTagAsString(queryElement, "where");
        order = XmlUtils.getChildTagAsString(queryElement, "order");
        if (root.equalsIgnoreCase("select")) {
            result = selectQuery(connection, correlationID, tableName, columns, where, order);
        } else {
            if (root.equalsIgnoreCase("insert")) {
                result = insertQuery(connection, correlationID, prc, tableName, columns);
            } else {
                if (root.equalsIgnoreCase("delete")) {
                    result = deleteQuery(connection, correlationID, tableName, where);
                } else {
                    if (root.equalsIgnoreCase("update")) {
                        result = updateQuery(connection, correlationID, tableName, columns, where);
                    } else {
                        if (root.equalsIgnoreCase("alter")) {
                            String sequenceName = XmlUtils.getChildTagAsString(queryElement, "sequenceName");
                            int startWith = Integer.parseInt(XmlUtils.getChildTagAsString(queryElement, "startWith"));
                            result = alterQuery(connection, sequenceName, startWith);
                        } else {
                            if (root.equalsIgnoreCase("sql")) {
                                String type = XmlUtils.getChildTagAsString(queryElement, "type");
                                String query = XmlUtils.getChildTagAsString(queryElement, "query");
                                result = sql(connection, correlationID, query, type);
                            } else {
                                throw new SenderException(getLogPrefix() + "unknown root element [" + root + "]");
                            }
                        }
                    }
                }
            }
        }
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "got exception parsing [" + message + "]", e);
    } catch (JdbcException e) {
        throw new SenderException(getLogPrefix() + "got exception preparing [" + message + "]", e);
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Vector(java.util.Vector)

Example 17 with DomBuilderException

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

the class FixedResultSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException {
    String result = returnString;
    if (prc != null) {
        ParameterValueList pvl;
        try {
            pvl = prc.getValues(paramList);
        } catch (ParameterException e) {
            throw new SenderException("exception extracting parameters", e);
        }
        if (pvl != null) {
            for (int i = 0; i < pvl.size(); i++) {
                ParameterValue pv = pvl.getParameterValue(i);
                result = replace(result, "${" + pv.getDefinition().getName() + "}", pv.asStringValue(""));
            }
        }
    }
    if (getSubstituteVars()) {
        result = StringResolver.substVars(returnString, prc.getSession());
    }
    if (StringUtils.isNotEmpty(styleSheetName)) {
        URL xsltSource = ClassUtils.getResourceURL(classLoader, styleSheetName);
        if (xsltSource != null) {
            try {
                String xsltResult = null;
                Transformer transformer = XmlUtils.createTransformer(xsltSource);
                xsltResult = XmlUtils.transformXml(transformer, result);
                result = xsltResult;
            } catch (IOException e) {
                throw new SenderException("cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e);
            } catch (TransformerConfigurationException te) {
                throw new SenderException("got error creating transformer from file [" + styleSheetName + "]", te);
            } catch (TransformerException te) {
                throw new SenderException("got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te);
            } catch (DomBuilderException te) {
                throw new SenderException("caught DomBuilderException", te);
            }
        }
    }
    log.debug("returning fixed result [" + result + "]");
    return result;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Transformer(javax.xml.transform.Transformer) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException) IOException(java.io.IOException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) URL(java.net.URL) TransformerException(javax.xml.transform.TransformerException)

Example 18 with DomBuilderException

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

the class MailSender method sendEmail.

/**
 * Send a mail conforming to the XML input
 */
protected String sendEmail(String input, ParameterResolutionContext prc) throws SenderException {
    // initialize this request
    String from;
    String subject;
    String threadTopic;
    String message;
    String messageType;
    String messageBase64;
    String charset;
    Collection<Recipient> recipients;
    Collection<Attachment> attachments = null;
    Element emailElement;
    try {
        emailElement = XmlUtils.buildElement(input);
        from = XmlUtils.getChildTagAsString(emailElement, "from");
        subject = XmlUtils.getChildTagAsString(emailElement, "subject");
        threadTopic = XmlUtils.getChildTagAsString(emailElement, "threadTopic");
        message = XmlUtils.getChildTagAsString(emailElement, "message");
        messageType = XmlUtils.getChildTagAsString(emailElement, "messageType");
        messageBase64 = XmlUtils.getChildTagAsString(emailElement, "messageBase64");
        charset = XmlUtils.getChildTagAsString(emailElement, "charset");
        Element recipientsElement = XmlUtils.getFirstChildTag(emailElement, "recipients");
        recipients = retrieveRecipients(XmlUtils.getChildTags(recipientsElement, "recipient"));
        Element attachmentsElement = XmlUtils.getFirstChildTag(emailElement, "attachments");
        if (attachmentsElement != null)
            attachments = retrieveAttachments(XmlUtils.getChildTags(attachmentsElement, "attachment"), prc);
    } catch (DomBuilderException e) {
        throw new SenderException("exception parsing [" + input + "]", e);
    }
    return sendEmail(from, subject, threadTopic, message, messageType, messageBase64, charset, recipients, attachments);
}
Also used : Element(org.w3c.dom.Element) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 SenderException (nl.nn.adapterframework.core.SenderException)10 IOException (java.io.IOException)9 Element (org.w3c.dom.Element)9 TransformerException (javax.xml.transform.TransformerException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 ParameterException (nl.nn.adapterframework.core.ParameterException)5 Map (java.util.Map)4 Transformer (javax.xml.transform.Transformer)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)4 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)4 ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4 URL (java.net.URL)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2