use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlValidatorSender method sendMessage.
@Override
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException {
IPipeLineSession session = prc.getSession();
String fullReasons = "tja";
try {
String resultEvent = validate(message, session, getLogPrefix(), null, null, false);
if (AbstractXmlValidator.XML_VALIDATOR_VALID_MONITOR_EVENT.equals(resultEvent)) {
return message;
}
// TODO: find real fullReasons
fullReasons = resultEvent;
if (isThrowException()) {
throw new SenderException(fullReasons);
}
log.warn(fullReasons);
return message;
} catch (Exception e) {
if (isThrowException()) {
throw new SenderException(e);
}
log.warn(fullReasons, e);
return message;
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class IbisLocalSender method open.
public void open() throws SenderException {
super.open();
if (StringUtils.isNotEmpty(getJavaListener()) && isCheckDependency()) {
boolean listenerOpened = false;
int loops = getDependencyTimeOut();
while (!listenerOpened && !configuration.isUnloadInProgressOrDone() && (loops == -1 || loops > 0)) {
JavaListener listener = JavaListener.getListener(getJavaListener());
if (listener != null) {
listenerOpened = listener.isOpen();
}
if (!listenerOpened && !configuration.isUnloadInProgressOrDone()) {
if (loops != -1) {
loops--;
}
try {
log.debug("waiting for JavaListener [" + getJavaListener() + "] to open");
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new SenderException(e);
}
}
}
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class MailSender method retrieveAttachments.
private Collection<Attachment> retrieveAttachments(Collection<Node> attachmentsNode, ParameterResolutionContext prc) throws SenderException {
Collection<Attachment> attachments = null;
Iterator iter = attachmentsNode.iterator();
if (iter.hasNext()) {
attachments = new LinkedList<Attachment>();
while (iter.hasNext()) {
Element attachmentElement = (Element) iter.next();
String name = attachmentElement.getAttribute("name");
String sessionKey = attachmentElement.getAttribute("sessionKey");
String url = attachmentElement.getAttribute("url");
boolean base64 = Boolean.parseBoolean(attachmentElement.getAttribute("base64"));
Object value = null;
if (StringUtils.isNotEmpty(sessionKey)) {
Object object = prc.getSession().get(sessionKey);
if (object instanceof InputStream) {
DataSource attachmentDataSource;
try {
attachmentDataSource = new ByteArrayDataSource((InputStream) object, "application/octet-stream");
} catch (IOException e) {
throw new SenderException("error retrieving attachment from sessionkey", e);
}
value = new DataHandler(attachmentDataSource);
} else if (object instanceof String) {
String skValue = (String) object;
if (base64) {
value = decodeBase64(skValue);
} else {
value = skValue;
}
} else {
throw new SenderException("MailSender [" + getName() + "] received unknown attachment type [" + object.getClass().getName() + "] in sessionkey");
}
} else {
if (StringUtils.isNotEmpty(url)) {
DataSource attachmentDataSource;
try {
attachmentDataSource = new URLDataSource(new URL(url));
} catch (MalformedURLException e) {
throw new SenderException("error retrieving attachment from url", e);
}
value = new DataHandler(attachmentDataSource);
} else {
String nodeValue = XmlUtils.getStringValue(attachmentElement);
if (base64) {
value = decodeBase64(nodeValue);
} else {
value = nodeValue;
}
}
}
Attachment attachment = new Attachment(value, name);
attachments.add(attachment);
}
}
return attachments;
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class ParallelSenders method doSendMessage.
public String doSendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Guard guard = new Guard();
Map<ISender, ParallelSenderExecutor> executorMap = new HashMap<ISender, ParallelSenderExecutor>();
TaskExecutor executor = createTaskExecutor();
for (Iterator<ISender> it = getSenderIterator(); it.hasNext(); ) {
ISender sender = it.next();
// Create a new ParameterResolutionContext to be thread safe, see
// documentation on constructor of ParameterResolutionContext
// (parameter cacheXmlSource).
// Testing also showed that disabling caching is better for
// performance. At least when testing with a lot of large messages
// in parallel. This might be due to the fact that objects can be
// garbage collected earlier. OutOfMemoryErrors occur much
// faster when caching is enabled. Testing was done by sending 10
// messages of 1 MB concurrently to a pipeline which will process
// the message in parallel with 10 SenderWrappers (containing a
// XsltSender and IbisLocalSender).
ParameterResolutionContext newPrc = new ParameterResolutionContext(prc.getInput(), prc.getSession(), prc.isNamespaceAware(), prc.isXslt2(), false);
guard.addResource();
ParallelSenderExecutor pse = new ParallelSenderExecutor(sender, correlationID, message, newPrc, guard, getStatisticsKeeper(sender));
executorMap.put(sender, pse);
executor.execute(pse);
}
try {
guard.waitForAllResources();
} catch (InterruptedException e) {
throw new SenderException(getLogPrefix() + "was interupted", e);
}
XmlBuilder resultsXml = new XmlBuilder("results");
for (Iterator<ISender> it = getSenderIterator(); it.hasNext(); ) {
ISender sender = it.next();
ParallelSenderExecutor pse = (ParallelSenderExecutor) executorMap.get(sender);
XmlBuilder resultXml = new XmlBuilder("result");
resultXml.addAttribute("senderClass", ClassUtils.nameOf(sender));
resultXml.addAttribute("senderName", sender.getName());
Throwable throwable = pse.getThrowable();
if (throwable == null) {
Object result = pse.getReply();
if (result == null) {
resultXml.addAttribute("type", "null");
} else {
resultXml.addAttribute("type", ClassUtils.nameOf(result));
resultXml.setValue(XmlUtils.skipXmlDeclaration(result.toString()), false);
}
} else {
resultXml.addAttribute("type", ClassUtils.nameOf(throwable));
resultXml.setValue(throwable.getMessage());
}
resultsXml.addSubElement(resultXml);
}
return resultsXml.toXML();
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class ReloadSender method sendMessage.
@Override
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws TimeOutException, SenderException {
String configName = null;
String activeVersion = null;
ParameterValueList pvl = null;
try {
if (prc != null && paramList != null) {
pvl = prc.getValues(paramList);
if (pvl.getParameterValue("name") != null)
configName = (String) pvl.getParameterValue("name").getValue();
if (pvl.getParameterValue("forceReload") != null)
setForceReload((Boolean) pvl.getParameterValue("forceReload").getValue());
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
}
try {
if (configName == null)
configName = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='NAME']");
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "error evaluating Xpath expression configName", e);
}
try {
if (!getForceReload())
activeVersion = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='VERSION']");
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "error evaluating Xpath expression activeVersion", e);
}
Configuration configuration = getPipe().getAdapter().getConfiguration().getIbisManager().getConfiguration(configName);
if (configuration != null) {
String latestVersion = configuration.getVersion();
if (getForceReload() || (latestVersion != null && !activeVersion.equals(latestVersion))) {
IbisContext ibisContext = configuration.getIbisManager().getIbisContext();
ibisContext.reload(configName);
return "Reload " + configName + " succeeded";
} else {
return "Reload " + configName + " skipped";
}
} else {
log.warn("Configuration [" + configName + "] not loaded yet");
return "Reload " + configName + " skipped";
}
}
Aggregations