Search in sources :

Example 21 with ParameterValueList

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

the class SchedulerSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException {
    try {
        ParameterValueList values = prc.getValues(paramList);
        String jobName = getName() + correlationID;
        String cronExpression = values.getParameterValue("_cronexpression").getValue().toString();
        if (StringUtils.isNotEmpty(jobNamePattern)) {
            jobName = values.getParameterValue("_jobname").getValue().toString();
            ;
        }
        schedule(jobName, cronExpression, correlationID, message);
        return jobName;
    } catch (SenderException e) {
        throw e;
    } catch (Exception e) {
        throw new SenderException("Error during scheduling " + message, e);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) SenderException(nl.nn.adapterframework.core.SenderException) SchedulerException(org.quartz.SchedulerException) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 22 with ParameterValueList

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

the class PutParametersInSession method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    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);
                    String pn = parameter.getName();
                    Object pv = parameter.getValue(pvl, prc);
                    session.put(pn, pv);
                    log.debug(getLogPrefix(session) + "stored [" + pv + "] in pipeLineSession under key [" + pn + "]");
                }
            }
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    return new PipeRunResult(getForward(), input);
}
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)

Example 23 with ParameterValueList

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

the class RhinoPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    // INIT
    String eol = System.getProperty("line.separator");
    if (input == null) {
        // No input from previous pipes. We will use filename and or string input.
        if ((StringUtils.isEmpty(fileInput)) && inputString == null && isLookupAtRuntime()) {
            // No input from file or input string. Nowhere to GO!
            throw new PipeRunException(this, getLogPrefix(session) + "No input specified anywhere. No string input, no file input and no previous pipe input");
        }
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
    }
    inputString = (String) input;
    // Get the input from the file at Run Time
    if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
        URL resource = null;
        try {
            resource = ClassUtils.getResourceURL(classLoader, getFileName());
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + getFileName() + "]", e);
        }
        if (resource == null) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + getFileName() + "]");
        }
        try {
            fileInput = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + getFileName() + "]", e);
        }
    }
    // Get all params as input
    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);
            paramsInput = pv.asStringValue("") + eol + paramsInput;
        }
    }
    String javascriptcode = "Packages.java;" + eol;
    if (fileInput != null) {
        javascriptcode = javascriptcode + fileInput;
    }
    if (paramsInput != null) {
        javascriptcode = paramsInput + eol + javascriptcode;
    }
    String stringResult = (String) javascriptcode;
    stringResult = "INPUTSTREAM used in case of ERROR" + eol + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + eol + stringResult;
    // Start your engines
    // Rhino engine Ok.
    Context cx = Context.enter();
    Scriptable scope = cx.initStandardObjects();
    if (isDebug()) {
        System.out.println("debug active");
        cx.setLanguageVersion(Context.VERSION_1_2);
        cx.setGeneratingDebug(true);
    }
    // Load javascript factory with javascript functions from file, stringinput and paraminput
    String jsResult = "";
    try {
        cx.evaluateString(scope, javascriptcode, "jsScript", 1, null);
        Function fct = (Function) scope.get(jsfunctionName, scope);
        // Object result = fct.call(cx, scope, scope, new Object[]{jsfunctionArguments});
        Object result = fct.call(cx, scope, scope, new Object[] { input });
        if (isDebug()) {
            System.out.println(cx.jsToJava(result, String.class));
        }
        ;
        jsResult = (String) cx.jsToJava(result, String.class);
    } catch (org.mozilla.javascript.EcmaError ex) {
        throw new PipeRunException(this, "org.mozilla.javascript.EcmaError -> ", ex);
    // System.out.println(ex.getMessage());
    } finally {
        Context.exit();
    }
    // Use the result
    if (!(jsResult instanceof String)) {
    } else {
        if ((String) jsResult != null) {
            stringResult = (String) jsResult;
        }
    }
    if (StringUtils.isEmpty(getSessionKey())) {
        return new PipeRunResult(getForward(), stringResult);
    } else {
        session.put(getSessionKey(), stringResult);
        return new PipeRunResult(getForward(), input);
    }
}
Also used : ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) URL(java.net.URL) org.mozilla.javascript(org.mozilla.javascript) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 24 with ParameterValueList

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

the class IfsaRequesterSender method convertParametersToMap.

protected Map convertParametersToMap(ParameterResolutionContext prc) throws SenderException {
    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);
        }
    }
    return params;
}
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)

Example 25 with ParameterValueList

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

the class FileHandler method createFile.

private File createFile(byte[] in, IPipeLineSession session, ParameterList paramList) throws IOException, ParameterException {
    File tmpFile;
    String writeSuffix_work = null;
    if (paramList != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) null, session);
        ParameterValueList pvl = prc.getValues(paramList);
        if (pvl != null) {
            ParameterValue writeSuffixParamValue = pvl.getParameterValue("writeSuffix");
            if (writeSuffixParamValue != null) {
                writeSuffix_work = (String) writeSuffixParamValue.getValue();
            }
        }
    }
    if (writeSuffix_work == null) {
        writeSuffix_work = getWriteSuffix();
    }
    String name = getEffectiveFileName(null, session);
    if (StringUtils.isEmpty(getDirectory())) {
        if (StringUtils.isEmpty(name)) {
            tmpFile = File.createTempFile("ibis", writeSuffix_work);
        } else {
            tmpFile = new File(name);
        }
    } else {
        if (StringUtils.isEmpty(name)) {
            tmpFile = File.createTempFile("ibis", writeSuffix_work, new File(getDirectory()));
        } else {
            tmpFile = new File(getDirectory() + File.separator + name);
        }
    }
    return tmpFile;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) File(java.io.File) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

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