use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class RestListener method processRequest.
public String processRequest(String correlationId, String message, IPipeLineSession requestContext) throws ListenerException {
HttpServletRequest httpServletRequest = (HttpServletRequest) requestContext.get(IPipeLineSession.HTTP_REQUEST_KEY);
String response;
String contentType = (String) requestContext.get("contentType");
// Check if valid path
String requestRestPath = (String) requestContext.get("restPath");
if (!getRestPath().equals(requestRestPath)) {
throw new ListenerException("illegal restPath value [" + requestRestPath + "], must be '" + getRestPath() + "'");
}
// Check if consumes has been set or contentType is set to JSON
if (getConsumes().equalsIgnoreCase("JSON") && "application/json".equalsIgnoreCase(httpServletRequest.getContentType())) {
try {
message = transformToXml(message);
} catch (PipeRunException e) {
throw new ListenerException("Failed to transform JSON to XML");
}
}
int eTag = 0;
// Check if contentType is not overwritten which disabled auto-converting and mediatype headers
if (contentType == null || StringUtils.isEmpty(contentType) || contentType.equalsIgnoreCase("*/*")) {
if (getProduces().equalsIgnoreCase("XML"))
requestContext.put("contentType", "application/xml");
if (getProduces().equalsIgnoreCase("JSON"))
requestContext.put("contentType", "application/json");
if (getProduces().equalsIgnoreCase("TEXT"))
requestContext.put("contentType", "text/plain");
response = super.processRequest(correlationId, message, requestContext);
if (response != null && !response.isEmpty())
eTag = response.hashCode();
if (getProduces().equalsIgnoreCase("JSON")) {
try {
response = transformToJson(response);
} catch (PipeRunException e) {
throw new ListenerException("Failed to transform XML to JSON");
}
}
} else {
response = super.processRequest(correlationId, message, requestContext);
if (response != null && !response.isEmpty())
eTag = response.hashCode();
}
if (!requestContext.containsKey("etag") && getGenerateEtag() && eTag != 0) {
// The etag can be a negative integer...
requestContext.put("etag", RestListenerUtils.formatEtag(getRestPath(), getUriPattern(), eTag));
}
return response;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class ZipWriterPipe method closeZipWriterHandle.
protected void closeZipWriterHandle(IPipeLineSession session, boolean mustFind) throws PipeRunException {
ZipWriter sessionData = getZipWriter(session);
if (sessionData == null) {
if (mustFind) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot find session data");
} else {
log.debug(getLogPrefix(session) + "did find session data, assuming already closed");
}
} else {
try {
sessionData.close();
} catch (CompressionException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot close", e);
}
}
session.remove(getZipWriterHandle());
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class ZipWriterPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (ACTION_CLOSE.equals(getAction())) {
closeZipWriterHandle(session, true);
return new PipeRunResult(getForward(), input);
}
String msg = null;
if (input instanceof String) {
msg = (String) input;
}
ParameterResolutionContext prc = new ParameterResolutionContext(msg, session);
ParameterValueList pvl;
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e1) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot determine filename", e1);
}
ZipWriter sessionData = getZipWriter(session);
if (ACTION_OPEN.equals(getAction())) {
if (sessionData != null) {
throw new PipeRunException(this, getLogPrefix(session) + "zipWriterHandle in session key [" + getZipWriterHandle() + "] is already open");
}
sessionData = createZipWriter(session, pvl, input);
return new PipeRunResult(getForward(), input);
}
// from here on action must be 'write' or 'stream'
if (sessionData == null) {
throw new PipeRunException(this, getLogPrefix(session) + "zipWriterHandle in session key [" + getZipWriterHandle() + "] is not open");
}
String filename = (String) pvl.getParameterValue(PARAMETER_FILENAME).getValue();
if (StringUtils.isEmpty(filename)) {
throw new PipeRunException(this, getLogPrefix(session) + "filename cannot be empty");
}
try {
if (ACTION_STREAM.equals(getAction())) {
sessionData.openEntry(filename);
PipeRunResult prr = new PipeRunResult(getForward(), sessionData.getZipoutput());
return prr;
}
if (ACTION_WRITE.equals(getAction())) {
try {
if (isCompleteFileHeader()) {
sessionData.writeEntryWithCompletedHeader(filename, input, isCloseInputstreamOnExit(), getCharset());
} else {
sessionData.writeEntry(filename, input, isCloseInputstreamOnExit(), getCharset());
}
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot add data to zipentry for [" + filename + "]", e);
}
return new PipeRunResult(getForward(), input);
}
throw new PipeRunException(this, getLogPrefix(session) + "illegal action [" + getAction() + "]");
} catch (CompressionException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot add zipentry for [" + filename + "]", e);
}
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class BatchFileTransformerPipe method doPipe.
/**
* Open a reader for the file named according the input messsage and
* transform it.
* Move the input file to a done directory when transformation is finished
* and return the names of the generated files.
*
* @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.IPipeLineSession)
*/
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (input == null) {
throw new PipeRunException(this, "got null input instead of String containing filename");
}
if (!(input instanceof String)) {
throw new PipeRunException(this, "expected String containing filename as input, got [" + ClassUtils.nameOf(input) + "], value [" + input + "]");
}
String filename = input.toString();
File file = new File(filename);
try {
PipeRunResult result = super.doPipe(file, session);
try {
FileUtils.moveFileAfterProcessing(file, getMove2dirAfterTransform(), isDelete(), isOverwrite(), getNumberOfBackups());
} catch (Exception e) {
log.error(getLogPrefix(session), e);
}
return result;
} catch (PipeRunException e) {
try {
FileUtils.moveFileAfterProcessing(file, getMove2dirAfterError(), isDelete(), isOverwrite(), getNumberOfBackups());
} catch (Exception e2) {
log.error(getLogPrefix(session) + "Could not move file after exception [" + e2 + "]");
}
throw e;
}
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class TransactionAttributePipeLineProcessor method processPipeLine.
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
try {
// TransactionStatus txStatus = txManager.getTransaction(txDef);
IbisTransaction itx = new IbisTransaction(txManager, pipeLine.getTxDef(), "pipeline of adapter [" + pipeLine.getOwner().getName() + "]");
TransactionStatus txStatus = itx.getStatus();
try {
TimeoutGuard tg = new TimeoutGuard("pipeline of adapter [" + pipeLine.getOwner().getName() + "]");
Throwable tCaught = null;
try {
tg.activateGuard(pipeLine.getTransactionTimeout());
PipeLineResult pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
boolean mustRollback = false;
if (pipeLineResult == null) {
mustRollback = true;
log.warn("Pipeline received null result for messageId [" + messageId + "], transaction (when present and active) will be rolled back");
} else {
if (StringUtils.isNotEmpty(pipeLine.getCommitOnState()) && !pipeLine.getCommitOnState().equalsIgnoreCase(pipeLineResult.getState())) {
mustRollback = true;
log.warn("Pipeline result state [" + pipeLineResult.getState() + "] for messageId [" + messageId + "] is not equal to commitOnState [" + pipeLine.getCommitOnState() + "], transaction (when present and active) will be rolled back");
}
}
if (mustRollback) {
try {
txStatus.setRollbackOnly();
} catch (Exception e) {
throw new PipeRunException(null, "Could not set RollBackOnly", e);
}
}
return pipeLineResult;
} catch (Throwable t) {
tCaught = t;
throw tCaught;
} finally {
if (tg.cancel()) {
if (tCaught == null) {
throw new InterruptedException(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 pipeline 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(null, "Caught unknown checked exception", t);
}
} finally {
// txManager.commit(txStatus);
itx.commit();
}
} catch (RuntimeException e) {
throw new PipeRunException(null, "RuntimeException calling PipeLine with tx attribute [" + pipeLine.getTransactionAttribute() + "]", e);
}
}
Aggregations