use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.
the class FileUtils method getFilename.
/**
* Construct a filename from a pattern and session variables.
*/
public static String getFilename(ParameterList definedParameters, IPipeLineSession session, String originalFilename, String filenamePattern) throws ParameterException {
// no pattern defined, outputname = inputname
if (StringUtils.isEmpty(filenamePattern)) {
return originalFilename;
}
// obtain filename
int ndx = originalFilename.lastIndexOf('.');
String name = originalFilename;
String extension = "";
if (ndx > 0) {
name = originalFilename.substring(0, ndx);
extension = originalFilename.substring(ndx + 1);
}
// construct the parameterlist
ParameterList pl = new ParameterList();
try {
if (definedParameters != null)
pl.addAll(definedParameters);
Parameter p = new Parameter();
p.setName("file");
p.setDefaultValue(name);
p.configure();
pl.add(p);
p = new Parameter();
p.setName("ext");
p.setDefaultValue(extension);
p.configure();
pl.add(p);
p = new Parameter();
p.setName("__filename");
p.setPattern(filenamePattern);
p.configure();
pl.add(p);
} catch (ConfigurationException e) {
throw new ParameterException(e);
}
// resolve the parameters
ParameterResolutionContext prc = new ParameterResolutionContext((String) null, session);
ParameterValueList pvl = prc.getValues(pl);
String filename = pvl.getParameterValue("__filename").getValue().toString();
return filename;
}
use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.
the class GetTibcoQueues method doPipeWithTimeoutGuarded.
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
String result;
String url_work;
String authAlias_work;
String userName_work;
String password_work;
String queueName_work = null;
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);
}
}
url_work = getParameterValue(pvl, "url");
if (url_work == null) {
url_work = getUrl();
}
authAlias_work = getParameterValue(pvl, "authAlias");
if (authAlias_work == null) {
authAlias_work = getAuthAlias();
}
userName_work = getParameterValue(pvl, "userName");
if (userName_work == null) {
userName_work = getUserName();
}
password_work = getParameterValue(pvl, "password");
if (password_work == null) {
password_work = getPassword();
}
CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
Connection connection = null;
Session jSession = null;
TibjmsAdmin admin = null;
try {
admin = TibcoUtils.getActiveServerAdmin(url_work, cf);
if (admin == null) {
throw new PipeRunException(this, "could not find an active server");
}
String ldapUrl = getParameterValue(pvl, "ldapUrl");
LdapSender ldapSender = null;
if (StringUtils.isNotEmpty(ldapUrl)) {
ldapSender = retrieveLdapSender(ldapUrl, cf);
}
queueName_work = getParameterValue(pvl, "queueName");
if (StringUtils.isNotEmpty(queueName_work)) {
String countOnly_work = getParameterValue(pvl, "countOnly");
boolean countOnly = ("true".equalsIgnoreCase(countOnly_work) ? true : false);
if (countOnly) {
return getQueueMessageCountOnly(admin, queueName_work);
}
}
ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work);
connection = factory.createConnection(cf.getUsername(), cf.getPassword());
jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
if (StringUtils.isNotEmpty(queueName_work)) {
String queueItem_work = getParameterValue(pvl, "queueItem");
int qi;
if (StringUtils.isNumeric(queueItem_work)) {
qi = Integer.parseInt(queueItem_work);
} else {
qi = 1;
}
result = getQueueMessage(jSession, admin, queueName_work, qi, ldapSender);
} else {
String showAge_work = getParameterValue(pvl, "showAge");
boolean showAge = ("true".equalsIgnoreCase(showAge_work) ? true : false);
result = getQueuesInfo(jSession, admin, showAge, ldapSender);
}
} catch (Exception e) {
String msg = getLogPrefix(session) + "exception on showing Tibco queues, url [" + url_work + "]" + (StringUtils.isNotEmpty(queueName_work) ? " queue [" + queueName_work + "]" : "");
throw new PipeRunException(this, msg, e);
} finally {
if (admin != null) {
try {
admin.close();
} catch (TibjmsAdminException e) {
log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e);
}
}
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
log.warn(getLogPrefix(session) + "exception on closing connection", e);
}
}
}
return result;
}
use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.
the class SapSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String tid = null;
try {
ParameterValueList pvl = null;
if (prc != null) {
pvl = prc.getValues(paramList);
}
SapSystem sapSystem = getSystem(pvl);
JCoFunction function = getFunction(sapSystem, pvl);
if (StringUtils.isEmpty(getSapSystemName())) {
pvl.removeParameterValue(getSapSystemNameParam());
}
if (StringUtils.isEmpty(getFunctionName())) {
pvl.removeParameterValue(getFunctionNameParam());
}
message2FunctionCall(function, message, correlationID, pvl);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + " function call [" + functionCall2message(function) + "]");
JCoDestination destination = getDestination(prc.getSession(), sapSystem);
tid = getTid(destination, sapSystem);
if (StringUtils.isEmpty(tid)) {
function.execute(destination);
} else {
function.execute(destination, tid);
}
if (isSynchronous()) {
return functionResult2message(function);
} else {
return tid;
}
} catch (Exception e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.parameters.ParameterValueList 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.ParameterValueList 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