use of nl.nn.adapterframework.parameters.ParameterValue 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.parameters.ParameterValue in project iaf by ibissource.
the class FileHandler method createFile.
private File createFile(byte[] in, IPipeLineSession session, ParameterList paramList) throws IOException, ParameterException {
File tmpFile;
String writeSuffix_work = null;
if (paramList != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) null, session);
ParameterValueList pvl = prc.getValues(paramList);
if (pvl != null) {
ParameterValue writeSuffixParamValue = pvl.getParameterValue("writeSuffix");
if (writeSuffixParamValue != null) {
writeSuffix_work = (String) writeSuffixParamValue.getValue();
}
}
}
if (writeSuffix_work == null) {
writeSuffix_work = getWriteSuffix();
}
String name = getEffectiveFileName(null, session);
if (StringUtils.isEmpty(getDirectory())) {
if (StringUtils.isEmpty(name)) {
tmpFile = File.createTempFile("ibis", writeSuffix_work);
} else {
tmpFile = new File(name);
}
} else {
if (StringUtils.isEmpty(name)) {
tmpFile = File.createTempFile("ibis", writeSuffix_work, new File(getDirectory()));
} else {
tmpFile = new File(getDirectory() + File.separator + name);
}
}
return tmpFile;
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class SapSender method getFunction.
public JCO.Function getFunction(SapSystem sapSystem, ParameterValueList pvl) throws SapException {
if (StringUtils.isNotEmpty(getSapSystemName()) && StringUtils.isNotEmpty(getFunctionName())) {
return getFunctionTemplate().getFunction();
}
String functionName = getFunctionName();
if (StringUtils.isEmpty(functionName)) {
if (pvl == null) {
throw new SapException("no parameters to determine functionName from");
}
ParameterValue pv = pvl.getParameterValue(getFunctionNameParam());
if (pv == null) {
throw new SapException("could not get ParameterValue for parameter [" + getFunctionNameParam() + "]");
}
functionName = pv.asStringValue(null);
}
if (StringUtils.isEmpty(functionName)) {
throw new SapException("could not determine functionName using parameter [" + getFunctionNameParam() + "]");
}
return getFunctionTemplate(sapSystem, functionName).getFunction();
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class FixedResultSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException {
String result = returnString;
if (prc != null) {
ParameterValueList pvl;
try {
pvl = prc.getValues(paramList);
} catch (ParameterException e) {
throw new SenderException("exception extracting parameters", e);
}
if (pvl != null) {
for (int i = 0; i < pvl.size(); i++) {
ParameterValue pv = pvl.getParameterValue(i);
result = replace(result, "${" + pv.getDefinition().getName() + "}", pv.asStringValue(""));
}
}
}
if (getSubstituteVars()) {
result = StringResolver.substVars(returnString, prc.getSession());
}
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 SenderException("cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e);
} catch (TransformerConfigurationException te) {
throw new SenderException("got error creating transformer from file [" + styleSheetName + "]", te);
} catch (TransformerException te) {
throw new SenderException("got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te);
} catch (DomBuilderException te) {
throw new SenderException("caught DomBuilderException", te);
}
}
}
log.debug("returning fixed result [" + result + "]");
return result;
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class MailSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String from = null;
String subject = null;
String threadTopic = null;
String messageType = null;
String messageBase64 = null;
String charset = null;
Collection<Recipient> recipients = null;
Collection<Attachment> attachments = null;
ParameterValueList pvl;
ParameterValue pv;
String messageInMailSafeForm;
if (paramList == null) {
messageInMailSafeForm = sendEmail(message, prc);
} else {
try {
pvl = prc.getValues(paramList);
pv = pvl.getParameterValue("from");
if (pv != null) {
from = pv.asStringValue(null);
log.debug("MailSender [" + getName() + "] retrieved from-parameter [" + from + "]");
}
pv = pvl.getParameterValue("subject");
if (pv != null) {
subject = pv.asStringValue(null);
log.debug("MailSender [" + getName() + "] retrieved subject-parameter [" + subject + "]");
}
pv = pvl.getParameterValue("threadTopic");
if (pv != null) {
threadTopic = pv.asStringValue(null);
log.debug("MailSender [" + getName() + "] retrieved threadTopic-parameter [" + threadTopic + "]");
}
pv = pvl.getParameterValue("message");
if (pv != null) {
message = pv.asStringValue(message);
log.debug("MailSender [" + getName() + "] retrieved message-parameter [" + message + "]");
}
pv = pvl.getParameterValue("messageType");
if (pv != null) {
messageType = pv.asStringValue(null);
log.debug("MailSender [" + getName() + "] retrieved messageType-parameter [" + messageType + "]");
}
pv = pvl.getParameterValue("messageBase64");
if (pv != null) {
messageBase64 = pv.asStringValue(null);
log.debug("MailSender [" + getName() + "] retrieved messageBase64-parameter [" + messageBase64 + "]");
}
pv = pvl.getParameterValue("charset");
if (pv != null) {
charset = pv.asStringValue(null);
log.debug("MailSender [" + getName() + "] retrieved charset-parameter [" + charset + "]");
}
pv = pvl.getParameterValue("recipients");
if (pv != null) {
recipients = retrieveRecipients(pv.asCollection());
log.debug("MailSender [" + getName() + "] retrieved recipients-parameter [" + recipients + "]");
}
pv = pvl.getParameterValue("attachments");
if (pv != null) {
attachments = retrieveAttachments(pv.asCollection(), prc);
log.debug("MailSender [" + getName() + "] retrieved attachments-parameter [" + attachments + "]");
}
} catch (ParameterException e) {
throw new SenderException("MailSender [" + getName() + "] got exception determining parametervalues", e);
}
messageInMailSafeForm = sendEmail(from, subject, threadTopic, message, messageType, messageBase64, charset, recipients, attachments);
}
prc.getSession().put("messageInMailSafeForm", messageInMailSafeForm);
return correlationID;
}
Aggregations