Search in sources :

Example 31 with ParameterException

use of nl.nn.adapterframework.core.ParameterException 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 32 with ParameterException

use of nl.nn.adapterframework.core.ParameterException 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 33 with ParameterException

use of nl.nn.adapterframework.core.ParameterException in project iaf by ibissource.

the class IbisJavaSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String result = null;
    HashMap context = null;
    try {
        if (paramList != null) {
            context = (HashMap) prc.getValueMap(paramList);
        } else {
            context = new HashMap();
        }
        DispatcherManager dm = null;
        Class c = Class.forName("nl.nn.adapterframework.dispatcher.DispatcherManagerFactory");
        if (getDispatchType().equalsIgnoreCase("DLL")) {
            String version = nl.nn.adapterframework.dispatcher.Version.version;
            if (version.contains("IbisServiceDispatcher 1.3"))
                throw new SenderException("IBIS-ServiceDispatcher out of date! Please update to version 1.4 or higher");
            Method getDispatcherManager = c.getMethod("getDispatcherManager", String.class);
            dm = (DispatcherManager) getDispatcherManager.invoke(null, getDispatchType());
        } else {
            Method getDispatcherManager = c.getMethod("getDispatcherManager");
            dm = (DispatcherManager) getDispatcherManager.invoke(null, (Object[]) null);
        }
        result = dm.processRequest(getServiceName(), correlationID, message, context);
        if (isMultipartResponse()) {
            return HttpSender.handleMultipartResponse(multipartResponseContentType, new ByteArrayInputStream(result.getBytes(multipartResponseCharset)), prc, null);
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "exception processing message using request processor [" + getServiceName() + "]", e);
    } finally {
        if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
            log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
        }
        if (prc != null) {
            Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DispatcherManager(nl.nn.adapterframework.dispatcher.DispatcherManager) ParameterException(nl.nn.adapterframework.core.ParameterException) Method(java.lang.reflect.Method) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 34 with ParameterException

use of nl.nn.adapterframework.core.ParameterException in project iaf by ibissource.

the class IbisLocalSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String result = null;
    HashMap context = null;
    if (paramList != null) {
        try {
            context = (HashMap) prc.getValueMap(paramList);
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
        }
    } else {
        if (StringUtils.isNotEmpty(getReturnedSessionKeys())) {
            context = new HashMap();
        }
    }
    if (StringUtils.isNotEmpty(getServiceName())) {
        try {
            if (isIsolated()) {
                if (isSynchronous()) {
                    log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in separate Thread");
                    result = isolatedServiceCaller.callServiceIsolated(getServiceName(), correlationID, message, context, false);
                } else {
                    log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in asynchronously");
                    isolatedServiceCaller.callServiceAsynchronous(getServiceName(), correlationID, message, context, false);
                    result = message;
                }
            } else {
                log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in same Thread");
                result = ServiceDispatcher.getInstance().dispatchRequest(getServiceName(), correlationID, message, context);
            }
        } catch (ListenerException e) {
            if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
                throw new TimeOutException(getLogPrefix() + "timeout calling service [" + getServiceName() + "]", e);
            } else {
                throw new SenderException(getLogPrefix() + "exception calling service [" + getServiceName() + "]", e);
            }
        } finally {
            if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
                log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
            }
            if (prc != null) {
                Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
            }
        }
    } else {
        String javaListener;
        if (StringUtils.isNotEmpty(getJavaListenerSessionKey())) {
            javaListener = (String) prc.getSession().get(getJavaListenerSessionKey());
        } else {
            javaListener = getJavaListener();
        }
        try {
            JavaListener listener = JavaListener.getListener(javaListener);
            if (listener == null) {
                String msg = "could not find JavaListener [" + javaListener + "]";
                if (isThrowJavaListenerNotFoundException()) {
                    throw new SenderException(msg);
                } else {
                    log.info(getLogPrefix() + msg);
                    return "<error>" + msg + "</error>";
                }
            }
            if (isIsolated()) {
                if (isSynchronous()) {
                    log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in separate Thread");
                    result = isolatedServiceCaller.callServiceIsolated(javaListener, correlationID, message, context, true);
                } else {
                    log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in asynchronously");
                    isolatedServiceCaller.callServiceAsynchronous(javaListener, correlationID, message, context, true);
                    result = message;
                }
            } else {
                log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in same Thread");
                result = listener.processRequest(correlationID, message, context);
            }
        } catch (ListenerException e) {
            if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
                throw new TimeOutException(getLogPrefix() + "timeout calling JavaListener [" + javaListener + "]", e);
            } else {
                throw new SenderException(getLogPrefix() + "exception calling JavaListener [" + javaListener + "]", e);
            }
        } finally {
            if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
                log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
            }
            if (prc != null) {
                Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
            }
        }
    }
    return result;
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) HashMap(java.util.HashMap) JavaListener(nl.nn.adapterframework.receivers.JavaListener) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 35 with ParameterException

use of nl.nn.adapterframework.core.ParameterException 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

ParameterException (nl.nn.adapterframework.core.ParameterException)35 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)23 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)18 PipeRunException (nl.nn.adapterframework.core.PipeRunException)15 SenderException (nl.nn.adapterframework.core.SenderException)14 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)13 IOException (java.io.IOException)11 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)10 TimeOutException (nl.nn.adapterframework.core.TimeOutException)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ParameterList (nl.nn.adapterframework.parameters.ParameterList)6 JMSException (javax.jms.JMSException)5 PipeForward (nl.nn.adapterframework.core.PipeForward)5 Parameter (nl.nn.adapterframework.parameters.Parameter)5 ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)5 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 INamedObject (nl.nn.adapterframework.core.INamedObject)4