Search in sources :

Example 16 with ParameterException

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

the class JmsSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc, String soapHeader) throws SenderException, TimeOutException {
    Session s = null;
    MessageProducer mp = null;
    ParameterValueList pvl = null;
    if (prc != null && paramList != null) {
        try {
            pvl = prc.getValues(paramList);
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "cannot extract parameters", e);
        }
    }
    if (isSoap()) {
        if (soapHeader == null) {
            if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) {
                ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam());
                if (soapHeaderParamValue == null) {
                    log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]");
                } else {
                    soapHeader = soapHeaderParamValue.asStringValue("");
                }
            }
        }
        message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(), soapHeader);
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]");
    }
    try {
        s = createSession();
        mp = getMessageProducer(s, getDestination(prc));
        Destination replyQueue = null;
        // create message
        Message msg = createTextMessage(s, correlationID, message);
        if (getMessageType() != null) {
            msg.setJMSType(getMessageType());
        }
        if (getDeliveryModeInt() > 0) {
            msg.setJMSDeliveryMode(getDeliveryModeInt());
            mp.setDeliveryMode(getDeliveryModeInt());
        }
        if (getPriority() >= 0) {
            msg.setJMSPriority(getPriority());
            mp.setPriority(getPriority());
        }
        // set properties
        if (pvl != null) {
            setProperties(msg, pvl);
        }
        if (replyToName != null) {
            replyQueue = getDestination(replyToName);
        } else {
            if (isSynchronous()) {
                replyQueue = getMessagingSource().getDynamicReplyQueue(s);
            }
        }
        if (replyQueue != null) {
            msg.setJMSReplyTo(replyQueue);
            if (log.isDebugEnabled())
                log.debug("replyTo set to queue [" + replyQueue.toString() + "]");
        }
        // send message
        send(mp, msg);
        if (log.isDebugEnabled()) {
            log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
        } else {
            if (log.isInfoEnabled()) {
                log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
            }
        }
        if (isSynchronous()) {
            String replyCorrelationId = null;
            if (replyToName != null) {
                if ("CORRELATIONID".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = correlationID;
                } else if ("CORRELATIONID_FROM_MESSAGE".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = msg.getJMSCorrelationID();
                } else {
                    replyCorrelationId = msg.getJMSMessageID();
                }
            }
            if (log.isDebugEnabled())
                log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for [" + getReplyTimeout() + "] ms");
            MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId);
            try {
                Message rawReplyMsg = mc.receive(getReplyTimeout());
                if (rawReplyMsg == null) {
                    throw new TimeOutException("did not receive reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] within [" + getReplyTimeout() + "] ms");
                }
                return getStringFromRawMessage(rawReplyMsg, prc != null ? prc.getSession() : null, isSoap(), getReplySoapHeaderSessionKey(), soapWrapper);
            } finally {
                if (mc != null) {
                    try {
                        mc.close();
                    } catch (JMSException e) {
                        log.warn("JmsSender [" + getName() + "] got exception closing message consumer for reply", e);
                    }
                }
            }
        }
        return msg.getJMSMessageID();
    } catch (JMSException e) {
        throw new SenderException(e);
    } catch (IOException e) {
        throw new SenderException(e);
    } catch (NamingException e) {
        throw new SenderException(e);
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    } catch (TransformerException e) {
        throw new SenderException(e);
    } catch (JmsException e) {
        throw new SenderException(e);
    } finally {
        if (mp != null) {
            try {
                mp.close();
            } catch (JMSException e) {
                log.warn("JmsSender [" + getName() + "] got exception closing message producer", e);
            }
        }
        closeSession(s);
    }
}
Also used : Destination(javax.jms.Destination) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) MessageConsumer(javax.jms.MessageConsumer) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) Message(javax.jms.Message) JMSException(javax.jms.JMSException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ParameterException(nl.nn.adapterframework.core.ParameterException) NamingException(javax.naming.NamingException) MessageProducer(javax.jms.MessageProducer) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) TransformerException(javax.xml.transform.TransformerException) Session(javax.jms.Session)

Example 17 with ParameterException

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

the class Parameter method getValueForFormatting.

private Object getValueForFormatting(ParameterValueList alreadyResolvedParameters, ParameterResolutionContext prc, String name) throws ParameterException {
    ParameterValue paramValue = alreadyResolvedParameters.getParameterValue(name);
    Object substitutionValue = paramValue == null ? null : paramValue.getValue();
    if (substitutionValue == null) {
        substitutionValue = prc.getSession().get(name);
    }
    if (substitutionValue == null) {
        if ("now".equals(name.toLowerCase())) {
            substitutionValue = new Date();
        } else if ("uid".equals(name.toLowerCase())) {
            substitutionValue = Misc.createSimpleUUID();
        } else if ("uuid".equals(name.toLowerCase())) {
            substitutionValue = Misc.createRandomUUID();
        } else if ("hostname".equals(name.toLowerCase())) {
            substitutionValue = Misc.getHostname();
        } else if ("fixeddate".equals(name.toLowerCase())) {
            if (!ConfigurationUtils.stubConfiguration()) {
                throw new ParameterException("Parameter pattern [" + name + "] only allowed in stub mode");
            }
            Date d;
            SimpleDateFormat formatterFrom = new SimpleDateFormat(PutSystemDateInSession.FORMAT_FIXEDDATETIME);
            String fixedDateTime = (String) prc.getSession().get(PutSystemDateInSession.FIXEDDATE_STUB4TESTTOOL_KEY);
            if (StringUtils.isEmpty(fixedDateTime)) {
                fixedDateTime = PutSystemDateInSession.FIXEDDATETIME;
            }
            try {
                d = formatterFrom.parse(fixedDateTime);
            } catch (ParseException e) {
                throw new ParameterException("Cannot parse fixed date [" + PutSystemDateInSession.FIXEDDATETIME + "] with format [" + PutSystemDateInSession.FORMAT_FIXEDDATETIME + "]", e);
            }
            substitutionValue = d;
        } else if ("fixeduid".equals(name.toLowerCase())) {
            if (!ConfigurationUtils.stubConfiguration()) {
                throw new ParameterException("Parameter pattern [" + name + "] only allowed in stub mode");
            }
            substitutionValue = FIXEDUID;
        } else if ("fixedhostname".equals(name.toLowerCase())) {
            if (!ConfigurationUtils.stubConfiguration()) {
                throw new ParameterException("Parameter pattern [" + name + "] only allowed in stub mode");
            }
            substitutionValue = FIXEDHOSTNAME;
        }
    }
    if (substitutionValue == null) {
        throw new ParameterException("Parameter with name [" + name + "] in pattern" + pattern + " can not be resolved");
    }
    return substitutionValue;
}
Also used : INamedObject(nl.nn.adapterframework.core.INamedObject) ParameterException(nl.nn.adapterframework.core.ParameterException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 18 with ParameterException

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

the class LdapChallengePipe method doPipe.

/**
 * Checks to see if the supplied parameteres of the pipe can login to LDAP
 * @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.PipeLineSession)
 */
public PipeRunResult doPipe(Object msg, IPipeLineSession pls) throws PipeRunException {
    LdapSender ldapSender = new LdapSender();
    String ldapProviderURL;
    String credentials;
    String principal;
    ParameterResolutionContext prc;
    try {
        prc = new ParameterResolutionContext((String) msg, pls);
        Map paramMap = prc.getValueMap(getParameterList());
        if (StringUtils.isNotEmpty(getLdapProviderURL())) {
            ldapProviderURL = getLdapProviderURL();
        } else {
            ldapProviderURL = (String) paramMap.get("ldapProviderURL");
        }
        credentials = (String) paramMap.get("credentials");
        principal = (String) paramMap.get("principal");
    } catch (ParameterException e) {
        throw new PipeRunException(this, "Invalid parameter", e);
    }
    ldapSender.setErrorSessionKey(getErrorSessionKey());
    if (StringUtils.isEmpty(ldapProviderURL)) {
        throw new PipeRunException(this, "ldapProviderURL is empty");
    }
    if (StringUtils.isEmpty(principal)) {
        // throw new PipeRunException(this, "principal is empty");
        handleError(ldapSender, prc, 34, "Principal is Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    if (StringUtils.isEmpty(credentials)) {
        // throw new PipeRunException(this, "credentials are empty");
        handleError(ldapSender, prc, 49, "Credentials are Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    Parameter dummyEntryName = new Parameter();
    dummyEntryName.setName("entryName");
    dummyEntryName.setValue(principal);
    ldapSender.addParameter(dummyEntryName);
    ldapSender.setUsePooling(false);
    ldapSender.setLdapProviderURL(ldapProviderURL);
    if (StringUtils.isNotEmpty(getInitialContextFactoryName())) {
        ldapSender.setInitialContextFactoryName(getInitialContextFactoryName());
    }
    ldapSender.setPrincipal(principal);
    ldapSender.setCredentials(credentials);
    ldapSender.setOperation(LdapSender.OPERATION_READ);
    try {
        log.debug("Looking up context for principal [" + principal + "]");
        ldapSender.configure();
        log.debug("Succesfully looked up context for principal [" + principal + "]");
    } catch (Exception e) {
        if (StringUtils.isNotEmpty(getErrorSessionKey())) {
            ldapSender.storeLdapException(e, prc);
        } else {
            log.warn("LDAP error looking up context for principal [" + principal + "]", e);
        }
        return new PipeRunResult(findForward("invalid"), msg);
    }
    return new PipeRunResult(findForward("success"), msg);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 19 with ParameterException

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

the class FixedForwardPipe method doInitialPipe.

public PipeRunResult doInitialPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if ((input == null || StringUtils.isEmpty(input.toString())) && isSkipOnEmptyInput()) {
        return new PipeRunResult(getForward(), input);
    }
    if (getIfParam() != null) {
        boolean skipPipe = true;
        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);
            }
        }
        String ip = getParameterValue(pvl, getIfParam());
        if (ip == null) {
            if (getIfValue() == null) {
                skipPipe = false;
            }
        } else {
            if (getIfValue() != null && getIfValue().equalsIgnoreCase(ip)) {
                skipPipe = false;
            }
        }
        if (skipPipe) {
            return new PipeRunResult(getForward(), input);
        }
    }
    return null;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 20 with ParameterException

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

the class FixedResult method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result = returnString;
    if ((StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) || StringUtils.isNotEmpty(getFileNameSessionKey())) {
        String fileName = null;
        if (StringUtils.isNotEmpty(getFileNameSessionKey())) {
            fileName = (String) session.get(fileNameSessionKey);
        }
        if (fileName == null) {
            if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
                fileName = getFileName();
            }
        }
        URL resource = null;
        try {
            resource = ClassUtils.getResourceURL(classLoader, fileName);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + fileName + "]", e);
        }
        if (resource == null) {
            PipeForward fileNotFoundForward = findForward(FILE_NOT_FOUND_FORWARD);
            if (fileNotFoundForward != null) {
                return new PipeRunResult(fileNotFoundForward, input);
            } else {
                throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + fileName + "]");
            }
        }
        try {
            result = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + fileName + "]", e);
        }
    }
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        ParameterValueList pvl;
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
        for (int i = 0; i < pvl.size(); i++) {
            ParameterValue pv = pvl.getParameterValue(i);
            String replaceFrom;
            if (isReplaceFixedParams()) {
                replaceFrom = pv.getDefinition().getName();
            } else {
                replaceFrom = "${" + pv.getDefinition().getName() + "}";
            }
            result = replace(result, replaceFrom, pv.asStringValue(""));
        }
    }
    if (getSubstituteVars()) {
        result = StringResolver.substVars(returnString, session, appConstants);
    }
    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 PipeRunException(this, getLogPrefix(session) + "cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e);
            } catch (TransformerConfigurationException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "got error creating transformer from file [" + styleSheetName + "]", te);
            } catch (TransformerException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te);
            } catch (DomBuilderException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "caught DomBuilderException", te);
            }
        }
    }
    log.debug(getLogPrefix(session) + " returning fixed result [" + result + "]");
    return new PipeRunResult(getForward(), 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) IOException(java.io.IOException) PipeForward(nl.nn.adapterframework.core.PipeForward) URL(java.net.URL) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) TransformerException(javax.xml.transform.TransformerException)

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