use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class TransactionAttributePipeProcessor method processPipe.
public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
PipeRunResult pipeRunResult;
int txOption;
int txTimeout = 0;
if (pipe instanceof HasTransactionAttribute) {
HasTransactionAttribute taPipe = (HasTransactionAttribute) pipe;
txOption = taPipe.getTransactionAttributeNum();
txTimeout = taPipe.getTransactionTimeout();
} else {
txOption = TransactionDefinition.PROPAGATION_SUPPORTS;
}
// TransactionStatus txStatus = txManager.getTransaction(SpringTxManagerProxy.getTransactionDefinition(txOption,txTimeout));
IbisTransaction itx = new IbisTransaction(txManager, SpringTxManagerProxy.getTransactionDefinition(txOption, txTimeout), "pipe [" + pipe.getName() + "]");
TransactionStatus txStatus = itx.getStatus();
try {
TimeoutGuard tg = new TimeoutGuard("pipeline of adapter [" + pipeLine.getOwner().getName() + "] running pipe [" + pipe.getName() + "]");
Throwable tCaught = null;
try {
tg.activateGuard(txTimeout);
pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
} catch (Throwable t) {
tCaught = t;
throw tCaught;
} finally {
if (tg.cancel()) {
if (tCaught == null) {
throw new PipeRunException(pipe, tg.getDescription() + " was interrupted");
} else {
log.warn("Thread interrupted, but propagating other caught exception of type [" + ClassUtils.nameOf(tCaught) + "]");
}
}
}
} catch (Throwable t) {
log.debug("setting RollBackOnly for pipe [" + pipe.getName() + "] after catching exception");
txStatus.setRollbackOnly();
if (t instanceof Error) {
throw (Error) t;
} else if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else if (t instanceof PipeRunException) {
throw (PipeRunException) t;
} else {
throw new PipeRunException(pipe, "Caught unknown checked exception", t);
}
} finally {
// txManager.commit(txStatus);
itx.commit();
}
return pipeRunResult;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class MoveFilePipe method moveFile.
private void moveFile(IPipeLineSession session, File srcFile, File dstFile) throws PipeRunException {
try {
if (!dstFile.getParentFile().exists()) {
if (isCreateDirectory()) {
if (dstFile.getParentFile().mkdirs()) {
log.debug(getLogPrefix(session) + "created directory [" + dstFile.getParent() + "]");
} else {
log.warn(getLogPrefix(session) + "directory [" + dstFile.getParent() + "] could not be created");
}
} else {
log.warn(getLogPrefix(session) + "directory [" + dstFile.getParent() + "] does not exists");
}
}
if (isAppend()) {
if (FileUtils.appendFile(srcFile, dstFile, getNumberOfAttempts(), getWaitBeforeRetry()) == null) {
throw new PipeRunException(this, "Could not move file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
} else {
srcFile.delete();
log.info(getLogPrefix(session) + "moved file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
}
} else {
if (!isOverwrite() && getNumberOfBackups() == 0) {
if (dstFile.exists() && isThrowException()) {
throw new PipeRunException(this, "Could not move file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "] because it already exists");
} else {
dstFile = FileUtils.getFreeFile(dstFile);
}
}
if (FileUtils.moveFile(srcFile, dstFile, isOverwrite(), getNumberOfBackups(), getNumberOfAttempts(), getWaitBeforeRetry()) == null) {
throw new PipeRunException(this, "Could not move file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
} else {
log.info(getLogPrefix(session) + "moved file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
}
}
} catch (Exception e) {
throw new PipeRunException(this, "Error while moving file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]", e);
}
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class PasswordHashPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
Object result;
PipeForward pipeForward;
if (StringUtils.isEmpty(getHashSessionKey())) {
try {
if (getRoundsSessionKey() == null) {
result = PasswordHash.createHash(input.toString().toCharArray(), getRounds());
} else {
result = PasswordHash.createHash(input.toString().toCharArray(), Integer.valueOf(session.get(getRoundsSessionKey()).toString()));
}
pipeForward = getForward();
} catch (Exception e) {
throw new PipeRunException(this, "Could not hash password", e);
}
} else {
try {
result = input;
if (PasswordHash.validatePassword(input.toString(), (String) session.get(getHashSessionKey()))) {
pipeForward = getForward();
} else {
pipeForward = findForward(FAILURE_FORWARD_NAME);
}
} catch (Exception e) {
throw new PipeRunException(this, "Could not validate password", e);
}
}
return new PipeRunResult(pipeForward, result);
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class PutParametersInSession method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
ParameterValueList pvl = null;
ParameterList parameterList = getParameterList();
if (parameterList != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
if (pvl != null) {
for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.getParameter(i);
String pn = parameter.getName();
Object pv = parameter.getValue(pvl, prc);
session.put(pn, pv);
log.debug(getLogPrefix(session) + "stored [" + pv + "] in pipeLineSession under key [" + pn + "]");
}
}
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
}
return new PipeRunResult(getForward(), input);
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class PutSystemDateInSession method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String formattedDate;
if (isReturnFixedDate()) {
SimpleDateFormat formatterFrom = new SimpleDateFormat(FORMAT_FIXEDDATETIME);
String fixedDateTime = (String) session.get(FIXEDDATE_STUB4TESTTOOL_KEY);
if (StringUtils.isEmpty(fixedDateTime)) {
fixedDateTime = FIXEDDATETIME;
}
Date d;
try {
d = formatterFrom.parse(fixedDateTime);
} catch (ParseException e) {
throw new PipeRunException(this, "cannot parse fixed date [" + fixedDateTime + "] with format [" + FORMAT_FIXEDDATETIME + "]", e);
}
formattedDate = formatter.format(d);
} else {
if (sleepWhenEqualToPrevious > -1) {
// whole virtual machine.
synchronized (OBJECT) {
formattedDate = formatter.format(new Date());
while (formattedDate.equals(previousFormattedDate)) {
try {
Thread.sleep(sleepWhenEqualToPrevious);
} catch (InterruptedException e) {
}
formattedDate = formatter.format(new Date());
}
previousFormattedDate = formattedDate;
}
} else {
formattedDate = formatter.format(new Date());
}
}
session.put(this.getSessionKey(), formattedDate);
if (log.isDebugEnabled()) {
log.debug(getLogPrefix(session) + "stored [" + formattedDate + "] in pipeLineSession under key [" + getSessionKey() + "]");
}
return new PipeRunResult(getForward(), input);
}
Aggregations