use of nl.nn.adapterframework.core.PipeRunException 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.core.PipeRunException 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.core.PipeRunException in project iaf by ibissource.
the class ApiPrincipalPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (input == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null input");
}
if (!(input instanceof String)) {
throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
}
if (getAction().equals("get")) {
ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
if (userPrincipal == null)
throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
return new PipeRunResult(getForward(), userPrincipal.getData());
}
if (getAction().equals("set")) {
ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
if (userPrincipal == null)
throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
userPrincipal.setData((String) input);
cache.put(userPrincipal.getToken(), userPrincipal, authTTL);
return new PipeRunResult(getForward(), "");
}
if (getAction().equals("create")) {
// TODO type of token? (jwt, saml)
String uidString = (new UID()).toString();
Random random = new Random();
String token = random.nextInt() + uidString + Integer.toHexString(uidString.hashCode()) + random.nextInt(8);
ApiPrincipal userPrincipal = new ApiPrincipal(authTTL);
userPrincipal.setData((String) input);
userPrincipal.setToken(token);
if (getAuthenticationMethod().equals("cookie")) {
Cookie cookie = new Cookie("authenticationToken", token);
cookie.setPath("/");
cookie.setMaxAge(authTTL);
HttpServletResponse response = (HttpServletResponse) session.get(IPipeLineSession.HTTP_RESPONSE_KEY);
response.addCookie(cookie);
}
cache.put(token, userPrincipal, authTTL);
return new PipeRunResult(getForward(), token);
}
if (getAction().equals("remove")) {
ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
if (userPrincipal == null)
throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
cache.remove(userPrincipal.getToken());
return new PipeRunResult(getForward(), "");
}
return new PipeRunResult(findForward("exception"), "this is not supposed to happen... like ever!");
}
use of nl.nn.adapterframework.core.PipeRunException 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.core.PipeRunException 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