use of nl.nn.adapterframework.parameters.ParameterResolutionContext 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.ParameterResolutionContext in project iaf by ibissource.
the class BatchTransformerPipeBase method getReader.
protected BufferedReader getReader(String streamId, Object input, IPipeLineSession session) throws PipeRunException {
Connection connection = null;
try {
connection = querySender.getConnection();
PreparedStatement statement = null;
String msg = (String) input;
statement = querySender.getStatement(connection, streamId, msg, false);
ParameterResolutionContext prc = new ParameterResolutionContext(msg, session);
if (querySender.paramList != null) {
querySender.applyParameters(statement, prc.getValues(querySender.paramList));
}
ResultSet rs = statement.executeQuery();
if (rs == null || !rs.next()) {
throw new SenderException("query has empty resultset");
}
return new ResultSetReader(connection, rs, getReader(rs, getCharset(), streamId, session));
} catch (Exception e) {
throw new PipeRunException(this, "cannot open reader", e);
}
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class JdbcIteratingPipeBase method getIterator.
protected IDataIterator getIterator(Object input, IPipeLineSession session, String correlationID, Map threadContext) throws SenderException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
connection = querySender.getConnection();
String msg = (String) input;
statement = querySender.getStatement(connection, correlationID, msg, false);
ParameterResolutionContext prc = new ParameterResolutionContext(msg, session);
if (querySender.paramList != null) {
querySender.applyParameters(statement, prc.getValues(querySender.paramList));
}
rs = statement.executeQuery();
if (rs == null) {
throw new SenderException("resultset is null");
}
if (!rs.next()) {
JdbcUtil.fullClose(connection, rs);
// no results
return null;
}
return getIterator(connection, rs);
} catch (Throwable t) {
try {
if (rs != null) {
JdbcUtil.fullClose(connection, rs);
} else {
if (statement != null) {
JdbcUtil.fullClose(connection, statement);
} else {
if (connection != null) {
try {
connection.close();
} catch (SQLException e1) {
log.debug(getLogPrefix(session) + "caught exception closing sender after exception", e1);
}
}
}
}
} finally {
throw new SenderException(getLogPrefix(session), t);
}
}
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class ExecuteJdbcProperties method doPost.
private String doPost(IPipeLineSession session) throws PipeRunException {
String action = (String) session.get("action");
String name = (String) session.get("name");
String value = (String) session.get("value");
FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
String form_jmsRealm = (String) session.get("jmsRealm");
if (StringUtils.isEmpty(name)) {
throw new PipeRunException(this, getLogPrefix(session) + "Name should not be empty");
}
String result = null;
String remoteUser = (String) session.get("principal");
if ("insert".equalsIgnoreCase(action)) {
try {
qs.setName("QuerySender");
qs.setJmsRealm(form_jmsRealm);
qs.setQueryType("insert");
if (StringUtils.isEmpty(remoteUser)) {
qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE) VALUES (?, ?, CURRENT_TIMESTAMP)");
} else {
qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE, LASTMODBY) VALUES (?, ?, CURRENT_TIMESTAMP, ?)");
}
Parameter param = new Parameter();
param.setName("name");
param.setValue(name);
qs.addParameter(param);
param = new Parameter();
param.setName("value");
param.setValue(value);
qs.addParameter(param);
if (StringUtils.isNotEmpty(remoteUser)) {
param = new Parameter();
param.setName("lastmodby");
param.setValue(remoteUser);
qs.addParameter(param);
}
qs.configure();
qs.open();
ParameterResolutionContext prc = new ParameterResolutionContext("", session);
result = qs.sendMessage("", "", prc);
} catch (Throwable t) {
throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc insert query", t);
} finally {
qs.close();
}
} else if ("update".equalsIgnoreCase(action)) {
try {
qs.setName("QuerySender");
qs.setJmsRealm(form_jmsRealm);
qs.setQueryType("update");
qs.setQuery("UPDATE IBISPROP SET VALUE=?, LASTMODDATE=CURRENT_TIMESTAMP, LASTMODBY=? WHERE NAME=?");
Parameter param = new Parameter();
param.setName("value");
param.setValue(value);
qs.addParameter(param);
param = new Parameter();
param.setName("lastmodby");
if (StringUtils.isNotEmpty(remoteUser)) {
param.setValue(remoteUser);
}
qs.addParameter(param);
param = new Parameter();
param.setName("name");
param.setValue(name);
qs.addParameter(param);
qs.configure();
qs.open();
ParameterResolutionContext prc = new ParameterResolutionContext("", session);
result = qs.sendMessage("", "", prc);
} catch (Throwable t) {
throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc update query", t);
} finally {
qs.close();
}
} else if ("delete".equalsIgnoreCase(action)) {
try {
qs.setName("QuerySender");
qs.setJmsRealm(form_jmsRealm);
qs.setQueryType("delete");
qs.setQuery("DELETE IBISPROP WHERE NAME=?");
Parameter param = new Parameter();
param.setName("name");
param.setValue(name);
qs.addParameter(param);
qs.configure();
qs.open();
ParameterResolutionContext prc = new ParameterResolutionContext("", session);
result = qs.sendMessage("", "", prc);
} catch (Throwable t) {
throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc delete query", t);
} finally {
qs.close();
}
} else {
throw new PipeRunException(this, getLogPrefix(session) + "Unknown action [" + action + "]");
}
session.put("result", result);
return "<dummy/>";
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class ShowConfig method doGet.
private String doGet(IPipeLineSession session) throws PipeRunException {
String parm_name = (String) session.get("name");
if (StringUtils.isEmpty(parm_name)) {
return retrieveAllConfigs(session);
} else {
session.put("contentType", "application/octet-stream");
String parm_jmsRealm = (String) session.get("jmsRealm");
if (StringUtils.isEmpty(parm_jmsRealm)) {
parm_jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
if (parm_jmsRealm == null) {
throw new PipeRunException(this, getLogPrefix(session) + "No datasource jmsRealm available");
}
}
FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
String queryResult;
try {
qs.setName("QuerySender");
qs.setJmsRealm(parm_jmsRealm);
qs.setQueryType("select");
qs.setQuery("SELECT CONFIG FROM IBISCONFIG WHERE NAME = ? ORDER BY NAME");
Parameter param = new Parameter();
param.setName("name");
param.setSessionKey("name");
qs.addParameter(param);
qs.setScalar(true);
qs.setScalarExtended(true);
qs.setBlobsCompressed(false);
qs.setStreamResultToServlet(true);
qs.configure();
qs.open();
ParameterResolutionContext prc = new ParameterResolutionContext("dummy", session);
queryResult = qs.sendMessage("dummy", "dummy", prc);
} catch (Throwable t) {
throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
} finally {
qs.close();
}
if (queryResult.length() == 0) {
// means result is found and streamed
} else {
throw new PipeRunException(this, getLogPrefix(session) + "Could not retrieve configuration for name [" + parm_name + "]");
}
return queryResult;
}
}
Aggregations