Search in sources :

Example 31 with ParameterValue

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

the class CmisSender method createCmisSession.

/**
 * Creates a session during JMV runtime, tries to retrieve parameters and falls back on the defaults when they can't be found
 */
public Session createCmisSession(ParameterValueList pvl) throws SenderException {
    String authAlias_work = null;
    String username_work = null;
    String password_work = null;
    if (pvl != null) {
        ParameterValue pv = pvl.get("authAlias");
        if (pv != null) {
            authAlias_work = pv.asStringValue();
        }
        pv = pvl.get("username");
        if (pv == null) {
            pv = pvl.get("userName");
        }
        if (pv != null) {
            username_work = pv.asStringValue();
        }
        pv = pvl.get("password");
        if (pv != null) {
            password_work = pv.asStringValue();
        }
    }
    if (authAlias_work == null) {
        authAlias_work = getAuthAlias();
    }
    if (username_work == null) {
        username_work = getUsername();
    }
    if (password_work == null) {
        password_work = getPassword();
    }
    CredentialFactory cf = new CredentialFactory(authAlias_work, username_work, password_work);
    try {
        return getSessionBuilder().build(cf.getUsername(), cf.getPassword());
    } catch (CmisSessionException e) {
        throw new SenderException(e);
    }
}
Also used : ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) SenderException(nl.nn.adapterframework.core.SenderException)

Example 32 with ParameterValue

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

the class HttpSender method getMultipartPostMethodWithParamsInBody.

/**
 * Returns a multi-parted message, either as X-WWW-FORM-URLENCODED, FORM-DATA or MTOM
 * @throws IOException
 */
protected HttpPost getMultipartPostMethodWithParamsInBody(URI uri, String message, ParameterValueList parameters, PipeLineSession session) throws SenderException, IOException {
    HttpPost hmethod = new HttpPost(uri);
    if (postType.equals(PostType.URLENCODED) && StringUtils.isEmpty(getMultipartXmlSessionKey())) {
        // x-www-form-urlencoded
        List<NameValuePair> requestFormElements = new ArrayList<NameValuePair>();
        if (StringUtils.isNotEmpty(getFirstBodyPartName())) {
            requestFormElements.add(new BasicNameValuePair(getFirstBodyPartName(), message));
            log.debug(getLogPrefix() + "appended parameter [" + getFirstBodyPartName() + "] with value [" + message + "]");
        }
        if (parameters != null) {
            for (ParameterValue pv : parameters) {
                String name = pv.getDefinition().getName();
                String value = pv.asStringValue("");
                // Skip parameters that are configured as ignored
                if (skipParameter(name))
                    continue;
                requestFormElements.add(new BasicNameValuePair(name, value));
                if (log.isDebugEnabled())
                    log.debug(getLogPrefix() + "appended parameter [" + name + "] with value [" + value + "]");
            }
        }
        try {
            hmethod.setEntity(new UrlEncodedFormEntity(requestFormElements, getCharSet()));
        } catch (UnsupportedEncodingException e) {
            throw new SenderException(getLogPrefix() + "unsupported encoding for one or more post parameters");
        }
    } else {
        // formdata and mtom
        HttpEntity requestEntity = createMultiPartEntity(message, parameters, session);
        hmethod.setEntity(requestEntity);
    }
    return hmethod;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) HttpEntity(org.apache.http.HttpEntity) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) SenderException(nl.nn.adapterframework.core.SenderException)

Example 33 with ParameterValue

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

the class JmsSender method setProperties.

/**
 * Sets the JMS message properties as described in the msgProperties arraylist
 */
private void setProperties(javax.jms.Message msg, ParameterValueList pvl) throws JMSException {
    for (ParameterValue property : pvl) {
        ParameterType type = property.getDefinition().getType();
        String name = property.getDefinition().getName();
        if ((!isSoap() || !name.equals(getSoapHeaderParam()) && (StringUtils.isEmpty(getDestinationParam()) || !name.equals(getDestinationParam())))) {
            if (log.isDebugEnabled()) {
                log.debug(getLogPrefix() + "setting [" + type + "] property from param [" + name + "] to value [" + property.getValue() + "]");
            }
            switch(type) {
                case BOOLEAN:
                    msg.setBooleanProperty(name, property.asBooleanValue(false));
                    break;
                case INTEGER:
                    msg.setIntProperty(name, property.asIntegerValue(0));
                    break;
                case STRING:
                    msg.setStringProperty(name, property.asStringValue(""));
                    break;
                default:
                    msg.setObjectProperty(name, property.getValue());
                    break;
            }
        }
    }
}
Also used : ParameterType(nl.nn.adapterframework.parameters.Parameter.ParameterType) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue)

Example 34 with ParameterValue

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

the class PutParametersInSession method doPipe.

@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
    ParameterList parameterList = getParameterList();
    if (!parameterList.isEmpty()) {
        try {
            ParameterValueList pvl = parameterList.getValues(message, session, isNamespaceAware());
            if (pvl != null) {
                for (ParameterValue pv : pvl) {
                    String name = pv.getName();
                    Object value = pv.getValue();
                    session.put(name, value);
                    if (log.isDebugEnabled())
                        log.debug(getLogPrefix(session) + "stored [" + value + "] in pipeLineSession under key [" + name + "]");
                }
            }
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    return new PipeRunResult(getSuccessForward(), message);
}
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)

Example 35 with ParameterValue

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

the class RhinoPipe method doPipe.

@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
    // INIT
    String eol = System.getProperty("line.separator");
    if (message == null || message.isEmpty()) {
        // 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");
        }
    }
    // Get the input from the file at Run Time
    if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
        URL resource = null;
        try {
            resource = ClassUtils.getResourceURL(this, 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, Misc.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + getFileName() + "]", e);
        }
    }
    // Get all params as input
    if (getParameterList() != null) {
        ParameterValueList pvl;
        try {
            pvl = getParameterList().getValues(message, session);
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
        for (ParameterValue pv : pvl) {
            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()) {
        log.debug("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[] { message.asObject() });
        jsResult = (String) Context.jsToJava(result, String.class);
        if (isDebug() && log.isDebugEnabled()) {
            log.debug(getLogPrefix(session) + "jsResult [" + jsResult + "]");
        }
    } catch (EcmaError ex) {
        throw new PipeRunException(this, "org.mozilla.javascript.EcmaError -> ", ex);
    } finally {
        Context.exit();
    }
    // Use the result
    if (jsResult != null) {
        stringResult = jsResult;
    }
    if (StringUtils.isEmpty(getSessionKey())) {
        return new PipeRunResult(getSuccessForward(), stringResult);
    } else {
        session.put(getSessionKey(), stringResult);
        return new PipeRunResult(getSuccessForward(), message);
    }
}
Also used : Context(org.mozilla.javascript.Context) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) EcmaError(org.mozilla.javascript.EcmaError) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) Scriptable(org.mozilla.javascript.Scriptable) URL(java.net.URL) Function(org.mozilla.javascript.Function) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException)

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