Search in sources :

Example 16 with ParameterValue

use of nl.nn.adapterframework.parameters.ParameterValue 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 17 with ParameterValue

use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.

the class MailSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String from = null;
    String subject = null;
    String threadTopic = null;
    String messageType = null;
    String messageBase64 = null;
    String charset = null;
    Collection<Recipient> recipients = null;
    Collection<Attachment> attachments = null;
    ParameterValueList pvl;
    ParameterValue pv;
    String messageInMailSafeForm;
    if (paramList == null) {
        messageInMailSafeForm = sendEmail(message, prc);
    } else {
        try {
            pvl = prc.getValues(paramList);
            pv = pvl.getParameterValue("from");
            if (pv != null) {
                from = pv.asStringValue(null);
                log.debug("MailSender [" + getName() + "] retrieved from-parameter [" + from + "]");
            }
            pv = pvl.getParameterValue("subject");
            if (pv != null) {
                subject = pv.asStringValue(null);
                log.debug("MailSender [" + getName() + "] retrieved subject-parameter [" + subject + "]");
            }
            pv = pvl.getParameterValue("threadTopic");
            if (pv != null) {
                threadTopic = pv.asStringValue(null);
                log.debug("MailSender [" + getName() + "] retrieved threadTopic-parameter [" + threadTopic + "]");
            }
            pv = pvl.getParameterValue("message");
            if (pv != null) {
                message = pv.asStringValue(message);
                log.debug("MailSender [" + getName() + "] retrieved message-parameter [" + message + "]");
            }
            pv = pvl.getParameterValue("messageType");
            if (pv != null) {
                messageType = pv.asStringValue(null);
                log.debug("MailSender [" + getName() + "] retrieved messageType-parameter [" + messageType + "]");
            }
            pv = pvl.getParameterValue("messageBase64");
            if (pv != null) {
                messageBase64 = pv.asStringValue(null);
                log.debug("MailSender [" + getName() + "] retrieved messageBase64-parameter [" + messageBase64 + "]");
            }
            pv = pvl.getParameterValue("charset");
            if (pv != null) {
                charset = pv.asStringValue(null);
                log.debug("MailSender [" + getName() + "] retrieved charset-parameter [" + charset + "]");
            }
            pv = pvl.getParameterValue("recipients");
            if (pv != null) {
                recipients = retrieveRecipients(pv.asCollection());
                log.debug("MailSender [" + getName() + "] retrieved recipients-parameter [" + recipients + "]");
            }
            pv = pvl.getParameterValue("attachments");
            if (pv != null) {
                attachments = retrieveAttachments(pv.asCollection(), prc);
                log.debug("MailSender [" + getName() + "] retrieved attachments-parameter [" + attachments + "]");
            }
        } catch (ParameterException e) {
            throw new SenderException("MailSender [" + getName() + "] got exception determining parametervalues", e);
        }
        messageInMailSafeForm = sendEmail(from, subject, threadTopic, message, messageType, messageBase64, charset, recipients, attachments);
    }
    prc.getSession().put("messageInMailSafeForm", messageInMailSafeForm);
    return correlationID;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)17 SenderException (nl.nn.adapterframework.core.SenderException)8 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)7 ParameterException (nl.nn.adapterframework.core.ParameterException)6 IOException (java.io.IOException)5 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)4 URL (java.net.URL)3 TransformerException (javax.xml.transform.TransformerException)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Transformer (javax.xml.transform.Transformer)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 JCoParameterList (com.sap.conn.jco.JCoParameterList)1 JCoStructure (com.sap.conn.jco.JCoStructure)1 JCO (com.sap.mw.jco.JCO)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1