Search in sources :

Example 1 with LdapSender

use of nl.nn.adapterframework.ldap.LdapSender in project iaf by ibissource.

the class GetTibcoQueues method retrieveLdapSender.

private LdapSender retrieveLdapSender(String ldapUrl, CredentialFactory cf) {
    try {
        LdapSender ldapSender = new LdapSender();
        ldapSender.setProviderURL(ldapUrl);
        ldapSender.setAttributesToReturn("cn,description");
        if (StringUtils.isNotEmpty(cf.getAlias())) {
            ldapSender.setJndiAuthAlias(cf.getAlias());
        }
        if (StringUtils.isNotEmpty(cf.getUsername())) {
            ldapSender.setPrincipal(cf.getUsername());
        }
        if (StringUtils.isNotEmpty(cf.getPassword())) {
            ldapSender.setCredentials(cf.getPassword());
        }
        Parameter p = new Parameter();
        p.setName("entryName");
        p.setXpathExpression("concat('cn=',*)");
        p.configure();
        ldapSender.addParameter(p);
        ldapSender.configure();
        return ldapSender;
    } catch (ConfigurationException e) {
        log.warn(getLogPrefix(null) + "exception on retrieving ldapSender", e);
    }
    return null;
}
Also used : LdapSender(nl.nn.adapterframework.ldap.LdapSender) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Parameter(nl.nn.adapterframework.parameters.Parameter)

Example 2 with LdapSender

use of nl.nn.adapterframework.ldap.LdapSender 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)

Aggregations

ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 LdapSender (nl.nn.adapterframework.ldap.LdapSender)2 TibjmsAdmin (com.tibco.tibjms.admin.TibjmsAdmin)1 TibjmsAdminException (com.tibco.tibjms.admin.TibjmsAdminException)1 TibjmsAdminInvalidNameException (com.tibco.tibjms.admin.TibjmsAdminInvalidNameException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 JMSException (javax.jms.JMSException)1 Session (javax.jms.Session)1 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)1 ParameterException (nl.nn.adapterframework.core.ParameterException)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 Parameter (nl.nn.adapterframework.parameters.Parameter)1 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)1 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)1 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)1