use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class FixedForwardPipe method doInitialPipe.
public PipeRunResult doInitialPipe(Object input, IPipeLineSession session) throws PipeRunException {
if ((input == null || StringUtils.isEmpty(input.toString())) && isSkipOnEmptyInput()) {
return new PipeRunResult(getForward(), input);
}
if (getIfParam() != null) {
boolean skipPipe = true;
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 on extracting parameters", e);
}
}
String ip = getParameterValue(pvl, getIfParam());
if (ip == null) {
if (getIfValue() == null) {
skipPipe = false;
}
} else {
if (getIfValue() != null && getIfValue().equalsIgnoreCase(ip)) {
skipPipe = false;
}
}
if (skipPipe) {
return new PipeRunResult(getForward(), input);
}
}
return null;
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class FixedResult method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String result = returnString;
if ((StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) || StringUtils.isNotEmpty(getFileNameSessionKey())) {
String fileName = null;
if (StringUtils.isNotEmpty(getFileNameSessionKey())) {
fileName = (String) session.get(fileNameSessionKey);
}
if (fileName == null) {
if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
fileName = getFileName();
}
}
URL resource = null;
try {
resource = ClassUtils.getResourceURL(classLoader, fileName);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + fileName + "]", e);
}
if (resource == null) {
PipeForward fileNotFoundForward = findForward(FILE_NOT_FOUND_FORWARD);
if (fileNotFoundForward != null) {
return new PipeRunResult(fileNotFoundForward, input);
} else {
throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + fileName + "]");
}
}
try {
result = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + fileName + "]", e);
}
}
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);
String replaceFrom;
if (isReplaceFixedParams()) {
replaceFrom = pv.getDefinition().getName();
} else {
replaceFrom = "${" + pv.getDefinition().getName() + "}";
}
result = replace(result, replaceFrom, pv.asStringValue(""));
}
}
if (getSubstituteVars()) {
result = StringResolver.substVars(returnString, session, appConstants);
}
if (StringUtils.isNotEmpty(styleSheetName)) {
URL xsltSource = ClassUtils.getResourceURL(classLoader, styleSheetName);
if (xsltSource != null) {
try {
String xsltResult = null;
Transformer transformer = XmlUtils.createTransformer(xsltSource);
xsltResult = XmlUtils.transformXml(transformer, result);
result = xsltResult;
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e);
} catch (TransformerConfigurationException te) {
throw new PipeRunException(this, getLogPrefix(session) + "got error creating transformer from file [" + styleSheetName + "]", te);
} catch (TransformerException te) {
throw new PipeRunException(this, getLogPrefix(session) + "got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te);
} catch (DomBuilderException te) {
throw new PipeRunException(this, getLogPrefix(session) + "caught DomBuilderException", te);
}
}
}
log.debug(getLogPrefix(session) + " returning fixed result [" + result + "]");
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class HashPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String message = (String) input;
String authAlias = getAuthAlias();
String secret = getSecret();
try {
ParameterList parameterList = getParameterList();
ParameterResolutionContext prc = new ParameterResolutionContext(message, session);
ParameterValueList pvl = prc.getValues(parameterList);
if (pvl != null) {
Parameter authAliasParam = parameterList.findParameter("authAlias");
if (authAliasParam != null)
authAlias = (String) authAliasParam.getValue(pvl, prc);
Parameter secretParam = parameterList.findParameter("secret");
if (secretParam != null)
secret = (String) secretParam.getValue(pvl, prc);
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting authAlias", e);
}
CredentialFactory accessTokenCf = new CredentialFactory(authAlias, "", secret);
String cfSecret = accessTokenCf.getPassword();
if (cfSecret == null || cfSecret.isEmpty())
throw new PipeRunException(this, getLogPrefix(session) + "empty secret, unable to hash");
try {
Mac mac = Mac.getInstance(getAlgorithm());
SecretKeySpec secretkey = new SecretKeySpec(cfSecret.getBytes(getEncoding()), "algorithm");
mac.init(secretkey);
String hash = Base64.encodeBase64String(mac.doFinal(message.getBytes()));
return new PipeRunResult(getForward(), hash);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "error creating hash", e);
}
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class CmisHttpSender method invoke.
public Response invoke(String url, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) throws SenderException, TimeOutException {
// Prepare the message. We will overwrite things later...
this.headers = headers;
int responseCode = -1;
IPipeLineSession pls = new PipeLineSessionBase();
pls.put("writer", writer);
pls.put("url", url);
ParameterResolutionContext prc = new ParameterResolutionContext("", pls);
try {
sendMessageWithTimeoutGuarded(null, null, prc);
return (Response) pls.get("response");
} catch (Exception e) {
throw new CmisConnectionException(getUrl(), responseCode, e);
}
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class XslErrorMessageFormatter method format.
@Override
public String format(String message, Throwable t, INamedObject location, String originalMessage, String messageId, long receivedTime) {
String result = super.format(message, t, location, originalMessage, messageId, receivedTime);
if (StringUtils.isNotEmpty(getStyleSheet()) || StringUtils.isNotEmpty(getXpathExpression())) {
try {
Transformer errorTransformer;
if (StringUtils.isNotEmpty(getStyleSheet())) {
errorTransformer = XmlUtils.createTransformer(ClassUtils.getResourceURL(this, styleSheet));
} else {
String xpath = getXpathExpression();
// if (StringUtils.isEmpty(xpath)) {
// xpath="/errorMessage/@message";
// }
errorTransformer = XmlUtils.createTransformer(XmlUtils.createXPathEvaluatorSource(xpath));
}
ParameterList params = getParameterList();
if (params != null) {
try {
params.configure();
} catch (ConfigurationException e) {
log.error("exception while configuring parameters", e);
}
ParameterResolutionContext prc = new ParameterResolutionContext(message, new PipeLineSessionBase());
Map<String, Object> parametervalues = null;
try {
parametervalues = prc.getValueMap(params);
} catch (ParameterException e) {
log.error("got exception extracting parameters", e);
}
XmlUtils.setTransformerParameters(errorTransformer, parametervalues);
}
result = XmlUtils.transformXml(errorTransformer, result);
} catch (IOException e) {
log.error(" cannot retrieve [" + styleSheet + "]", e);
} catch (javax.xml.transform.TransformerConfigurationException te) {
log.error("got error creating transformer from file [" + styleSheet + "]", te);
} catch (Exception tfe) {
log.error("could not transform [" + result + "] using stylesheet [" + styleSheet + "]", tfe);
}
} else
log.warn("no stylesheet defined for XslErrorMessageFormatter");
return result;
}
Aggregations