Search in sources :

Example 1 with ParameterValue

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

the class JdbcFacade method applyParameters.

protected void applyParameters(PreparedStatement statement, ParameterValueList parameters) throws SQLException, SenderException {
    for (int i = 0; i < parameters.size(); i++) {
        ParameterValue pv = parameters.getParameterValue(i);
        String paramType = pv.getDefinition().getType();
        Object value = pv.getValue();
        if (Parameter.TYPE_DATE.equals(paramType)) {
            if (value == null) {
                statement.setNull(i + 1, Types.DATE);
            } else {
                statement.setDate(i + 1, new java.sql.Date(((Date) value).getTime()));
            }
        } else if (Parameter.TYPE_DATETIME.equals(paramType)) {
            if (value == null) {
                statement.setNull(i + 1, Types.TIMESTAMP);
            } else {
                statement.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
            }
        } else if (Parameter.TYPE_TIMESTAMP.equals(paramType)) {
            if (value == null) {
                statement.setNull(i + 1, Types.TIMESTAMP);
            } else {
                statement.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
            }
        } else if (Parameter.TYPE_TIME.equals(paramType)) {
            if (value == null) {
                statement.setNull(i + 1, Types.TIME);
            } else {
                statement.setTime(i + 1, new java.sql.Time(((Date) value).getTime()));
            }
        } else if (Parameter.TYPE_XMLDATETIME.equals(paramType)) {
            if (value == null) {
                statement.setNull(i + 1, Types.TIMESTAMP);
            } else {
                statement.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
            }
        } else if (Parameter.TYPE_NUMBER.equals(paramType)) {
            if (value == null) {
                statement.setNull(i + 1, Types.NUMERIC);
            } else {
                statement.setDouble(i + 1, ((Number) value).doubleValue());
            }
        } else if (Parameter.TYPE_INTEGER.equals(paramType)) {
            if (value == null) {
                statement.setNull(i + 1, Types.INTEGER);
            } else {
                statement.setInt(i + 1, (Integer) value);
            }
        } else if (Parameter.TYPE_INPUTSTREAM.equals(paramType)) {
            if (value instanceof FileInputStream) {
                FileInputStream fis = (FileInputStream) value;
                long len = 0;
                try {
                    len = fis.getChannel().size();
                } catch (IOException e) {
                    log.warn(getLogPrefix() + "could not determine file size", e);
                }
                statement.setBinaryStream(i + 1, fis, (int) len);
            } else if (value instanceof ByteArrayInputStream) {
                ByteArrayInputStream bais = (ByteArrayInputStream) value;
                long len = bais.available();
                statement.setBinaryStream(i + 1, bais, (int) len);
            } else if (value instanceof InputStream) {
                statement.setBinaryStream(i + 1, (InputStream) value);
            } else {
                throw new SenderException(getLogPrefix() + "unknown inputstream [" + value.getClass() + "] for parameter [" + pv.getDefinition().getName() + "]");
            }
        } else if ("string2bytes".equals(paramType)) {
            statement.setBytes(i + 1, ((String) value).getBytes());
        } else if ("bytes".equals(paramType)) {
            statement.setBytes(i + 1, (byte[]) value);
        } else {
            statement.setString(i + 1, (String) value);
        }
    }
}
Also used : ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) Date(java.util.Date) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) INamedObject(nl.nn.adapterframework.core.INamedObject) SenderException(nl.nn.adapterframework.core.SenderException)

Example 2 with ParameterValue

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

the class CmisSender method getSession.

public Session getSession(ParameterResolutionContext prc) throws SenderException {
    if (session == null || !isKeepSession()) {
        String authAlias_work = null;
        String userName_work = null;
        String password_work = null;
        ParameterValueList pvl = null;
        try {
            if (prc != null && paramList != null) {
                pvl = prc.getValues(paramList);
                if (pvl != null) {
                    ParameterValue pv = pvl.getParameterValue("authAlias");
                    if (pv != null) {
                        authAlias_work = (String) pv.getValue();
                    }
                    pv = pvl.getParameterValue("userName");
                    if (pv != null) {
                        userName_work = (String) pv.getValue();
                    }
                    pv = pvl.getParameterValue("password");
                    if (pv != null) {
                        password_work = (String) pv.getValue();
                    }
                }
            }
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
        }
        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);
        session = connect(cf.getUsername(), cf.getPassword());
    }
    return session;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 3 with ParameterValue

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

the class HttpSender method getPostMethodWithParamsInBody.

protected HttpPost getPostMethodWithParamsInBody(URIBuilder uri, String message, ParameterValueList parameters, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException {
    try {
        HttpPost hmethod = new HttpPost(uri.build());
        if (!isMultipart() && StringUtils.isEmpty(getMultipartXmlSessionKey())) {
            List<NameValuePair> Parameters = new ArrayList<NameValuePair>();
            if (StringUtils.isNotEmpty(getInputMessageParam())) {
                Parameters.add(new BasicNameValuePair(getInputMessageParam(), message));
                log.debug(getLogPrefix() + "appended parameter [" + getInputMessageParam() + "] with value [" + message + "]");
            }
            if (parameters != null) {
                for (int i = 0; i < parameters.size(); i++) {
                    ParameterValue pv = parameters.getParameterValue(i);
                    String name = pv.getDefinition().getName();
                    String value = pv.asStringValue("");
                    if (headersParamsMap.keySet().contains(name)) {
                        hmethod.addHeader(name, value);
                        if (log.isDebugEnabled())
                            log.debug(getLogPrefix() + "appended header [" + name + "] with value [" + value + "]");
                    } else {
                        Parameters.add(new BasicNameValuePair(name, value));
                        if (log.isDebugEnabled())
                            log.debug(getLogPrefix() + "appended parameter [" + name + "] with value [" + value + "]");
                    }
                }
            }
            try {
                hmethod.setEntity(new UrlEncodedFormEntity(Parameters));
            } catch (UnsupportedEncodingException e) {
                throw new SenderException(getLogPrefix() + "unsupported encoding for one or more post parameters");
            }
        } else {
            HttpEntity requestEntity = createMultiPartEntity(message, parameters, session);
            hmethod.setEntity(requestEntity);
        }
        return hmethod;
    } catch (URISyntaxException e) {
        throw new SenderException(getLogPrefix() + "cannot find path from url [" + getUrl() + "]", e);
    }
}
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) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URISyntaxException(java.net.URISyntaxException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) SenderException(nl.nn.adapterframework.core.SenderException)

Example 4 with ParameterValue

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

the class ZipWriterPipe method createZipWriter.

protected ZipWriter createZipWriter(IPipeLineSession session, ParameterValueList pvl, Object input) throws PipeRunException {
    if (log.isDebugEnabled())
        log.debug(getLogPrefix(session) + "opening new zipstream");
    OutputStream resultStream = null;
    if (input == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "input cannot be null, must be OutputStream, HttpResponse or String containing filename");
    }
    if (input instanceof OutputStream) {
        resultStream = (OutputStream) input;
    } else if (input instanceof HttpServletResponse) {
        ParameterValue pv = pvl.getParameterValue(PARAMETER_FILENAME);
        if (pv == null) {
            throw new PipeRunException(this, getLogPrefix(session) + "parameter 'filename' not found, but required if stream is HttpServletResponse");
        }
        String filename = pv.asStringValue("download.zip");
        try {
            HttpServletResponse response = (HttpServletResponse) input;
            StreamUtil.openZipDownload(response, filename);
            resultStream = response.getOutputStream();
        } catch (IOException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot open download for [" + filename + "]", e);
        }
    } else if (input instanceof String) {
        String filename = (String) input;
        if (StringUtils.isEmpty(filename)) {
            throw new PipeRunException(this, getLogPrefix(session) + "input string cannot be empty but must contain a filename");
        }
        try {
            resultStream = new FileOutputStream(filename);
        } catch (FileNotFoundException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot create file [" + filename + "] a specified by input message", e);
        }
    }
    if (resultStream == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "Dit not find OutputStream or HttpResponse, and could not find filename");
    }
    ZipWriter sessionData = ZipWriter.createZipWriter(session, getZipWriterHandle(), resultStream, isCloseOutputstreamOnExit());
    return sessionData;
}
Also used : ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) FileNotFoundException(java.io.FileNotFoundException) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException)

Example 5 with ParameterValue

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

the class SapFunctionFacade method message2FunctionCall.

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

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