use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class JdbcQuerySenderBase method sendMessage.
@Override
protected String sendMessage(Connection connection, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
PreparedStatement statement = null;
ParameterList newParamList = new ParameterList();
if (paramList != null) {
newParamList = (ParameterList) paramList.clone();
}
if (isUseNamedParams()) {
message = adjustParamList(newParamList, message);
}
try {
boolean updateBlob = "updateBlob".equalsIgnoreCase(getQueryType());
boolean updateClob = "updateClob".equalsIgnoreCase(getQueryType());
log.debug(getLogPrefix() + "obtaining prepared statement to execute");
statement = getStatement(connection, correlationID, message, updateBlob || updateClob);
log.debug(getLogPrefix() + "obtained prepared statement to execute");
statement.setQueryTimeout(getTimeout());
if (prc != null && paramList != null) {
applyParameters(statement, prc.getValues(newParamList));
}
if ("select".equalsIgnoreCase(getQueryType())) {
Object blobSessionVar = null;
Object clobSessionVar = null;
if (prc != null && StringUtils.isNotEmpty(getBlobSessionKey())) {
blobSessionVar = prc.getSession().get(getBlobSessionKey());
}
if (prc != null && StringUtils.isNotEmpty(getClobSessionKey())) {
clobSessionVar = prc.getSession().get(getClobSessionKey());
}
if (isStreamResultToServlet()) {
HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
String contentType = (String) prc.getSession().get("contentType");
String contentDisposition = (String) prc.getSession().get("contentDisposition");
return executeSelectQuery(statement, blobSessionVar, clobSessionVar, response, contentType, contentDisposition);
} else {
return executeSelectQuery(statement, blobSessionVar, clobSessionVar);
}
}
if (updateBlob) {
if (StringUtils.isEmpty(getBlobSessionKey())) {
return executeUpdateBlobQuery(statement, message);
}
return executeUpdateBlobQuery(statement, prc == null ? null : prc.getSession().get(getBlobSessionKey()));
}
if (updateClob) {
if (StringUtils.isEmpty(getClobSessionKey())) {
return executeUpdateClobQuery(statement, message);
}
return executeUpdateClobQuery(statement, prc == null ? null : prc.getSession().get(getClobSessionKey()));
}
if ("package".equalsIgnoreCase(getQueryType())) {
return executePackageQuery(connection, statement, message);
}
return executeOtherQuery(connection, correlationID, statement, message, prc, newParamList);
} catch (SenderException e) {
if (e.getCause() instanceof SQLException) {
SQLException sqle = (SQLException) e.getCause();
if (sqle.getErrorCode() == 1013) {
throw new TimeOutException("Timeout of [" + getTimeout() + "] sec expired");
}
}
throw new SenderException(e);
} catch (Throwable t) {
throw new SenderException(getLogPrefix() + "got exception sending message", t);
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (SQLException e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing SQL statement", e));
}
if (isCloseInputstreamOnExit()) {
if (paramList != null) {
for (int i = 0; i < paramList.size(); i++) {
if (Parameter.TYPE_INPUTSTREAM.equals(paramList.getParameter(i).getType())) {
log.debug(getLogPrefix() + "Closing inputstream for parameter [" + paramList.getParameter(i).getName() + "]");
try {
InputStream inputStream = (InputStream) paramList.getParameter(i).getValue(null, prc);
inputStream.close();
} catch (Exception e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing inputstream", e));
}
}
}
}
}
}
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class NetStorageSender method configure.
public void configure() throws ConfigurationException {
super.configure();
// Safety checks
if (getAction() == null)
throw new ConfigurationException(getLogPrefix() + "action must be specified");
if (!actions.contains(getAction()))
throw new ConfigurationException(getLogPrefix() + "unknown or invalid action [" + getAction() + "] supported actions are " + actions.toString() + "");
if (getCpCode() == null)
throw new ConfigurationException(getLogPrefix() + "cpCode must be specified");
if (!getUrl().startsWith("http"))
throw new ConfigurationException(getLogPrefix() + "url must be start with http(s)");
if (hashAlgorithm != null && !hashAlgorithms.contains(hashAlgorithm))
throw new ConfigurationException(getLogPrefix() + "unknown authenticationMethod [" + hashAlgorithm + "] supported methods are " + hashAlgorithms.toString() + "");
if (getSignVersion() < 3 || getSignVersion() > 5)
throw new ConfigurationException(getLogPrefix() + "signVersion must be either 3, 4 or 5");
ParameterList parameterList = getParameterList();
if (getAction().equals("upload") && parameterList.findParameter("file") == null)
throw new ConfigurationException(getLogPrefix() + "the upload action requires a file parameter to be present");
if (getAction().equals("rename") && parameterList.findParameter("destination") == null)
throw new ConfigurationException(getLogPrefix() + "the rename action requires a destination parameter to be present");
if (getAction().equals("mtime") && parameterList.findParameter("mtime") == null)
throw new ConfigurationException(getLogPrefix() + "the mtime action requires a mtime parameter to be present");
accessTokenCf = new CredentialFactory(getAuthAlias(), getNonce(), getAccessToken());
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class XmlSwitch method doPipe.
/**
* This is where the action takes place, the switching is done. Pipes may only throw a PipeRunException,
* to be handled by the caller of this object.<br/>
* As WebLogic has the problem that when an non-well formed XML stream is given to
* weblogic.xerces the transformer gets corrupt, on an exception the configuration is done again, so that the
* transformer is re-initialized.
*/
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String forward = "";
String sInput = (String) input;
PipeForward pipeForward = null;
if (StringUtils.isNotEmpty(getSessionKey())) {
sInput = (String) session.get(sessionKey);
}
if (transformerPool != null) {
ParameterList parameterList = null;
ParameterResolutionContext prc = new ParameterResolutionContext(sInput, session, isNamespaceAware());
;
try {
Map parametervalues = null;
if (getParameterList() != null) {
parameterList = getParameterList();
parametervalues = prc.getValueMap(parameterList);
}
forward = transformerPool.transform(prc.getInputSource(), parametervalues);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception on transformation", e);
}
} else {
forward = sInput;
}
log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
if (StringUtils.isEmpty(forward) && getEmptyForwardName() != null) {
throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
pipeForward = findForward(getEmptyForwardName());
} else {
if (findForward(forward) != null) {
throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
pipeForward = findForward(forward);
} else {
log.info(getLogPrefix(session) + "determined forward [" + forward + "], which is not defined. Will use [" + getNotFoundForwardName() + "] instead");
throwEvent(XML_SWITCH_FORWARD_NOT_FOUND_MONITOR_EVENT);
pipeForward = findForward(getNotFoundForwardName());
}
}
if (pipeForward == null) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot find forward or pipe named [" + forward + "]");
}
return new PipeRunResult(pipeForward, input);
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class XsltPipe method doPipe.
/**
* Here the actual transforming is done. Under weblogic the transformer object becomes
* corrupt when a not-well formed xml was handled. The transformer is then re-initialized
* via the configure() and start() methods.
*/
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (input == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null input");
}
if (!(input instanceof String)) {
throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
}
String stringResult = (String) input;
// ParameterResolutionContext prc = new ParameterResolutionContext((String)input, session, isNamespaceAware());
try {
ParameterResolutionContext prc = getInput(stringResult, session);
Map parametervalues = null;
ParameterList parameterList = getParameterList();
if (parameterList != null) {
parametervalues = prc.getValueMap(parameterList);
}
// stringResult = transformerPool.transform(prc.getInputSource(), parametervalues);
stringResult = transform(transformerPool, prc.getInputSource(), parametervalues);
if (isSkipEmptyTags()) {
log.debug(getLogPrefix(session) + " skipping empty tags from result [" + stringResult + "]");
// URL xsltSource = ClassUtils.getResourceURL( this, skipEmptyTags_xslt);
// Transformer transformer = XmlUtils.createTransformer(xsltSource);
// stringResult = XmlUtils.transformXml(transformer, stringResult);
ParameterResolutionContext prc_SkipEmptyTags = new ParameterResolutionContext(stringResult, session, true, true);
stringResult = transformerPoolSkipEmptyTags.transform(prc_SkipEmptyTags.getInputSource(), null);
}
if (StringUtils.isEmpty(getSessionKey())) {
return new PipeRunResult(getForward(), stringResult);
}
session.put(getSessionKey(), stringResult);
return new PipeRunResult(getForward(), input);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on transforming input", e);
}
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class MessageSendingPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String originalMessage = input.toString();
String result = null;
String correlationID = session.getMessageId();
if (getInputWrapper() != null) {
log.debug(getLogPrefix(session) + "wrapping input");
PipeRunResult wrapResult = pipeProcessor.processPipe(getPipeLine(), inputWrapper, correlationID, input, session);
if (wrapResult != null && !wrapResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
return wrapResult;
} else {
input = wrapResult.getResult();
}
log.debug(getLogPrefix(session) + "input after wrapping [" + input.toString() + "]");
}
if (getInputValidator() != null) {
log.debug(getLogPrefix(session) + "validating input");
PipeRunResult validationResult = pipeProcessor.processPipe(getPipeLine(), inputValidator, correlationID, input, session);
if (validationResult != null && !validationResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
return validationResult;
}
}
if (StringUtils.isNotEmpty(getStubFileName())) {
ParameterList pl = getParameterList();
result = returnString;
if (pl != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
Map params;
try {
params = prc.getValueMap(pl);
} catch (ParameterException e1) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception evaluating parameters", e1);
}
String sfn = null;
if (params != null && params.size() > 0) {
sfn = (String) params.get(STUBFILENAME);
}
if (sfn != null) {
try {
result = Misc.resourceToString(ClassUtils.getResourceURL(classLoader, sfn), SystemUtils.LINE_SEPARATOR);
log.info(getLogPrefix(session) + "returning result from dynamic stub [" + sfn + "]");
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception loading result from stub [" + sfn + "]", e);
}
} else {
log.info(getLogPrefix(session) + "returning result from static stub [" + getStubFileName() + "]");
}
} else {
log.info(getLogPrefix(session) + "returning result from static stub [" + getStubFileName() + "]");
}
} else {
Map threadContext = new HashMap();
try {
String messageID = null;
// sendResult has a messageID for async senders, the result for sync senders
int retryInterval = getRetryMinInterval();
String sendResult = null;
boolean replyIsValid = false;
int retriesLeft = 0;
if (getMaxRetries() > 0) {
retriesLeft = getMaxRetries() + 1;
} else {
retriesLeft = 1;
}
while (retriesLeft-- >= 1 && !replyIsValid) {
try {
sendResult = sendMessage(input, session, correlationID, getSender(), threadContext);
if (retryTp != null) {
String retry = retryTp.transform(sendResult, null);
if (retry.equalsIgnoreCase("true")) {
if (retriesLeft >= 1) {
retryInterval = increaseRetryIntervalAndWait(session, retryInterval, "xpathRetry result [" + retry + "], retries left [" + retriesLeft + "]");
}
} else {
replyIsValid = true;
}
} else {
replyIsValid = true;
}
} catch (TimeOutException toe) {
if (retriesLeft >= 1) {
retryInterval = increaseRetryIntervalAndWait(session, retryInterval, "timeout occured, retries left [" + retriesLeft + "]");
} else {
throw toe;
}
} catch (SenderException se) {
if (retriesLeft >= 1) {
retryInterval = increaseRetryIntervalAndWait(session, retryInterval, "exception [" + (se != null ? se.getMessage() : "") + "] occured, retries left [" + retriesLeft + "]");
} else {
throw se;
}
}
}
if (!replyIsValid) {
throw new PipeRunException(this, getLogPrefix(session) + "invalid reply message is received");
}
if (getSender().isSynchronous()) {
if (log.isInfoEnabled()) {
log.info(getLogPrefix(session) + "sent message to [" + getSender().getName() + "] synchronously");
}
result = sendResult;
} else {
messageID = sendResult;
if (log.isInfoEnabled()) {
log.info(getLogPrefix(session) + "sent message to [" + getSender().getName() + "] messageID [" + messageID + "] correlationID [" + correlationID + "] linkMethod [" + getLinkMethod() + "]");
}
// as this will be used with the listener
if (getLinkMethod().equalsIgnoreCase("MESSAGEID")) {
correlationID = sendResult;
if (log.isDebugEnabled())
log.debug(getLogPrefix(session) + "setting correlationId to listen for to messageId [" + correlationID + "]");
}
}
ITransactionalStorage messageLog = getMessageLog();
if (messageLog != null) {
long messageLogStartTime = System.currentTimeMillis();
String messageTrail = "no audit trail";
if (auditTrailTp != null) {
if (isUseInputForExtract()) {
messageTrail = auditTrailTp.transform(originalMessage, null);
} else {
messageTrail = auditTrailTp.transform((String) input, null);
}
} else {
if (StringUtils.isNotEmpty(getAuditTrailSessionKey())) {
messageTrail = (String) (session.get(getAuditTrailSessionKey()));
}
}
String storedMessageID = messageID;
if (storedMessageID == null) {
storedMessageID = "-";
}
if (correlationIDTp != null) {
if (StringUtils.isNotEmpty(getCorrelationIDSessionKey())) {
String sourceString = (String) (session.get(getCorrelationIDSessionKey()));
correlationID = correlationIDTp.transform(sourceString, null);
} else {
if (isUseInputForExtract()) {
correlationID = correlationIDTp.transform(originalMessage, null);
} else {
correlationID = correlationIDTp.transform((String) input, null);
}
}
if (StringUtils.isEmpty(correlationID)) {
correlationID = "-";
}
}
String label = null;
if (labelTp != null) {
if (isUseInputForExtract()) {
label = labelTp.transform(originalMessage, null);
} else {
label = labelTp.transform((String) input, null);
}
}
if (sender instanceof MailSender) {
String messageInMailSafeForm = (String) session.get("messageInMailSafeForm");
if (hideRegex != null) {
if (getHideMethod().equalsIgnoreCase("FIRSTHALF")) {
messageInMailSafeForm = Misc.hideFirstHalf(messageInMailSafeForm, hideRegex);
} else {
messageInMailSafeForm = Misc.hideAll(messageInMailSafeForm, hideRegex);
}
}
messageLog.storeMessage(storedMessageID, correlationID, new Date(), messageTrail, label, messageInMailSafeForm);
} else {
String message = (String) input;
if (hideRegex != null) {
if (getHideMethod().equalsIgnoreCase("FIRSTHALF")) {
message = Misc.hideFirstHalf(message, hideRegex);
} else {
message = Misc.hideAll(message, hideRegex);
}
}
messageLog.storeMessage(storedMessageID, correlationID, new Date(), messageTrail, label, message);
}
long messageLogEndTime = System.currentTimeMillis();
long messageLogDuration = messageLogEndTime - messageLogStartTime;
StatisticsKeeper sk = getPipeLine().getPipeStatistics(messageLog);
sk.addValue(messageLogDuration);
}
if (sender instanceof MailSender) {
session.remove("messageInMailSafeForm");
}
if (getListener() != null) {
result = listenerProcessor.getMessage(getListener(), correlationID, session);
} else {
result = sendResult;
}
if (result == null) {
result = "";
}
if (timeoutPending) {
timeoutPending = false;
throwEvent(PIPE_CLEAR_TIMEOUT_MONITOR_EVENT);
}
} catch (TimeOutException toe) {
throwEvent(PIPE_TIMEOUT_MONITOR_EVENT);
if (!timeoutPending) {
timeoutPending = true;
}
PipeForward timeoutForward = findForward(TIMEOUT_FORWARD);
log.warn(getLogPrefix(session) + "timeout occured");
if (timeoutForward == null) {
if (StringUtils.isEmpty(getResultOnTimeOut())) {
timeoutForward = findForward(EXCEPTION_FORWARD);
} else {
timeoutForward = getForward();
}
}
if (timeoutForward != null) {
String resultmsg;
if (StringUtils.isNotEmpty(getResultOnTimeOut())) {
resultmsg = getResultOnTimeOut();
} else {
if (input instanceof String) {
resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), toe, this, (String) input, session.getMessageId(), 0);
} else {
if (input == null) {
input = "null";
}
resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), toe, this, input.toString(), session.getMessageId(), 0);
}
}
return new PipeRunResult(timeoutForward, resultmsg);
}
throw new PipeRunException(this, getLogPrefix(session) + "caught timeout-exception", toe);
} catch (Throwable t) {
throwEvent(PIPE_EXCEPTION_MONITOR_EVENT);
PipeForward exceptionForward = findForward(EXCEPTION_FORWARD);
if (exceptionForward != null) {
log.warn(getLogPrefix(session) + "exception occured, forwarding to exception-forward [" + exceptionForward.getPath() + "], exception:\n", t);
String resultmsg;
if (input instanceof String) {
resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), t, this, (String) input, session.getMessageId(), 0);
} else {
if (input == null) {
input = "null";
}
resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), t, this, input.toString(), session.getMessageId(), 0);
}
return new PipeRunResult(exceptionForward, resultmsg);
}
throw new PipeRunException(this, getLogPrefix(session) + "caught exception", t);
}
}
if (!validResult(result)) {
PipeForward illegalResultForward = findForward(ILLEGAL_RESULT_FORWARD);
return new PipeRunResult(illegalResultForward, result);
}
IPipe outputValidator = getOutputValidator();
if (outputValidator != null) {
log.debug(getLogPrefix(session) + "validating response");
PipeRunResult validationResult;
validationResult = pipeProcessor.processPipe(getPipeLine(), outputValidator, correlationID, result, session);
if (validationResult != null && !validationResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
return validationResult;
}
}
if (getOutputWrapper() != null) {
log.debug(getLogPrefix(session) + "wrapping response");
PipeRunResult wrapResult = pipeProcessor.processPipe(getPipeLine(), outputWrapper, correlationID, result, session);
if (wrapResult != null && !wrapResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
return wrapResult;
}
result = wrapResult.getResult().toString();
log.debug(getLogPrefix(session) + "response after wrapping [" + result + "]");
}
if (isStreamResultToServlet()) {
byte[] bytes = Base64.decodeBase64(new String(result));
try {
String contentType = (String) session.get("contentType");
if (StringUtils.isNotEmpty(contentType)) {
RestListenerUtils.setResponseContentType(session, contentType);
}
RestListenerUtils.writeToResponseOutputStream(session, bytes);
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "caught exception", e);
}
return new PipeRunResult(getForward(), "");
} else {
return new PipeRunResult(getForward(), result);
}
}
Aggregations