Search in sources :

Example 6 with ParameterValueList

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

the class EtagHandlerPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null input");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
    }
    String uriPatternSessionKey = null;
    ParameterValueList pvl = null;
    ParameterList parameterList = getParameterList();
    if (parameterList != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
            if (pvl != null) {
                for (int i = 0; i < parameterList.size(); i++) {
                    Parameter parameter = parameterList.getParameter(i);
                    if ("uriPattern".equalsIgnoreCase(parameter.getName()))
                        uriPatternSessionKey = (String) parameter.getValue(pvl, prc);
                }
            }
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    // hash over data genereren, uit cache lezen en teruggeven, in cache updaten, verwijderen uit cache, cache naar disk wegschrijven, cache legen
    String cacheKey = null;
    if (uriPatternSessionKey != null && !uriPatternSessionKey.isEmpty())
        cacheKey = getRestPath() + "_" + uriPatternSessionKey.toLowerCase();
    else
        cacheKey = getRestPath() + "_" + getUriPattern();
    if (cache != null && cache.containsKey(cacheKey)) {
        Object returnCode = false;
        if (getAction().equalsIgnoreCase("generate")) {
            cache.put(cacheKey, RestListenerUtils.formatEtag(getRestPath(), getUriPattern(), input.hashCode()));
            returnCode = true;
        } else if (getAction().equalsIgnoreCase("get")) {
            returnCode = cache.get(cacheKey);
        } else if (getAction().equalsIgnoreCase("set")) {
            cache.put(cacheKey, input.toString());
            returnCode = true;
        } else if (getAction().equalsIgnoreCase("delete")) {
            returnCode = cache.remove(cacheKey);
        } else if (getAction().equalsIgnoreCase("flush")) {
            if (cache instanceof ApiEhcache) {
                ((ApiEhcache) cache).flush();
                returnCode = true;
            }
        } else if (getAction().equalsIgnoreCase("clear")) {
            cache.clear();
            returnCode = true;
        } else {
            throw new PipeRunException(this, getLogPrefix(session) + "action not found [" + getAction() + "]");
        }
        if (log.isDebugEnabled())
            log.debug("found eTag cacheKey [" + cacheKey + "] with action [" + getAction() + "]");
        return new PipeRunResult(getForward(), returnCode);
    } else {
        PipeForward pipeForward = findForward("exception");
        String msg;
        if (cache == null)
            msg = "failed to locate cache";
        else
            msg = "failed to locate eTag [" + cacheKey + "] in cache";
        if (pipeForward == null) {
            throw new PipeRunException(this, getLogPrefix(session) + msg);
        }
        return new PipeRunResult(pipeForward, "");
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) ApiEhcache(nl.nn.adapterframework.http.rest.ApiEhcache) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 7 with ParameterValueList

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

the class IfsaRequesterSender method sendMessage.

public String sendMessage(String dummyCorrelationId, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    try {
        if (isSynchronous()) {
            if (JtaUtil.inTransaction()) {
                throw new SenderException("cannot send RR message from within a transaction");
            }
        } else {
            if (!JtaUtil.inTransaction()) {
                log.warn("FF messages should be sent from within a transaction");
            }
        }
    } catch (Exception e) {
        // N.B. do not move this catch clause down; this will catch TimeOutExceptions unwantedly
        throw new SenderException(e);
    }
    ParameterValueList paramValueList;
    try {
        paramValueList = prc.getValues(paramList);
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "caught ParameterException in sendMessage() determining serviceId", e);
    }
    Map params = new HashMap();
    if (paramValueList != null && paramList != null) {
        for (int i = 0; i < paramList.size(); i++) {
            String key = paramList.getParameter(i).getName();
            String value = paramValueList.getParameterValue(i).asStringValue(null);
            params.put(key, value);
        }
    }
    // IFSAMessage originatingMessage = (IFSAMessage)prc.getSession().get(PushingIfsaProviderListener.THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY);
    String BIF = (String) prc.getSession().get(getBifNameSessionKey());
    if (StringUtils.isEmpty(BIF)) {
        BIF = (String) prc.getSession().get(PushingIfsaProviderListener.THREAD_CONTEXT_BIFNAME_KEY);
    }
    return sendMessage(dummyCorrelationId, message, params, BIF, null);
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) HashMap(java.util.HashMap) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 8 with ParameterValueList

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

the class DirectWrapperPipe method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    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 extracting parameters", e);
        }
    }
    String destination = getParameterValue(pvl, DESTINATION);
    String cmhVersion = getParameterValue(pvl, CMHVERSION);
    String addOutputNamespace = getParameterValue(pvl, ADDOUTPUTNAMESPACE);
    EsbSoapWrapperPipe eswPipe = new EsbSoapWrapperPipe();
    if (addOutputNamespace != null) {
        if ("on".equalsIgnoreCase(addOutputNamespace)) {
            eswPipe.setAddOutputNamespace(true);
        }
    }
    if (destination != null) {
        Parameter p = new Parameter();
        p.setName(DESTINATION);
        p.setValue(destination);
        eswPipe.addParameter(p);
    }
    if (cmhVersion != null) {
        if (StringUtils.isNumeric(cmhVersion)) {
            eswPipe.setCmhVersion(Integer.parseInt(cmhVersion));
        }
    }
    PipeForward pf = new PipeForward();
    pf.setName("success");
    eswPipe.registerForward(pf);
    try {
        eswPipe.configure();
        PipeRunResult prr = eswPipe.doPipe(input, session);
        result = (String) prr.getResult();
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "Exception on wrapping input", e);
    }
    return result;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 9 with ParameterValueList

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

the class ReloadSender method sendMessage.

@Override
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws TimeOutException, SenderException {
    String configName = null;
    String activeVersion = null;
    ParameterValueList pvl = null;
    try {
        if (prc != null && paramList != null) {
            pvl = prc.getValues(paramList);
            if (pvl.getParameterValue("name") != null)
                configName = (String) pvl.getParameterValue("name").getValue();
            if (pvl.getParameterValue("forceReload") != null)
                setForceReload((Boolean) pvl.getParameterValue("forceReload").getValue());
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
    }
    try {
        if (configName == null)
            configName = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='NAME']");
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression configName", e);
    }
    try {
        if (!getForceReload())
            activeVersion = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='VERSION']");
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression activeVersion", e);
    }
    Configuration configuration = getPipe().getAdapter().getConfiguration().getIbisManager().getConfiguration(configName);
    if (configuration != null) {
        String latestVersion = configuration.getVersion();
        if (getForceReload() || (latestVersion != null && !activeVersion.equals(latestVersion))) {
            IbisContext ibisContext = configuration.getIbisManager().getIbisContext();
            ibisContext.reload(configName);
            return "Reload " + configName + " succeeded";
        } else {
            return "Reload " + configName + " skipped";
        }
    } else {
        log.warn("Configuration [" + configName + "] not loaded yet");
        return "Reload " + configName + " skipped";
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Configuration(nl.nn.adapterframework.configuration.Configuration) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 10 with ParameterValueList

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

the class SendTibcoMessage method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    Connection connection = null;
    Session jSession = null;
    MessageProducer msgProducer = null;
    Destination destination = null;
    String url_work;
    String authAlias_work;
    String userName_work;
    String password_work;
    String queueName_work;
    String messageProtocol_work;
    int replyTimeout_work;
    String soapAction_work;
    String result = 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();
    }
    queueName_work = getParameterValue(pvl, "queueName");
    if (queueName_work == null) {
        queueName_work = getQueueName();
    }
    messageProtocol_work = getParameterValue(pvl, "messageProtocol");
    if (messageProtocol_work == null) {
        messageProtocol_work = getMessageProtocol();
    }
    String replyTimeout_work_str = getParameterValue(pvl, "replyTimeout");
    if (replyTimeout_work_str == null) {
        replyTimeout_work = getReplyTimeout();
    } else {
        replyTimeout_work = Integer.parseInt(replyTimeout_work_str);
    }
    soapAction_work = getParameterValue(pvl, "soapAction");
    if (soapAction_work == null)
        soapAction_work = getSoapAction();
    if (StringUtils.isEmpty(soapAction_work) && !StringUtils.isEmpty(queueName_work)) {
        String[] q = queueName_work.split("\\.");
        if (q.length > 0) {
            if (q[0].equalsIgnoreCase("P2P") && q.length >= 4) {
                soapAction_work = q[3];
            } else if (q[0].equalsIgnoreCase("ESB") && q.length == 8) {
                soapAction_work = q[5] + "_" + q[6];
            } else if (q[0].equalsIgnoreCase("ESB") && q.length > 8) {
                soapAction_work = q[6] + "_" + q[7];
            }
        }
    }
    if (StringUtils.isEmpty(soapAction_work)) {
        log.debug(getLogPrefix(session) + "deriving default soapAction");
        try {
            URL resource = ClassUtils.getResourceURL(this, "/xml/xsl/esb/soapAction.xsl");
            TransformerPool tp = TransformerPool.getInstance(resource, true);
            soapAction_work = tp.transform(input.toString(), null);
        } catch (Exception e) {
            log.error(getLogPrefix(session) + "failed to execute soapAction.xsl");
        }
    }
    if (messageProtocol_work == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "messageProtocol must be set");
    }
    if (!messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY) && !messageProtocol_work.equalsIgnoreCase(FIRE_AND_FORGET)) {
        throw new PipeRunException(this, getLogPrefix(session) + "illegal value for messageProtocol [" + messageProtocol_work + "], must be '" + REQUEST_REPLY + "' or '" + FIRE_AND_FORGET + "'");
    }
    CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
    try {
        TibjmsAdmin admin;
        try {
            admin = TibcoUtils.getActiveServerAdmin(url_work, cf);
        } catch (TibjmsAdminException e) {
            log.debug(getLogPrefix(session) + "caught exception", e);
            admin = null;
        }
        if (admin != null) {
            QueueInfo queueInfo;
            try {
                queueInfo = admin.getQueue(queueName_work);
            } catch (Exception e) {
                throw new PipeRunException(this, getLogPrefix(session) + " exception on getting queue info", e);
            }
            if (queueInfo == null) {
                throw new PipeRunException(this, getLogPrefix(session) + " queue [" + queueName_work + "] does not exist");
            }
            try {
                admin.close();
            } catch (TibjmsAdminException e) {
                log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e);
            }
        }
        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);
        destination = jSession.createQueue(queueName_work);
        msgProducer = jSession.createProducer(destination);
        TextMessage msg = jSession.createTextMessage();
        msg.setText(input.toString());
        Destination replyQueue = null;
        if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) {
            replyQueue = jSession.createTemporaryQueue();
            msg.setJMSReplyTo(replyQueue);
            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
            msgProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            msgProducer.setTimeToLive(replyTimeout_work);
        } else {
            msg.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
            msgProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
        }
        if (StringUtils.isNotEmpty(soapAction_work)) {
            log.debug(getLogPrefix(session) + "setting [SoapAction] property to value [" + soapAction_work + "]");
            msg.setStringProperty("SoapAction", soapAction_work);
        }
        msgProducer.send(msg);
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix(session) + "sent message [" + msg.getText() + "] " + "to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]");
        } else {
            if (log.isInfoEnabled()) {
                log.info(getLogPrefix(session) + "sent message to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]");
            }
        }
        if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) {
            String replyCorrelationId = msg.getJMSMessageID();
            MessageConsumer msgConsumer = jSession.createConsumer(replyQueue, "JMSCorrelationID='" + replyCorrelationId + "'");
            log.debug(getLogPrefix(session) + "] start waiting for reply on [" + replyQueue + "] selector [" + replyCorrelationId + "] for [" + replyTimeout_work + "] ms");
            try {
                connection.start();
                Message rawReplyMsg = msgConsumer.receive(replyTimeout_work);
                if (rawReplyMsg == null) {
                    throw new PipeRunException(this, getLogPrefix(session) + "did not receive reply on [" + replyQueue + "] replyCorrelationId [" + replyCorrelationId + "] within [" + replyTimeout_work + "] ms");
                }
                TextMessage replyMsg = (TextMessage) rawReplyMsg;
                result = replyMsg.getText();
            } finally {
            }
        } else {
            result = msg.getJMSMessageID();
        }
    } catch (JMSException e) {
        throw new PipeRunException(this, getLogPrefix(session) + " exception on sending message to Tibco queue", e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.warn(getLogPrefix(session) + "exception on closing connection", e);
            }
        }
    }
    return result;
}
Also used : QueueInfo(com.tibco.tibjms.admin.QueueInfo) Destination(javax.jms.Destination) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException) URL(java.net.URL) TransformerPool(nl.nn.adapterframework.util.TransformerPool) ConnectionFactory(javax.jms.ConnectionFactory) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) MessageConsumer(javax.jms.MessageConsumer) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Connection(javax.jms.Connection) TibjmsAdmin(com.tibco.tibjms.admin.TibjmsAdmin) PipeRunException(nl.nn.adapterframework.core.PipeRunException) JMSException(javax.jms.JMSException) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) ParameterException(nl.nn.adapterframework.core.ParameterException) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

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