Search in sources :

Example 6 with ParameterResolutionContext

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

the class ConfigData method processJarFile.

private String processJarFile(IPipeLineSession session, String name, String version, String fileName, String fileNameSessionKey) throws PipeRunException {
    String formJmsRealm = (String) session.get("jmsRealm");
    String activeConfig = (String) session.get(ACTIVE_CONFIG);
    String autoReload = (String) session.get(AUTO_RELOAD);
    String result = selectConfigQuery(session, name);
    if ("on".equals(activeConfig)) {
        activeConfigQuery(session, name, formJmsRealm, result);
    }
    if (Integer.parseInt(result) > 0) {
        deleteConfigQuery(session, name, formJmsRealm, version);
    }
    String remoteUser = (String) session.get("principal");
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(formJmsRealm);
        qs.setQueryType("insert");
        if (StringUtils.isEmpty(remoteUser)) {
            qs.setQuery("INSERT INTO IBISCONFIG (NAME, VERSION, FILENAME, CONFIG, CRE_TYDST, ACTIVECONFIG, AUTORELOAD) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?)");
        } else {
            qs.setQuery("INSERT INTO IBISCONFIG (NAME, VERSION, FILENAME, CONFIG, CRE_TYDST, RUSER, ACTIVECONFIG, AUTORELOAD) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?, ?)");
        }
        Parameter param = new Parameter();
        param.setName("name");
        param.setValue(name);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("version");
        param.setValue(version);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("fileName");
        param.setValue(fileName);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("config");
        param.setSessionKey(fileNameSessionKey);
        param.setType(Parameter.TYPE_INPUTSTREAM);
        qs.addParameter(param);
        if (StringUtils.isNotEmpty(remoteUser)) {
            param = new Parameter();
            param.setName("ruser");
            param.setValue(remoteUser);
            qs.addParameter(param);
        }
        setActiveConfig(activeConfig, qs);
        setAutoReload(autoReload, qs);
        qs.configure();
        qs.open();
        ParameterResolutionContext prc = new ParameterResolutionContext(DUMMY, session);
        result = qs.sendMessage(DUMMY, DUMMY, prc);
    } catch (Exception t) {
        throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
    } finally {
        qs.close();
    }
    return result;
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 7 with ParameterResolutionContext

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

the class ConfigData method deleteConfigQuery.

private String deleteConfigQuery(IPipeLineSession session, String name, String formJmsRealm, String version) throws PipeRunException {
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    String result = "";
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(formJmsRealm);
        qs.setQuery("DELETE FROM IBISCONFIG WHERE NAME = ? AND VERSION = ?");
        Parameter param = new Parameter();
        param.setName("name");
        param.setValue(name);
        qs.addParameter(param);
        param = new Parameter();
        param.setName("version");
        param.setValue(version);
        qs.addParameter(param);
        qs.setScalar(true);
        qs.configure();
        qs.open();
        ParameterResolutionContext prc = new ParameterResolutionContext(DUMMY, session);
        result = qs.sendMessage(DUMMY, DUMMY, prc);
    } catch (Exception t) {
        throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
    } finally {
        qs.close();
    }
    return result;
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 8 with ParameterResolutionContext

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

the class ConfigData method selectConfigQuery.

private String selectConfigQuery(IPipeLineSession session, String name) throws PipeRunException {
    String formJmsRealm = (String) session.get("jmsRealm");
    String result = "";
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    try {
        qs.setName("QuerySender");
        qs.setJmsRealm(formJmsRealm);
        qs.setQueryType("select");
        qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG WHERE NAME=?");
        Parameter param = new Parameter();
        param.setName("name");
        param.setValue(name);
        qs.addParameter(param);
        qs.setScalar(true);
        qs.configure();
        qs.open();
        ParameterResolutionContext prc = new ParameterResolutionContext(DUMMY, session);
        result = qs.sendMessage(DUMMY, DUMMY, prc);
    } catch (Exception t) {
        throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
    } finally {
        qs.close();
    }
    return result;
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 9 with ParameterResolutionContext

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

the class XQueryPipe method doPipe.

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());
    }
    try {
        String stringResult = (String) input;
        // We already specifically use Saxon in this pipe, hence set xslt2
        // to true to make XmlUtils use the Saxon
        // DocumentBuilderFactoryImpl.
        ParameterResolutionContext prc = new ParameterResolutionContext(stringResult, session, isNamespaceAware(), true);
        Map parametervalues = null;
        if (getParameterList() != null) {
            parametervalues = prc.getValueMap(getParameterList());
        }
        preparedExpression.bindDocument(XQConstants.CONTEXT_ITEM, stringResult, null, null);
        Iterator iterator = getParameterList().iterator();
        while (iterator.hasNext()) {
            Parameter parameter = (Parameter) iterator.next();
            preparedExpression.bindObject(new QName(parameter.getName()), parametervalues.get(parameter.getName()), null);
        }
        XQResultSequence resultSequence = preparedExpression.executeQuery();
        stringResult = resultSequence.getSequenceAsString(null);
        return new PipeRunResult(getForward(), stringResult);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on running xquery", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) QName(javax.xml.namespace.QName) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Iterator(java.util.Iterator) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XQException(javax.xml.xquery.XQException) XQResultSequence(javax.xml.xquery.XQResultSequence)

Example 10 with ParameterResolutionContext

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

the class XmlSwitch method doPipe.

/**
 * This is where the action takes place, the switching is done. Pipes may only throw a PipeRunException,
 * to be handled by the caller of this object.<br/>
 * As WebLogic has the problem that when an non-well formed XML stream is given to
 * weblogic.xerces the transformer gets corrupt, on an exception the configuration is done again, so that the
 * transformer is re-initialized.
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    String sInput = (String) input;
    PipeForward pipeForward = null;
    if (StringUtils.isNotEmpty(getSessionKey())) {
        sInput = (String) session.get(sessionKey);
    }
    if (transformerPool != null) {
        ParameterList parameterList = null;
        ParameterResolutionContext prc = new ParameterResolutionContext(sInput, session, isNamespaceAware());
        ;
        try {
            Map parametervalues = null;
            if (getParameterList() != null) {
                parameterList = getParameterList();
                parametervalues = prc.getValueMap(parameterList);
            }
            forward = transformerPool.transform(prc.getInputSource(), parametervalues);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception on transformation", e);
        }
    } else {
        forward = sInput;
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    if (StringUtils.isEmpty(forward) && getEmptyForwardName() != null) {
        throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
        pipeForward = findForward(getEmptyForwardName());
    } else {
        if (findForward(forward) != null) {
            throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
            pipeForward = findForward(forward);
        } else {
            log.info(getLogPrefix(session) + "determined forward [" + forward + "], which is not defined. Will use [" + getNotFoundForwardName() + "] instead");
            throwEvent(XML_SWITCH_FORWARD_NOT_FOUND_MONITOR_EVENT);
            pipeForward = findForward(getNotFoundForwardName());
        }
    }
    if (pipeForward == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "cannot find forward or pipe named [" + forward + "]");
    }
    return new PipeRunResult(pipeForward, input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) PipeForward(nl.nn.adapterframework.core.PipeForward) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map)

Aggregations

ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)47 PipeRunException (nl.nn.adapterframework.core.PipeRunException)32 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)21 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)20 ParameterException (nl.nn.adapterframework.core.ParameterException)18 IOException (java.io.IOException)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 Parameter (nl.nn.adapterframework.parameters.Parameter)15 Map (java.util.Map)10 SenderException (nl.nn.adapterframework.core.SenderException)10 ParameterList (nl.nn.adapterframework.parameters.ParameterList)10 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)8 PipeForward (nl.nn.adapterframework.core.PipeForward)7 HashMap (java.util.HashMap)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)4 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)4 URL (java.net.URL)3 ISender (nl.nn.adapterframework.core.ISender)3 PipeStartException (nl.nn.adapterframework.core.PipeStartException)3