use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class XmlValidator method determineForward.
protected PipeForward determineForward(String resultEvent, IPipeLineSession session, boolean responseMode) throws PipeRunException {
throwEvent(resultEvent);
if (AbstractXmlValidator.XML_VALIDATOR_VALID_MONITOR_EVENT.equals(resultEvent)) {
return getForward();
}
PipeForward forward = null;
if (AbstractXmlValidator.XML_VALIDATOR_PARSER_ERROR_MONITOR_EVENT.equals(resultEvent)) {
if (responseMode) {
forward = findForward("outputParserError");
}
if (forward == null) {
forward = findForward("parserError");
}
}
if (forward == null) {
if (responseMode) {
forward = findForward("outputFailure");
}
if (forward == null) {
forward = findForward("failure");
}
}
if (forward == null) {
if (isForwardFailureToSuccess()) {
forward = findForward("success");
} else {
throw new PipeRunException(this, "not implemented: should get reason from validator");
}
}
return forward;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class RhinoPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
// INIT
String eol = System.getProperty("line.separator");
if (input == null) {
// No input from previous pipes. We will use filename and or string input.
if ((StringUtils.isEmpty(fileInput)) && inputString == null && isLookupAtRuntime()) {
// No input from file or input string. Nowhere to GO!
throw new PipeRunException(this, getLogPrefix(session) + "No input specified anywhere. No string input, no file input and no previous pipe input");
}
}
if (!(input instanceof String)) {
throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
}
inputString = (String) input;
// Get the input from the file at Run Time
if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
URL resource = null;
try {
resource = ClassUtils.getResourceURL(classLoader, getFileName());
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + getFileName() + "]", e);
}
if (resource == null) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + getFileName() + "]");
}
try {
fileInput = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + getFileName() + "]", e);
}
}
// Get all params as input
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
ParameterValueList pvl;
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
for (int i = 0; i < pvl.size(); i++) {
ParameterValue pv = pvl.getParameterValue(i);
paramsInput = pv.asStringValue("") + eol + paramsInput;
}
}
String javascriptcode = "Packages.java;" + eol;
if (fileInput != null) {
javascriptcode = javascriptcode + fileInput;
}
if (paramsInput != null) {
javascriptcode = paramsInput + eol + javascriptcode;
}
String stringResult = (String) javascriptcode;
stringResult = "INPUTSTREAM used in case of ERROR" + eol + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + eol + stringResult;
// Start your engines
// Rhino engine Ok.
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
if (isDebug()) {
System.out.println("debug active");
cx.setLanguageVersion(Context.VERSION_1_2);
cx.setGeneratingDebug(true);
}
// Load javascript factory with javascript functions from file, stringinput and paraminput
String jsResult = "";
try {
cx.evaluateString(scope, javascriptcode, "jsScript", 1, null);
Function fct = (Function) scope.get(jsfunctionName, scope);
// Object result = fct.call(cx, scope, scope, new Object[]{jsfunctionArguments});
Object result = fct.call(cx, scope, scope, new Object[] { input });
if (isDebug()) {
System.out.println(cx.jsToJava(result, String.class));
}
;
jsResult = (String) cx.jsToJava(result, String.class);
} catch (org.mozilla.javascript.EcmaError ex) {
throw new PipeRunException(this, "org.mozilla.javascript.EcmaError -> ", ex);
// System.out.println(ex.getMessage());
} finally {
Context.exit();
}
// Use the result
if (!(jsResult instanceof String)) {
} else {
if ((String) jsResult != null) {
stringResult = (String) jsResult;
}
}
if (StringUtils.isEmpty(getSessionKey())) {
return new PipeRunResult(getForward(), stringResult);
} else {
session.put(getSessionKey(), stringResult);
return new PipeRunResult(getForward(), input);
}
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class StreamPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
Object result = input;
String inputString;
if (input instanceof String) {
inputString = (String) input;
} else {
inputString = "";
}
ParameterResolutionContext prc = new ParameterResolutionContext(inputString, session, isNamespaceAware());
Map parameters = null;
ParameterList parameterList = getParameterList();
if (parameterList != null) {
try {
parameters = prc.getValueMap(parameterList);
} catch (ParameterException e) {
throw new PipeRunException(this, "Could not resolve parameters", e);
}
}
InputStream inputStream = null;
OutputStream outputStream = null;
HttpServletRequest httpRequest = null;
HttpServletResponse httpResponse = null;
String contentType = null;
String contentDisposition = null;
if (parameters != null) {
if (parameters.get("inputStream") != null) {
inputStream = (InputStream) parameters.get("inputStream");
}
if (parameters.get("outputStream") != null) {
outputStream = (OutputStream) parameters.get("outputStream");
}
if (parameters.get("httpRequest") != null) {
httpRequest = (HttpServletRequest) parameters.get("httpRequest");
}
if (parameters.get("httpResponse") != null) {
httpResponse = (HttpServletResponse) parameters.get("httpResponse");
}
if (parameters.get("contentType") != null) {
contentType = (String) parameters.get("contentType");
}
if (parameters.get("contentDisposition") != null) {
contentDisposition = (String) parameters.get("contentDisposition");
}
}
if (inputStream == null && input instanceof InputStream) {
inputStream = (InputStream) input;
}
try {
if (httpResponse != null) {
HttpSender.streamResponseBody(inputStream, contentType, contentDisposition, httpResponse, log, getLogPrefix(session));
} else if (httpRequest != null) {
StringBuilder partsString = new StringBuilder("<parts>");
String firstStringPart = null;
List<AntiVirusObject> antiVirusObjects = new ArrayList<AntiVirusObject>();
if (ServletFileUpload.isMultipartContent(httpRequest)) {
log.debug(getLogPrefix(session) + "request with content type [" + httpRequest.getContentType() + "] and length [" + httpRequest.getContentLength() + "] contains multipart content");
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory);
List<FileItem> items = servletFileUpload.parseRequest(httpRequest);
int fileCounter = 0;
int stringCounter = 0;
log.debug(getLogPrefix(session) + "multipart request items size [" + items.size() + "]");
String lastFoundFileName = null;
String lastFoundAVStatus = null;
String lastFoundAVMessage = null;
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input
// type="text|radio|checkbox|etc", select, etc).
String fieldValue = item.getString();
String fieldName = item.getFieldName();
if (isCheckAntiVirus() && fieldName.equalsIgnoreCase(getAntiVirusPartName())) {
log.debug(getLogPrefix(session) + "found antivirus status part [" + fieldName + "] with value [" + fieldValue + "]");
lastFoundAVStatus = fieldValue;
} else if (isCheckAntiVirus() && fieldName.equalsIgnoreCase(getAntiVirusMessagePartName())) {
log.debug(getLogPrefix(session) + "found antivirus message part [" + fieldName + "] with value [" + fieldValue + "]");
lastFoundAVMessage = fieldValue;
} else {
log.debug(getLogPrefix(session) + "found string part [" + fieldName + "] with value [" + fieldValue + "]");
if (isExtractFirstStringPart() && firstStringPart == null) {
firstStringPart = fieldValue;
} else {
String sessionKeyName = "part_string" + (++stringCounter > 1 ? stringCounter : "");
addSessionKey(session, sessionKeyName, fieldValue);
partsString.append("<part type=\"string\" name=\"" + fieldName + "\" sessionKey=\"" + sessionKeyName + "\" size=\"" + fieldValue.length() + "\"/>");
}
}
} else {
// Process form file field (input type="file").
if (lastFoundFileName != null && lastFoundAVStatus != null) {
antiVirusObjects.add(new AntiVirusObject(lastFoundFileName, lastFoundAVStatus, lastFoundAVMessage));
lastFoundFileName = null;
lastFoundAVStatus = null;
lastFoundAVMessage = null;
}
log.debug(getLogPrefix(session) + "found file part [" + item.getName() + "]");
String sessionKeyName = "part_file" + (++fileCounter > 1 ? fileCounter : "");
String fileName = FilenameUtils.getName(item.getName());
InputStream is = item.getInputStream();
int size = is.available();
String mimeType = item.getContentType();
if (size > 0) {
addSessionKey(session, sessionKeyName, is, fileName);
} else {
addSessionKey(session, sessionKeyName, null);
}
partsString.append("<part type=\"file\" name=\"" + fileName + "\" sessionKey=\"" + sessionKeyName + "\" size=\"" + size + "\" mimeType=\"" + mimeType + "\"/>");
lastFoundFileName = fileName;
}
}
if (lastFoundFileName != null && lastFoundAVStatus != null) {
antiVirusObjects.add(new AntiVirusObject(lastFoundFileName, lastFoundAVStatus, lastFoundAVMessage));
}
} else {
log.debug(getLogPrefix(session) + "request with content type [" + httpRequest.getContentType() + "] and length [" + httpRequest.getContentLength() + "] does NOT contain multipart content");
}
partsString.append("</parts>");
if (isExtractFirstStringPart()) {
result = adjustFirstStringPart(firstStringPart, session);
session.put(getMultipartXmlSessionKey(), partsString.toString());
} else {
result = partsString.toString();
}
if (!antiVirusObjects.isEmpty()) {
for (AntiVirusObject antiVirusObject : antiVirusObjects) {
if (!antiVirusObject.getStatus().equalsIgnoreCase(getAntiVirusPassedMessage())) {
String errorMessage = "multipart contains file [" + antiVirusObject.getFileName() + "] with antivirus status [" + antiVirusObject.getStatus() + "] and message [" + StringUtils.defaultString(antiVirusObject.getMessage()) + "]";
PipeForward antiVirusFailedForward = findForward(ANTIVIRUS_FAILED_FORWARD);
if (antiVirusFailedForward == null) {
throw new PipeRunException(this, errorMessage);
} else {
if (antiVirusFailureAsSoapFault) {
errorMessage = createSoapFaultMessage(errorMessage);
}
if (StringUtils.isEmpty(getAntiVirusFailureReasonSessionKey())) {
return new PipeRunResult(antiVirusFailedForward, errorMessage);
} else {
session.put(getAntiVirusFailureReasonSessionKey(), errorMessage);
return new PipeRunResult(antiVirusFailedForward, result);
}
}
}
}
}
} else {
Misc.streamToStream(inputStream, outputStream);
}
} catch (IOException e) {
throw new PipeRunException(this, "IOException streaming input to output", e);
} catch (FileUploadException e) {
throw new PipeRunException(this, "FileUploadException getting multiparts from httpServletRequest", e);
}
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class InputOutputPipeProcessor method processPipe.
public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
Object preservedObject = message;
PipeRunResult pipeRunResult = null;
INamedObject owner = pipeLine.getOwner();
IExtendedPipe pe = null;
if (pipe instanceof IExtendedPipe) {
pe = (IExtendedPipe) pipe;
}
if (pe != null) {
if (StringUtils.isNotEmpty(pe.getGetInputFromSessionKey())) {
if (log.isDebugEnabled())
log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with contents of sessionKey [" + pe.getGetInputFromSessionKey() + "]");
message = pipeLineSession.get(pe.getGetInputFromSessionKey());
}
if (StringUtils.isNotEmpty(pe.getGetInputFromFixedValue())) {
if (log.isDebugEnabled())
log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with fixed value [" + pe.getGetInputFromFixedValue() + "]");
message = pe.getGetInputFromFixedValue();
}
if ((message == null || StringUtils.isEmpty(message.toString())) && StringUtils.isNotEmpty(pe.getEmptyInputReplacement())) {
if (log.isDebugEnabled())
log.debug("Pipeline of adapter [" + owner.getName() + "] replacing empty input for pipe [" + pe.getName() + "] with fixed value [" + pe.getEmptyInputReplacement() + "]");
message = pe.getEmptyInputReplacement();
}
}
if (pipe instanceof FixedForwardPipe) {
FixedForwardPipe ffPipe = (FixedForwardPipe) pipe;
pipeRunResult = ffPipe.doInitialPipe(message, pipeLineSession);
}
if (pipeRunResult == null) {
pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
}
if (pipeRunResult == null) {
throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] received null result from pipe [" + pipe.getName() + "]d");
}
if (pe != null) {
if (pe.isRestoreMovedElements()) {
if (log.isDebugEnabled())
log.debug("Pipeline of adapter [" + owner.getName() + "] restoring from compacted result for pipe [" + pe.getName() + "]");
Object result = pipeRunResult.getResult();
if (result != null) {
String resultString = (String) result;
pipeRunResult.setResult(restoreMovedElements(resultString, pipeLineSession));
}
}
if (pe.getChompCharSize() != null || pe.getElementToMove() != null || pe.getElementToMoveChain() != null) {
log.debug("Pipeline of adapter [" + owner.getName() + "] compact received message");
Object result = pipeRunResult.getResult();
if (result != null) {
String resultString = (String) result;
try {
InputStream xmlInput = IOUtils.toInputStream(resultString, "UTF-8");
CompactSaxHandler handler = new CompactSaxHandler();
handler.setChompCharSize(pe.getChompCharSize());
handler.setElementToMove(pe.getElementToMove());
handler.setElementToMoveChain(pe.getElementToMoveChain());
handler.setElementToMoveSessionKey(pe.getElementToMoveSessionKey());
handler.setRemoveCompactMsgNamespaces(pe.isRemoveCompactMsgNamespaces());
handler.setContext(pipeLineSession);
SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
parserFactory.setNamespaceAware(true);
SAXParser saxParser = parserFactory.newSAXParser();
try {
saxParser.parse(xmlInput, handler);
resultString = handler.getXmlString();
} catch (Exception e) {
log.warn("Pipeline of adapter [" + owner.getName() + "] could not compact received message: " + e.getMessage());
}
handler = null;
} catch (Exception e) {
throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] got error during compacting received message to more compact format: " + e.getMessage());
}
pipeRunResult.setResult(resultString);
}
}
if (StringUtils.isNotEmpty(pe.getStoreResultInSessionKey())) {
if (log.isDebugEnabled())
log.debug("Pipeline of adapter [" + owner.getName() + "] storing result for pipe [" + pe.getName() + "] under sessionKey [" + pe.getStoreResultInSessionKey() + "]");
Object result = pipeRunResult.getResult();
pipeLineSession.put(pe.getStoreResultInSessionKey(), result);
}
if (pe.isPreserveInput()) {
pipeRunResult.setResult(preservedObject);
}
}
if (pe != null) {
if (pe.isWriteToSecLog()) {
String secLogMsg = "adapter [" + owner.getName() + "] pipe [" + pe.getName() + "]";
if (pe.getSecLogSessionKeys() != null) {
String sk = "";
StringTokenizer st = new StringTokenizer(pe.getSecLogSessionKeys(), " ,;");
while (st.hasMoreTokens()) {
if (sk.length() > 0) {
sk = sk + ",";
}
String key = st.nextToken();
Object value = pipeLineSession.get(key);
sk = sk + key + "=" + value;
}
secLogMsg = secLogMsg + " sessionKeys [" + sk + "]";
}
secLog.info(secLogMsg);
}
}
return pipeRunResult;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class LockerPipeProcessor method processPipe.
public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
PipeRunResult pipeRunResult;
IExtendedPipe extendedPipe = null;
Locker locker = null;
String objectId = null;
if (pipe instanceof IExtendedPipe) {
extendedPipe = (IExtendedPipe) pipe;
locker = extendedPipe.getLocker();
}
if (locker != null) {
try {
objectId = locker.lock();
} catch (Exception e) {
throw new PipeRunException(pipe, "error while setting lock", e);
}
}
if (objectId != null) {
try {
pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
} finally {
try {
locker.unlock(objectId);
} catch (Exception e) {
throw new PipeRunException(pipe, "error while removing lock", e);
}
}
} else {
pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
}
return pipeRunResult;
}
Aggregations