use of nl.nn.adapterframework.core.ParameterException 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.core.ParameterException 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.core.ParameterException in project iaf by ibissource.
the class IbisJavaSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String result = null;
HashMap context = null;
try {
if (paramList != null) {
context = (HashMap) prc.getValueMap(paramList);
} else {
context = new HashMap();
}
DispatcherManager dm = null;
Class c = Class.forName("nl.nn.adapterframework.dispatcher.DispatcherManagerFactory");
if (getDispatchType().equalsIgnoreCase("DLL")) {
String version = nl.nn.adapterframework.dispatcher.Version.version;
if (version.contains("IbisServiceDispatcher 1.3"))
throw new SenderException("IBIS-ServiceDispatcher out of date! Please update to version 1.4 or higher");
Method getDispatcherManager = c.getMethod("getDispatcherManager", String.class);
dm = (DispatcherManager) getDispatcherManager.invoke(null, getDispatchType());
} else {
Method getDispatcherManager = c.getMethod("getDispatcherManager");
dm = (DispatcherManager) getDispatcherManager.invoke(null, (Object[]) null);
}
result = dm.processRequest(getServiceName(), correlationID, message, context);
if (isMultipartResponse()) {
return HttpSender.handleMultipartResponse(multipartResponseContentType, new ByteArrayInputStream(result.getBytes(multipartResponseCharset)), prc, null);
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "exception processing message using request processor [" + getServiceName() + "]", e);
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (prc != null) {
Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
}
}
return result;
}
use of nl.nn.adapterframework.core.ParameterException in project iaf by ibissource.
the class IbisLocalSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String result = null;
HashMap context = null;
if (paramList != null) {
try {
context = (HashMap) prc.getValueMap(paramList);
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
}
} else {
if (StringUtils.isNotEmpty(getReturnedSessionKeys())) {
context = new HashMap();
}
}
if (StringUtils.isNotEmpty(getServiceName())) {
try {
if (isIsolated()) {
if (isSynchronous()) {
log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in separate Thread");
result = isolatedServiceCaller.callServiceIsolated(getServiceName(), correlationID, message, context, false);
} else {
log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in asynchronously");
isolatedServiceCaller.callServiceAsynchronous(getServiceName(), correlationID, message, context, false);
result = message;
}
} else {
log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in same Thread");
result = ServiceDispatcher.getInstance().dispatchRequest(getServiceName(), correlationID, message, context);
}
} catch (ListenerException e) {
if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
throw new TimeOutException(getLogPrefix() + "timeout calling service [" + getServiceName() + "]", e);
} else {
throw new SenderException(getLogPrefix() + "exception calling service [" + getServiceName() + "]", e);
}
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (prc != null) {
Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
}
}
} else {
String javaListener;
if (StringUtils.isNotEmpty(getJavaListenerSessionKey())) {
javaListener = (String) prc.getSession().get(getJavaListenerSessionKey());
} else {
javaListener = getJavaListener();
}
try {
JavaListener listener = JavaListener.getListener(javaListener);
if (listener == null) {
String msg = "could not find JavaListener [" + javaListener + "]";
if (isThrowJavaListenerNotFoundException()) {
throw new SenderException(msg);
} else {
log.info(getLogPrefix() + msg);
return "<error>" + msg + "</error>";
}
}
if (isIsolated()) {
if (isSynchronous()) {
log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in separate Thread");
result = isolatedServiceCaller.callServiceIsolated(javaListener, correlationID, message, context, true);
} else {
log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in asynchronously");
isolatedServiceCaller.callServiceAsynchronous(javaListener, correlationID, message, context, true);
result = message;
}
} else {
log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in same Thread");
result = listener.processRequest(correlationID, message, context);
}
} catch (ListenerException e) {
if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
throw new TimeOutException(getLogPrefix() + "timeout calling JavaListener [" + javaListener + "]", e);
} else {
throw new SenderException(getLogPrefix() + "exception calling JavaListener [" + javaListener + "]", e);
}
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (prc != null) {
Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
}
}
}
return result;
}
use of nl.nn.adapterframework.core.ParameterException 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