Search in sources :

Example 46 with SenderException

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;
    }
}
Also used : SenderException(nl.nn.adapterframework.core.SenderException) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 47 with SenderException

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);
                }
            }
        }
    }
}
Also used : JavaListener(nl.nn.adapterframework.receivers.JavaListener) SenderException(nl.nn.adapterframework.core.SenderException)

Example 48 with SenderException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) URLDataSource(javax.activation.URLDataSource) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) DataHandler(javax.activation.DataHandler) URL(java.net.URL) URLDataSource(javax.activation.URLDataSource) ByteArrayDataSource(org.apache.soap.util.mime.ByteArrayDataSource) DataSource(javax.activation.DataSource) Iterator(java.util.Iterator) SenderException(nl.nn.adapterframework.core.SenderException) ByteArrayDataSource(org.apache.soap.util.mime.ByteArrayDataSource)

Example 49 with SenderException

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();
}
Also used : HashMap(java.util.HashMap) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) ISender(nl.nn.adapterframework.core.ISender) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) Guard(nl.nn.adapterframework.util.Guard) SenderException(nl.nn.adapterframework.core.SenderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 50 with SenderException

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";
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Configuration(nl.nn.adapterframework.configuration.Configuration) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9