Search in sources :

Example 36 with ParameterValue

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

the class SapFunctionFacade method message2FunctionCall.

public void message2FunctionCall(JCoFunction function, String request, String correlationId, ParameterValueList pvl) throws SapException {
    JCoParameterList input = function.getImportParameterList();
    int requestFieldIndex = findFieldIndex(input, getRequestFieldIndex(), getRequestFieldName());
    setParameters(input, function.getTableParameterList(), request, requestFieldIndex);
    if (pvl != null) {
        for (ParameterValue pv : pvl) {
            String name = pv.getDefinition().getName();
            String value = pv.asStringValue("");
            int slashPos = name.indexOf('/');
            if (slashPos < 0) {
                input.setValue(name, value);
            } else {
                String structName = name.substring(0, slashPos);
                String elemName = name.substring(slashPos + 1);
                JCoStructure struct = input.getStructure(structName);
                struct.setValue(elemName, value);
            }
        }
    }
    int correlationIdFieldIndex = findFieldIndex(input, getCorrelationIdFieldIndex(), getCorrelationIdFieldName());
    if (correlationIdFieldIndex > 0 && input != null) {
        input.setValue(correlationIdFieldIndex - 1, correlationId);
    }
}
Also used : ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) JCoStructure(com.sap.conn.jco.JCoStructure) JCoParameterList(com.sap.conn.jco.JCoParameterList)

Example 37 with ParameterValue

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

the class EtagHandlerPipe method doPipe.

@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
    if (message == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null input");
    }
    String uriPatternSessionKey = null;
    ParameterValueList pvl = null;
    ParameterList parameterList = getParameterList();
    if (parameterList != null) {
        try {
            pvl = parameterList.getValues(message, session);
            if (pvl != null) {
                ParameterValue pv = pvl.get("uriPattern");
                if (pv != null) {
                    uriPatternSessionKey = pv.asStringValue();
                }
            }
        } 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 (log.isDebugEnabled())
            log.debug("found eTag cacheKey [" + cacheKey + "] with action [" + getAction() + "]");
        switch(getAction()) {
            case GENERATE:
                try {
                    cache.put(cacheKey, ApiCacheManager.buildEtag(getRestPath() + "/" + getUriPattern(), message.asString().hashCode()));
                } catch (IOException e) {
                    throw new PipeRunException(this, getLogPrefix(session) + "cannot open stream", e);
                }
                returnCode = true;
                break;
            case GET:
                returnCode = cache.get(cacheKey);
                break;
            case SET:
                try {
                    cache.put(cacheKey, message.asString());
                } catch (IOException e) {
                    throw new PipeRunException(this, getLogPrefix(session) + "cannot open stream", e);
                }
                returnCode = true;
                break;
            case DELETE:
                returnCode = cache.remove(cacheKey);
                break;
            case FLUSH:
                if (cache instanceof ApiEhcache) {
                    ((ApiEhcache) cache).flush();
                    returnCode = true;
                }
                break;
            case CLEAR:
                cache.clear();
                returnCode = true;
                break;
            default:
                throw new PipeRunException(this, getLogPrefix(session) + "action not found [" + getAction() + "]");
        }
        return new PipeRunResult(getSuccessForward(), returnCode);
    } else {
        PipeForward pipeForward = findForward(PipeForward.EXCEPTION_FORWARD_NAME);
        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) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) ParameterException(nl.nn.adapterframework.core.ParameterException) IOException(java.io.IOException) ApiEhcache(nl.nn.adapterframework.http.rest.ApiEhcache) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 38 with ParameterValue

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

the class JavascriptSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException {
    Object jsResult = "";
    int numberOfParameters = 0;
    JavascriptEngine<?> jsInstance = engine.create();
    try {
        jsInstance.startRuntime();
    } catch (JavascriptException e) {
        throw new SenderException("unable to start Javascript engine", e);
    }
    // Create a Parameter Value List
    ParameterValueList pvl = null;
    try {
        if (getParameterList() != null) {
            pvl = getParameterList().getValues(message, session);
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + " exception extracting parameters", e);
    }
    if (pvl != null) {
        numberOfParameters = pvl.size();
    }
    // This array will contain the parameters given in the configuration
    Object[] jsParameters = new Object[numberOfParameters];
    for (int i = 0; i < numberOfParameters; i++) {
        ParameterValue pv = pvl.getParameterValue(i);
        Object value = pv.getValue();
        try {
            jsParameters[i] = value instanceof Message ? ((Message) value).asString() : value;
        } catch (IOException e) {
            throw new SenderException(getLogPrefix(), e);
        }
    }
    for (ISender sender : getSenders()) {
        jsInstance.registerCallback(sender, session);
    }
    try {
        // Compile the given Javascript and execute the given Javascript function
        jsInstance.executeScript(adaptES6Literals(fileInput));
        jsResult = jsInstance.executeFunction(jsFunctionName, jsParameters);
    } catch (JavascriptException e) {
        throw new SenderException("unable to execute script/function", e);
    } finally {
        jsInstance.closeRuntime();
    }
    // Pass jsResult, the result of the Javascript function.
    // It is recommended to have the result of the Javascript function be of type String, which will be the output of the sender
    String result = String.valueOf(jsResult);
    if (StringUtils.isEmpty(result) || "null".equals(result) || "undefined".equals(result)) {
        return Message.nullMessage();
    }
    return new Message(result);
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) Message(nl.nn.adapterframework.stream.Message) IOException(java.io.IOException) ISender(nl.nn.adapterframework.core.ISender) JavascriptException(nl.nn.adapterframework.extensions.javascript.JavascriptException) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)38 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)21 ParameterException (nl.nn.adapterframework.core.ParameterException)19 SenderException (nl.nn.adapterframework.core.SenderException)18 IOException (java.io.IOException)16 PipeRunException (nl.nn.adapterframework.core.PipeRunException)12 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)9 Message (nl.nn.adapterframework.stream.Message)7 URL (java.net.URL)6 TransformerException (javax.xml.transform.TransformerException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 ParameterList (nl.nn.adapterframework.parameters.ParameterList)5 InputStream (java.io.InputStream)4 Transformer (javax.xml.transform.Transformer)4 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)4 JMSException (javax.jms.JMSException)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 TimeoutException (nl.nn.adapterframework.core.TimeoutException)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3