use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class DirectWrapperPipe method doPipeWithTimeoutGuarded.
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
String result;
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 destination = getParameterValue(pvl, DESTINATION);
String cmhVersion = getParameterValue(pvl, CMHVERSION);
String addOutputNamespace = getParameterValue(pvl, ADDOUTPUTNAMESPACE);
EsbSoapWrapperPipe eswPipe = new EsbSoapWrapperPipe();
if (addOutputNamespace != null) {
if ("on".equalsIgnoreCase(addOutputNamespace)) {
eswPipe.setAddOutputNamespace(true);
}
}
if (destination != null) {
Parameter p = new Parameter();
p.setName(DESTINATION);
p.setValue(destination);
eswPipe.addParameter(p);
}
if (cmhVersion != null) {
if (StringUtils.isNumeric(cmhVersion)) {
eswPipe.setCmhVersion(Integer.parseInt(cmhVersion));
}
}
PipeForward pf = new PipeForward();
pf.setName("success");
eswPipe.registerForward(pf);
try {
eswPipe.configure();
PipeRunResult prr = eswPipe.doPipe(input, session);
result = (String) prr.getResult();
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "Exception on wrapping input", e);
}
return result;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class JavaxValidationContext method getSchemaObject.
// protected String validate(Source source, IPipeLineSession session) throws XmlValidatorException, ConfigurationException, PipeRunException {
// init();
// String schemasId = schemasProvider.getSchemasId();
// if (schemasId == null) {
// schemasId = schemasProvider.getSchemasId(session);
// getSchemaObject(schemasId, schemasProvider.getSchemas(session));
// }
// Schema xsd = javaxSchemas.get(schemasId);
// try {
// Validator validator = xsd.newValidator();
// validator.setResourceResolver(new LSResourceResolver() {
// public LSInput resolveResource(String s, String s1, String s2, String s3, String s4) {
// System.out.println("--");
// return null;//To change body of implemented methods Settings | File Templates.
// }
// });
// validator.setErrorHandler(new ErrorHandler() {
// public void warning(SAXParseException e) throws SAXException {
// log.warn(e.getMessage());
// }
//
// public void error(SAXParseException e) throws SAXException {
// log.error(e.getMessage());
// }
//
// public void fatalError(SAXParseException e) throws SAXException {
// log.error(e.getMessage());
// }
// });
// //validator.setFeature("http://xml.org/sax/features/namespace-prefixes", true); /// DOESNT" WORK any more?
// validator.validate(source);
// } catch (SAXException e) {
// throw new XmlValidatorException(e.getClass() + " " + e.getMessage());
// } catch (IOException e) {
// throw new XmlValidatorException(e.getMessage(), e);
// }
// return XML_VALIDATOR_VALID_MONITOR_EVENT;
// }
/**
* Returns the {@link Schema} associated with this validator. This ia an XSD schema containing knowledge about the
* schema source as returned by {@link #getSchemaSources(List)}
* @throws ConfigurationException
*/
protected synchronized Schema getSchemaObject(String schemasId, List<nl.nn.adapterframework.validation.Schema> schemas) throws ConfigurationException {
Schema schema = javaxSchemas.get(schemasId);
if (schema == null) {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String s, String s1, String s2, String s3, String s4) {
return null;
}
});
try {
Collection<Source> sources = getSchemaSources(schemas);
schema = factory.newSchema(sources.toArray(new Source[sources.size()]));
javaxSchemas.put(schemasId, schema);
} catch (Exception e) {
throw new ConfigurationException("cannot read schema's [" + schemasId + "]", e);
}
}
return schema;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class StreamTransformerPipe 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 {
String streamId = getStreamId(input, session);
BufferedReader reader = getReader(streamId, input, session);
if (reader == null) {
throw new PipeRunException(this, "could not obtain reader for [" + streamId + "]");
}
Object transformationResult = null;
ParameterResolutionContext prc = new ParameterResolutionContext("", session);
try {
transformationResult = transform(streamId, reader, session, prc);
} finally {
if (isCloseInputstreamOnExit()) {
try {
reader.close();
} catch (IOException e) {
log.warn(getLogPrefix(session) + "Exception closing reader", e);
}
}
}
return new PipeRunResult(getForward(), transformationResult);
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class StreamTransformerPipe method transform.
/*
* Read all lines from the reader, treat every line as a record and transform
* it using the registered managers, record- and result handlers.
*/
private Object transform(String streamId, BufferedReader reader, IPipeLineSession session, ParameterResolutionContext prc) throws PipeRunException {
String rawRecord = null;
int linenumber = 0;
int counter = 0;
StringBuffer sb = null;
List prevParsedRecord = null;
IRecordHandler prevHandler = null;
IRecordHandlerManager currentManager = initialManager.getRecordFactoryUsingFilename(session, streamId);
try {
openDocument(session, streamId, prc);
while ((rawRecord = reader.readLine()) != null) {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
// remember linenumber for exception handler
linenumber++;
if (StringUtils.isEmpty(rawRecord)) {
// ignore empty line
continue;
}
// get handlers for current line
RecordHandlingFlow flow = currentManager.getRecordHandler(session, rawRecord);
if (flow == null) {
log.debug("<no flow>: " + rawRecord);
// ignore line for which no handlers are registered
continue;
} else {
// log.debug("flow ["+flow.getRecordKey()+"] openBlockBeforeLine ["+flow.getOpenBlockBeforeLine()+"]");
}
IResultHandler resultHandler = flow.getResultHandler();
closeBlock(session, resultHandler, streamId, flow, flow.getCloseBlockBeforeLine(), "closeBlockBeforeLine of flow [" + flow.getRecordKey() + "]", prc);
String obbl = null;
if (flow.getOpenBlockBeforeLineNumber() > 0) {
if (counter % flow.getOpenBlockBeforeLineNumber() == 0) {
obbl = flow.getOpenBlockBeforeLine();
}
} else {
obbl = flow.getOpenBlockBeforeLine();
}
openBlock(session, resultHandler, streamId, flow, obbl, prc);
if (isStoreOriginalBlock()) {
if (resultHandler instanceof ResultBlock2Sender) {
// In both cases a new block has just started
if (!session.containsKey(originalBlockKey)) {
sb = new StringBuffer();
}
if (sb.length() > 0) {
sb.append(System.getProperty("line.separator"));
}
sb.append(rawRecord);
// already put the block in the session, also if the block is not yet complete.
session.put(originalBlockKey, sb.toString());
}
}
IRecordHandler curHandler = flow.getRecordHandler();
if (curHandler != null) {
log.debug("manager [" + currentManager.getName() + "] key [" + flow.getRecordKey() + "] record handler [" + curHandler.getName() + "] line [" + linenumber + "]: " + rawRecord);
// there is a record handler, so transform the line
List parsedRecord = curHandler.parse(session, rawRecord);
Object result = curHandler.handleRecord(session, parsedRecord, prc);
counter++;
// if there is a result handler, write the transformed result
if (result != null && resultHandler != null) {
boolean recordTypeChanged = curHandler.isNewRecordType(session, curHandler.equals(prevHandler), prevParsedRecord, parsedRecord);
log.debug("manager [" + currentManager.getName() + "] key [" + flow.getRecordKey() + "] record handler [" + curHandler.getName() + "] recordTypeChanged [" + recordTypeChanged + "]");
if (recordTypeChanged && prevHandler != null && resultHandler.isBlockByRecordType()) {
String prevRecordType = prevHandler.getRecordType(prevParsedRecord);
log.debug("record handler [" + prevHandler.getName() + "] result handler [" + resultHandler.getName() + "] closing block for record type [" + prevRecordType + "]");
closeBlock(session, resultHandler, streamId, flow, prevRecordType, "record type change", prc);
}
// The suffix is then only written at the end of the file.
if (recordTypeChanged && resultHandler.hasPrefix()) {
if (prevHandler != null) {
resultHandler.closeRecordType(session, streamId, prc);
}
resultHandler.openRecordType(session, streamId, prc);
}
if (recordTypeChanged && resultHandler.isBlockByRecordType()) {
String recordType = curHandler.getRecordType(parsedRecord);
log.debug("record handler [" + curHandler.getName() + "] result handler [" + resultHandler.getName() + "] opening block [" + recordType + "]");
openBlock(session, resultHandler, streamId, flow, recordType, prc);
}
resultHandler.handleResult(session, streamId, flow.getRecordKey(), result, prc);
}
prevParsedRecord = parsedRecord;
prevHandler = curHandler;
} else {
log.debug("manager [" + currentManager.getName() + "] key [" + flow.getRecordKey() + "], no record handler: " + rawRecord);
}
closeBlock(session, resultHandler, streamId, flow, flow.getCloseBlockAfterLine(), "closeBlockAfterLine of flow [" + flow.getRecordKey() + "]", prc);
openBlock(session, resultHandler, streamId, flow, flow.getOpenBlockAfterLine(), prc);
// get the manager for the next record
currentManager = flow.getNextRecordHandlerManager();
}
return finalizeResult(session, streamId, false, prc);
} catch (Exception e) {
try {
finalizeResult(session, streamId, true, prc);
} catch (Throwable t) {
log.error("Unexpected error during finalizeResult of [" + streamId + "]", t);
}
throw new PipeRunException(this, "Error while transforming [" + streamId + "] at or after line [" + linenumber + "]", e);
} finally {
closeDocument(session, streamId, prc);
}
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class ZipWriterPipe method createZipWriter.
protected ZipWriter createZipWriter(IPipeLineSession session, ParameterValueList pvl, Object input) throws PipeRunException {
if (log.isDebugEnabled())
log.debug(getLogPrefix(session) + "opening new zipstream");
OutputStream resultStream = null;
if (input == null) {
throw new PipeRunException(this, getLogPrefix(session) + "input cannot be null, must be OutputStream, HttpResponse or String containing filename");
}
if (input instanceof OutputStream) {
resultStream = (OutputStream) input;
} else if (input instanceof HttpServletResponse) {
ParameterValue pv = pvl.getParameterValue(PARAMETER_FILENAME);
if (pv == null) {
throw new PipeRunException(this, getLogPrefix(session) + "parameter 'filename' not found, but required if stream is HttpServletResponse");
}
String filename = pv.asStringValue("download.zip");
try {
HttpServletResponse response = (HttpServletResponse) input;
StreamUtil.openZipDownload(response, filename);
resultStream = response.getOutputStream();
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot open download for [" + filename + "]", e);
}
} else if (input instanceof String) {
String filename = (String) input;
if (StringUtils.isEmpty(filename)) {
throw new PipeRunException(this, getLogPrefix(session) + "input string cannot be empty but must contain a filename");
}
try {
resultStream = new FileOutputStream(filename);
} catch (FileNotFoundException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot create file [" + filename + "] a specified by input message", e);
}
}
if (resultStream == null) {
throw new PipeRunException(this, getLogPrefix(session) + "Dit not find OutputStream or HttpResponse, and could not find filename");
}
ZipWriter sessionData = ZipWriter.createZipWriter(session, getZipWriterHandle(), resultStream, isCloseOutputstreamOnExit());
return sessionData;
}
Aggregations