use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class DomainTransformerPipe method doPipe.
public PipeRunResult doPipe(Object invoer, IPipeLineSession session) throws PipeRunException {
Connection conn = null;
PreparedStatement stmt = null;
StringBuffer buffer = new StringBuffer();
try {
conn = qs.getConnection();
stmt = conn.prepareStatement(query);
String invoerString = invoer.toString();
int startPos = invoerString.indexOf(DT_START);
if (startPos == -1)
return new PipeRunResult(getForward(), invoerString);
char[] invoerChars = invoerString.toCharArray();
int copyFrom = 0;
while (startPos != -1) {
buffer.append(invoerChars, copyFrom, startPos - copyFrom);
int nextStartPos = invoerString.indexOf(DT_START, startPos + DT_START.length());
if (nextStartPos == -1) {
nextStartPos = invoerString.length();
}
int endPos = invoerString.indexOf(DT_END, startPos + DT_START.length());
if (endPos == -1 || endPos > nextStartPos) {
log.warn(getLogPrefix(session) + "Found a start delimiter without an end delimiter at position [" + startPos + "] in [" + invoerString + "]");
buffer.append(invoerChars, startPos, nextStartPos - startPos);
copyFrom = nextStartPos;
} else {
String invoerSubstring = invoerString.substring(startPos + DT_START.length(), endPos);
StringTokenizer st = new StringTokenizer(invoerSubstring, DT_SEPARATOR);
int aantalTokens = st.countTokens();
if (aantalTokens < 2 || aantalTokens > 3) {
log.warn(getLogPrefix(session) + "Only 2 or 3 tokens are allowed in [" + invoerSubstring + "]");
buffer.append(invoerChars, startPos, endPos - startPos + DT_END.length());
copyFrom = endPos + DT_END.length();
} else {
String label = st.nextToken();
String valueIn = st.nextToken();
String type = TYPE_STRING;
if (st.hasMoreTokens()) {
type = st.nextToken();
}
if (!type.equals(TYPE_STRING) && !type.equals(TYPE_NUMBER)) {
log.warn(getLogPrefix(session) + "Only types [" + TYPE_STRING + "," + TYPE_NUMBER + "] are allowed in [" + invoerSubstring + "]");
buffer.append(invoerChars, startPos, endPos - startPos + DT_END.length());
copyFrom = endPos + DT_END.length();
} else {
String valueOut = null;
valueOut = getValueOut(label, valueIn, type, stmt);
if (valueOut != null) {
buffer.append(valueOut);
}
copyFrom = endPos + DT_END.length();
}
}
}
startPos = invoerString.indexOf(DT_START, copyFrom);
}
buffer.append(invoerChars, copyFrom, invoerChars.length - copyFrom);
} catch (Throwable t) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on transforming domain", t);
} finally {
JdbcUtil.fullClose(conn, stmt);
}
return new PipeRunResult(getForward(), buffer.toString());
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class FilenameSwitch method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String forward = "";
String sInput = (String) input;
PipeForward pipeForward = null;
int slashPos = sInput.lastIndexOf('/');
if (slashPos > 0) {
sInput = sInput.substring(slashPos + 1);
}
slashPos = sInput.lastIndexOf('\\');
if (slashPos > 0) {
sInput = sInput.substring(slashPos + 1);
}
forward = sInput;
if (isToLowercase()) {
forward = forward.toLowerCase();
}
log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
if (findForward(forward) != null)
pipeForward = findForward(forward);
else {
log.info(getLogPrefix(session) + "determined forward [" + forward + "], which is not defined. Will use [" + getNotFoundForwardName() + "] instead");
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.core.PipeRunException 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.PipeRunException 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.PipeRunException 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);
}
}
Aggregations