use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.
the class JdbcQuerySenderBase method executeOtherQuery.
protected String executeOtherQuery(Connection connection, String correlationID, PreparedStatement statement, String message, ParameterResolutionContext prc, ParameterList newParamList) throws SenderException {
ResultSet resultset = null;
try {
int numRowsAffected = 0;
if (StringUtils.isNotEmpty(getRowIdSessionKey())) {
CallableStatement cstmt = getCallWithRowIdReturned(connection, correlationID, message);
int ri = 1;
if (prc != null && paramList != null) {
ParameterValueList parameters = prc.getValues(newParamList);
applyParameters(cstmt, parameters);
ri = parameters.size() + 1;
}
cstmt.registerOutParameter(ri, Types.VARCHAR);
log.debug(getLogPrefix() + "executing a SQL command");
numRowsAffected = cstmt.executeUpdate();
String rowId = cstmt.getString(ri);
if (prc != null)
prc.getSession().put(getRowIdSessionKey(), rowId);
} else {
log.debug(getLogPrefix() + "executing a SQL command");
numRowsAffected = statement.executeUpdate();
}
if (StringUtils.isNotEmpty(getResultQuery())) {
Statement resStmt = null;
try {
resStmt = connection.createStatement();
log.debug("obtaining result from [" + getResultQuery() + "]");
ResultSet rs = resStmt.executeQuery(getResultQuery());
return getResult(rs);
} finally {
if (resStmt != null) {
resStmt.close();
}
}
}
if (getColumnsReturnedList() != null) {
return getResult(getReturnedColumns(getColumnsReturnedList(), statement));
}
if (isScalar()) {
return numRowsAffected + "";
}
return "<result><rowsupdated>" + numRowsAffected + "</rowsupdated></result>";
} catch (SQLException sqle) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", sqle);
} catch (JdbcException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
} catch (JMSException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "got exception evaluating parameters", e);
} finally {
try {
if (resultset != null) {
resultset.close();
}
} catch (SQLException e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
}
}
}
use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.
the class LdapFindMemberPipe method doPipeWithException.
public PipeRunResult doPipeWithException(Object input, IPipeLineSession session) throws PipeRunException {
String dnSearchIn_work;
String dnFind_work;
ParameterValueList pvl = null;
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
}
}
dnSearchIn_work = getParameterValue(pvl, "dnSearchIn");
if (dnSearchIn_work == null) {
dnSearchIn_work = getDnSearchIn();
}
dnFind_work = getParameterValue(pvl, "dnFind");
if (dnFind_work == null) {
dnFind_work = getDnFind();
}
boolean found = false;
if (StringUtils.isNotEmpty(dnSearchIn_work) && StringUtils.isNotEmpty(dnFind_work)) {
try {
found = findMember(getHost(), getPort(), dnSearchIn_work, isUseSsl(), dnFind_work, isRecursiveSearch());
} catch (NamingException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception on ldap lookup", e);
}
}
if (!found) {
String msg = getLogPrefix(session) + "dn [" + dnFind_work + "] not found as member in url [" + retrieveUrl(getHost(), getPort(), dnSearchIn_work, isUseSsl()) + "]";
if (notFoundForward == null) {
throw new PipeRunException(this, msg);
} else {
log.info(msg);
return new PipeRunResult(notFoundForward, input);
}
}
return new PipeRunResult(getForward(), input);
}
use of nl.nn.adapterframework.parameters.ParameterValueList 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.ParameterValueList in project iaf by ibissource.
the class CompareStringPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
ParameterValueList pvl = null;
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
}
String operand1 = getParameterValue(pvl, OPERAND1);
if (operand1 == null) {
if (StringUtils.isNotEmpty(getSessionKey1())) {
operand1 = (String) session.get(getSessionKey1());
}
if (operand1 == null) {
operand1 = (String) input;
}
}
String operand2 = getParameterValue(pvl, OPERAND2);
if (operand2 == null) {
if (StringUtils.isNotEmpty(getSessionKey2())) {
operand2 = (String) session.get(getSessionKey2());
}
if (operand2 == null) {
operand2 = (String) input;
}
}
if (isXml()) {
try {
operand1 = XmlUtils.canonicalize(operand1);
operand2 = XmlUtils.canonicalize(operand2);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on pretty printing input", e);
}
}
String ip = getParameterValue(pvl, IGNOREPATTERNS);
if (ip != null) {
try {
Node n = XmlUtils.buildNode(ip);
if (n.getNodeName().equals("ignores")) {
NodeList nList = n.getChildNodes();
for (int i = 0; i <= nList.getLength() - 1; i++) {
Node cn = nList.item(i);
if (cn.getNodeName().equals("ignore")) {
NodeList cnList = cn.getChildNodes();
String after = null;
String before = null;
for (int j = 0; j <= cnList.getLength() - 1; j++) {
Node ccn = cnList.item(j);
if (ccn.getNodeName().equals("after")) {
after = ccn.getFirstChild().getNodeValue();
} else {
if (ccn.getNodeName().equals("before")) {
before = ccn.getFirstChild().getNodeValue();
}
}
}
operand1 = ignoreBetween(operand1, after, before);
operand2 = ignoreBetween(operand2, after, before);
}
}
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on ignoring parts of input", e);
}
}
if (log.isDebugEnabled()) {
log.debug("operand1 [" + operand1 + "]");
log.debug("operand2 [" + operand2 + "]");
}
int comparison = operand1.compareTo(operand2);
if (comparison == 0)
return new PipeRunResult(findForward(EQUALSFORWARD), input);
else if (comparison < 0)
return new PipeRunResult(findForward(LESSTHANFORWARD), input);
else
return new PipeRunResult(findForward(GREATERTHANFORWARD), input);
}
use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.
the class TimeoutGuardPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
ParameterValueList pvl = null;
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
}
}
int timeout_work;
String timeout_work_str = getParameterValue(pvl, "timeout");
if (timeout_work_str == null) {
timeout_work = getTimeout();
} else {
timeout_work = Integer.valueOf(timeout_work_str);
}
DoPipe doPipe = new DoPipe(input, session, Thread.currentThread().getName(), NDC.peek());
ExecutorService service = Executors.newSingleThreadExecutor();
Future future = service.submit(doPipe);
String result = null;
try {
log.debug(getLogPrefix(session) + "setting timeout of [" + timeout_work + "] s");
result = (String) future.get(timeout_work, TimeUnit.SECONDS);
} catch (Exception e) {
String msg;
if (e instanceof TimeoutException) {
String errorMsg = getLogPrefix(session) + "exceeds timeout of [" + timeout_work + "] s, interupting";
future.cancel(true);
msg = e.getClass().getName() + ": " + errorMsg;
} else {
msg = e.getClass().getName();
}
if (isThrowException()) {
throw new PipeRunException(this, msg, e);
} else {
String msgString = msg + ": " + e.getMessage();
log.error(msgString, e);
String msgCdataString = "<![CDATA[" + msgString + "]]>";
result = "<error>" + msgCdataString + "</error>";
}
} finally {
service.shutdown();
}
return new PipeRunResult(getForward(), result);
}
Aggregations