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);
}
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations