use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class PostboxRetrieverPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (!(input instanceof String)) {
throw new PipeRunException(this, "String expected, got a [" + input.getClass().getName() + "]");
}
Map threadContext = null;
try {
threadContext = getListener().openThread();
Object rawMessage = getListener().retrieveRawMessage((String) input, threadContext);
if (rawMessage == null)
return new PipeRunResult(findForward("emptyPostbox"), getResultOnEmptyPostbox());
String result = getListener().getStringFromRawMessage(rawMessage, threadContext);
return new PipeRunResult(getForward(), result);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "caught exception", e);
} finally {
try {
getListener().closeThread(threadContext);
} catch (ListenerException le) {
log.error(getLogPrefix(session) + "got error closing listener");
}
}
}
use of nl.nn.adapterframework.core.PipeRunException 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.core.PipeRunException in project iaf by ibissource.
the class CompressPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
try {
Object result;
InputStream in;
OutputStream out;
boolean zipMultipleFiles = false;
if (messageIsContent) {
if (input instanceof byte[]) {
in = new ByteArrayInputStream((byte[]) input);
} else {
in = new ByteArrayInputStream(input.toString().getBytes());
}
} else {
if (compress && StringUtils.contains((String) input, ";")) {
zipMultipleFiles = true;
in = null;
} else {
in = new FileInputStream((String) input);
}
}
if (resultIsContent) {
out = new ByteArrayOutputStream();
result = out;
} else {
String outFilename = null;
if (messageIsContent) {
outFilename = FileUtils.getFilename(getParameterList(), session, (File) null, filenamePattern);
} else {
outFilename = FileUtils.getFilename(getParameterList(), session, new File((String) input), filenamePattern);
}
File outFile = new File(outputDirectory, outFilename);
result = outFile.getAbsolutePath();
out = new FileOutputStream(outFile);
}
if (zipMultipleFiles) {
ZipOutputStream zipper = new ZipOutputStream(out);
StringTokenizer st = new StringTokenizer((String) input, ";");
while (st.hasMoreElements()) {
String fn = st.nextToken();
String zipEntryName = getZipEntryName(fn, session);
zipper.putNextEntry(new ZipEntry(zipEntryName));
in = new FileInputStream(fn);
try {
int readLength = 0;
byte[] block = new byte[4096];
while ((readLength = in.read(block)) > 0) {
zipper.write(block, 0, readLength);
}
} finally {
in.close();
zipper.closeEntry();
}
}
zipper.close();
out = zipper;
} else {
if (compress) {
if ("gz".equals(fileFormat) || fileFormat == null && resultIsContent) {
out = new GZIPOutputStream(out);
} else {
ZipOutputStream zipper = new ZipOutputStream(out);
String zipEntryName = getZipEntryName(input, session);
zipper.putNextEntry(new ZipEntry(zipEntryName));
out = zipper;
}
} else {
if ("gz".equals(fileFormat) || fileFormat == null && messageIsContent) {
in = new GZIPInputStream(in);
} else {
ZipInputStream zipper = new ZipInputStream(in);
String zipEntryName = getZipEntryName(input, session);
if (zipEntryName.equals("")) {
// Use first entry found
zipper.getNextEntry();
} else {
// Position the stream at the specified entry
ZipEntry zipEntry = zipper.getNextEntry();
while (zipEntry != null && !zipEntry.getName().equals(zipEntryName)) {
zipEntry = zipper.getNextEntry();
}
}
in = zipper;
}
}
try {
int readLength = 0;
byte[] block = new byte[4096];
while ((readLength = in.read(block)) > 0) {
out.write(block, 0, readLength);
}
} finally {
out.close();
in.close();
}
}
return new PipeRunResult(getForward(), getResultMsg(result));
} catch (Exception e) {
PipeForward exceptionForward = findForward(EXCEPTIONFORWARD);
if (exceptionForward != null) {
log.warn(getLogPrefix(session) + "exception occured, forwarded to [" + exceptionForward.getPath() + "]", e);
String originalMessage;
if (input instanceof String) {
originalMessage = (String) input;
} else {
originalMessage = "Object of type " + input.getClass().getName();
}
String resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), e, this, originalMessage, session.getMessageId(), 0);
return new PipeRunResult(exceptionForward, resultmsg);
}
throw new PipeRunException(this, "Unexpected exception during compression", e);
}
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class DelayPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
try {
log.info(getLogPrefix(session) + "starts waiting for " + getDelayTime() + " ms.");
Thread.sleep(getDelayTime());
} catch (InterruptedException e) {
throw new PipeRunException(this, getLogPrefix(session) + "delay interrupted", e);
}
log.info(getLogPrefix(session) + "ends waiting for " + getDelayTime() + " ms.");
return new PipeRunResult(getForward(), input);
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class BytesOutputPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
Object result = null;
Variant in = new Variant(input);
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
FieldsContentHandler fieldsContentHandler = new FieldsContentHandler();
parser.setContentHandler(fieldsContentHandler);
parser.parse(in.asXmlInputSource());
result = fieldsContentHandler.getResult();
} catch (SAXException e) {
throw new PipeRunException(this, "SAXException", e);
} catch (IOException e) {
throw new PipeRunException(this, "IOException", e);
}
return new PipeRunResult(getForward(), result);
}
Aggregations