Search in sources :

Example 26 with ParameterValueList

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

the class FileUtils method getFilename.

/**
 * Construct a filename from a pattern and session variables.
 */
public static String getFilename(ParameterList definedParameters, IPipeLineSession session, String originalFilename, String filenamePattern) throws ParameterException {
    // no pattern defined, outputname = inputname
    if (StringUtils.isEmpty(filenamePattern)) {
        return originalFilename;
    }
    // obtain filename
    int ndx = originalFilename.lastIndexOf('.');
    String name = originalFilename;
    String extension = "";
    if (ndx > 0) {
        name = originalFilename.substring(0, ndx);
        extension = originalFilename.substring(ndx + 1);
    }
    // construct the parameterlist
    ParameterList pl = new ParameterList();
    try {
        if (definedParameters != null)
            pl.addAll(definedParameters);
        Parameter p = new Parameter();
        p.setName("file");
        p.setDefaultValue(name);
        p.configure();
        pl.add(p);
        p = new Parameter();
        p.setName("ext");
        p.setDefaultValue(extension);
        p.configure();
        pl.add(p);
        p = new Parameter();
        p.setName("__filename");
        p.setPattern(filenamePattern);
        p.configure();
        pl.add(p);
    } catch (ConfigurationException e) {
        throw new ParameterException(e);
    }
    // resolve the parameters
    ParameterResolutionContext prc = new ParameterResolutionContext((String) null, session);
    ParameterValueList pvl = prc.getValues(pl);
    String filename = pvl.getParameterValue("__filename").getValue().toString();
    return filename;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 27 with ParameterValueList

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

the class GetTibcoQueues method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    String url_work;
    String authAlias_work;
    String userName_work;
    String password_work;
    String queueName_work = null;
    ParameterValueList pvl = null;
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
        }
    }
    url_work = getParameterValue(pvl, "url");
    if (url_work == null) {
        url_work = getUrl();
    }
    authAlias_work = getParameterValue(pvl, "authAlias");
    if (authAlias_work == null) {
        authAlias_work = getAuthAlias();
    }
    userName_work = getParameterValue(pvl, "userName");
    if (userName_work == null) {
        userName_work = getUserName();
    }
    password_work = getParameterValue(pvl, "password");
    if (password_work == null) {
        password_work = getPassword();
    }
    CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
    Connection connection = null;
    Session jSession = null;
    TibjmsAdmin admin = null;
    try {
        admin = TibcoUtils.getActiveServerAdmin(url_work, cf);
        if (admin == null) {
            throw new PipeRunException(this, "could not find an active server");
        }
        String ldapUrl = getParameterValue(pvl, "ldapUrl");
        LdapSender ldapSender = null;
        if (StringUtils.isNotEmpty(ldapUrl)) {
            ldapSender = retrieveLdapSender(ldapUrl, cf);
        }
        queueName_work = getParameterValue(pvl, "queueName");
        if (StringUtils.isNotEmpty(queueName_work)) {
            String countOnly_work = getParameterValue(pvl, "countOnly");
            boolean countOnly = ("true".equalsIgnoreCase(countOnly_work) ? true : false);
            if (countOnly) {
                return getQueueMessageCountOnly(admin, queueName_work);
            }
        }
        ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work);
        connection = factory.createConnection(cf.getUsername(), cf.getPassword());
        jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        if (StringUtils.isNotEmpty(queueName_work)) {
            String queueItem_work = getParameterValue(pvl, "queueItem");
            int qi;
            if (StringUtils.isNumeric(queueItem_work)) {
                qi = Integer.parseInt(queueItem_work);
            } else {
                qi = 1;
            }
            result = getQueueMessage(jSession, admin, queueName_work, qi, ldapSender);
        } else {
            String showAge_work = getParameterValue(pvl, "showAge");
            boolean showAge = ("true".equalsIgnoreCase(showAge_work) ? true : false);
            result = getQueuesInfo(jSession, admin, showAge, ldapSender);
        }
    } catch (Exception e) {
        String msg = getLogPrefix(session) + "exception on showing Tibco queues, url [" + url_work + "]" + (StringUtils.isNotEmpty(queueName_work) ? " queue [" + queueName_work + "]" : "");
        throw new PipeRunException(this, msg, e);
    } finally {
        if (admin != null) {
            try {
                admin.close();
            } catch (TibjmsAdminException e) {
                log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e);
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.warn(getLogPrefix(session) + "exception on closing connection", e);
            }
        }
    }
    return result;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) LdapSender(nl.nn.adapterframework.ldap.LdapSender) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) TibjmsAdmin(com.tibco.tibjms.admin.TibjmsAdmin) PipeRunException(nl.nn.adapterframework.core.PipeRunException) TibjmsAdminInvalidNameException(com.tibco.tibjms.admin.TibjmsAdminInvalidNameException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) UnknownHostException(java.net.UnknownHostException) JMSException(javax.jms.JMSException) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) ParameterException(nl.nn.adapterframework.core.ParameterException) ConnectionFactory(javax.jms.ConnectionFactory) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Session(javax.jms.Session) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Example 28 with ParameterValueList

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

the class SapSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String tid = null;
    try {
        ParameterValueList pvl = null;
        if (prc != null) {
            pvl = prc.getValues(paramList);
        }
        SapSystem sapSystem = getSystem(pvl);
        JCoFunction function = getFunction(sapSystem, pvl);
        if (StringUtils.isEmpty(getSapSystemName())) {
            pvl.removeParameterValue(getSapSystemNameParam());
        }
        if (StringUtils.isEmpty(getFunctionName())) {
            pvl.removeParameterValue(getFunctionNameParam());
        }
        message2FunctionCall(function, message, correlationID, pvl);
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + " function call [" + functionCall2message(function) + "]");
        JCoDestination destination = getDestination(prc.getSession(), sapSystem);
        tid = getTid(destination, sapSystem);
        if (StringUtils.isEmpty(tid)) {
            function.execute(destination);
        } else {
            function.execute(destination, tid);
        }
        if (isSynchronous()) {
            return functionResult2message(function);
        } else {
            return tid;
        }
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) JCoFunction(com.sap.conn.jco.JCoFunction) JCoDestination(com.sap.conn.jco.JCoDestination) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 29 with ParameterValueList

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

use of nl.nn.adapterframework.parameters.ParameterValueList 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

ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)30 ParameterException (nl.nn.adapterframework.core.ParameterException)23 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)16 SenderException (nl.nn.adapterframework.core.SenderException)15 PipeRunException (nl.nn.adapterframework.core.PipeRunException)13 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)11 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)8 IOException (java.io.IOException)7 ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)6 JMSException (javax.jms.JMSException)5 Parameter (nl.nn.adapterframework.parameters.Parameter)5 URL (java.net.URL)4 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)4 HashMap (java.util.HashMap)3 Session (javax.jms.Session)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 ParameterList (nl.nn.adapterframework.parameters.ParameterList)3 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)3