use of nl.nn.adapterframework.core.PipeRunResult 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.core.PipeRunResult 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.core.PipeRunResult 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.core.PipeRunResult in project iaf by ibissource.
the class IfMultipart method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String forward;
PipeForward pipeForward = null;
if (input == null) {
forward = elseForwardName;
} else {
if (!(input instanceof HttpServletRequest)) {
throw new PipeRunException(this, getLogPrefix(null) + "expected HttpServletRequest as input, got [" + ClassUtils.nameOf(input) + "]");
}
HttpServletRequest request = (HttpServletRequest) input;
String contentType = request.getContentType();
if (StringUtils.isNotEmpty(contentType) && contentType.startsWith("multipart")) {
forward = thenForwardName;
} else {
forward = elseForwardName;
}
}
log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
pipeForward = findForward(forward);
if (pipeForward == null) {
throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
}
log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
return new PipeRunResult(pipeForward, input);
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class IsUserInRolePipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
try {
if (StringUtils.isEmpty(getRole())) {
String inputString = (String) input;
if (StringUtils.isEmpty(inputString)) {
throw new PipeRunException(this, "role cannot be empty");
}
assertUserIsInRole(session, inputString);
} else {
assertUserIsInRole(session, getRole());
}
} catch (SecurityException e) {
if (notInRoleForward != null) {
return new PipeRunResult(notInRoleForward, input);
} else {
throw new PipeRunException(this, "", e);
}
}
return new PipeRunResult(getForward(), input);
}
Aggregations