Search in sources :

Example 16 with ISender

use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.

the class ShadowSender method doSendMessage.

/**
 * We override this from the parallel sender as we should only execute the original and shadowsenders here!
 */
@Override
public Message doSendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    Guard guard = new Guard();
    Map<ISender, ParallelSenderExecutor> executorMap = new HashMap<ISender, ParallelSenderExecutor>();
    TaskExecutor executor = createTaskExecutor();
    // XsltSender and IbisLocalSender).
    for (Iterator<ISender> it = getExecutableSenders(); it.hasNext(); ) {
        ISender sender = it.next();
        guard.addResource();
        ParallelSenderExecutor pse = new ParallelSenderExecutor(sender, message, session, guard, getStatisticsKeeper(sender));
        executorMap.put(sender, pse);
        executor.execute(pse);
    }
    try {
        guard.waitForAllResources();
    } catch (InterruptedException e) {
        throw new SenderException(getLogPrefix() + "was interupted", e);
    }
    ParallelSenderExecutor originalSender = null;
    XmlBuilder resultsXml = new XmlBuilder("results");
    String correlationID = session == null ? null : session.getMessageId();
    resultsXml.addAttribute("correlationID", correlationID);
    XmlBuilder originalMessageXml = new XmlBuilder("originalMessage");
    try {
        originalMessageXml.setValue(XmlUtils.skipXmlDeclaration(message.asString()), false);
    } catch (IOException e) {
        throw new SenderException(getLogPrefix(), e);
    }
    resultsXml.addSubElement(originalMessageXml);
    // First loop through all (Shadow)Senders and handle their results
    for (Iterator<ISender> it = getExecutableSenders(); it.hasNext(); ) {
        ISender sender = it.next();
        ParallelSenderExecutor pse = executorMap.get(sender);
        XmlBuilder resultXml;
        if (sender.getName() != null && sender.getName().equalsIgnoreCase(getOriginalSender())) {
            originalSender = pse;
            resultXml = new XmlBuilder("originalResult");
        } else {
            resultXml = new XmlBuilder("shadowResult");
        }
        StatisticsKeeper sk = getStatisticsKeeper(sender);
        resultXml.addAttribute("duration", sk.getLast() + sk.getUnits());
        resultXml.addAttribute("count", sk.getCount());
        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);
    }
    // cause an SenderException regardless of the results of the ShadowSenders.
    if (originalSender == null) {
        // In theory this should never happen!
        throw new SenderException("no originalSender found");
    }
    // The messages have been processed, now the results need to be stored somewhere.
    try {
        resultISender.sendMessage(new Message(resultsXml.toXML()), session);
    } catch (SenderException se) {
        log.warn("failed to send ShadowSender result to [" + resultISender.getName() + "]");
    }
    if (originalSender.getThrowable() != null) {
        throw new SenderException(originalSender.getThrowable());
    }
    return originalSender.getReply();
}
Also used : Message(nl.nn.adapterframework.stream.Message) HashMap(java.util.HashMap) IOException(java.io.IOException) TaskExecutor(org.springframework.core.task.TaskExecutor) ISender(nl.nn.adapterframework.core.ISender) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Guard(nl.nn.adapterframework.util.Guard) SenderException(nl.nn.adapterframework.core.SenderException)

Example 17 with ISender

use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.

the class ShowConfigurationStatus method mapAdapterPipes.

private ArrayList<Object> mapAdapterPipes(Adapter adapter) {
    if (!adapter.configurationSucceeded())
        return null;
    PipeLine pipeline = adapter.getPipeLine();
    int totalPipes = pipeline.getPipes().size();
    ArrayList<Object> pipes = new ArrayList<Object>(totalPipes);
    for (int i = 0; i < totalPipes; i++) {
        Map<String, Object> pipesInfo = new HashMap<String, Object>();
        IPipe pipe = pipeline.getPipe(i);
        Map<String, PipeForward> pipeForwards = pipe.getForwards();
        String pipename = pipe.getName();
        Map<String, String> forwards = new HashMap<String, String>();
        for (PipeForward fwrd : pipeForwards.values()) {
            forwards.put(fwrd.getName(), fwrd.getPath());
        }
        pipesInfo.put("name", pipename);
        pipesInfo.put("forwards", forwards);
        if (pipe instanceof HasKeystore) {
            HasKeystore s = (HasKeystore) pipe;
            Map<String, Object> certInfo = addCertificateInfo(s);
            if (certInfo != null)
                pipesInfo.put("certificate", certInfo);
        }
        if (pipe instanceof MessageSendingPipe) {
            MessageSendingPipe msp = (MessageSendingPipe) pipe;
            ISender sender = msp.getSender();
            pipesInfo.put("sender", ClassUtils.nameOf(sender));
            if (sender instanceof HasKeystore) {
                HasKeystore s = (HasKeystore) sender;
                Map<String, Object> certInfo = addCertificateInfo(s);
                if (certInfo != null)
                    pipesInfo.put("certificate", certInfo);
            }
            if (sender instanceof HasPhysicalDestination) {
                pipesInfo.put("destination", ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
            if (sender instanceof JdbcSenderBase) {
                pipesInfo.put("isJdbcSender", true);
            }
            IListener<?> listener = msp.getListener();
            if (listener != null) {
                pipesInfo.put("listenerName", listener.getName());
                pipesInfo.put("listenerClass", ClassUtils.nameOf(listener));
                if (listener instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) listener).getPhysicalDestinationName();
                    pipesInfo.put("listenerDestination", pd);
                }
            }
            ITransactionalStorage<?> messageLog = msp.getMessageLog();
            if (messageLog != null) {
                pipesInfo.put("hasMessageLog", true);
                String messageLogCount;
                try {
                    if (showCountMessageLog) {
                        messageLogCount = "" + messageLog.getMessageCount();
                    } else {
                        messageLogCount = "?";
                    }
                } catch (Exception e) {
                    log.warn("Cannot determine number of messages in messageLog [" + messageLog.getName() + "]", e);
                    messageLogCount = "error";
                }
                pipesInfo.put("messageLogCount", messageLogCount);
                Map<String, Object> message = new HashMap<String, Object>();
                message.put("name", messageLog.getName());
                message.put("type", "log");
                message.put("slotId", messageLog.getSlotId());
                message.put("count", messageLogCount);
                pipesInfo.put("message", message);
            }
        }
        pipes.add(pipesInfo);
    }
    return pipes;
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) HasKeystore(nl.nn.adapterframework.encryption.HasKeystore) PipeForward(nl.nn.adapterframework.core.PipeForward) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) ISender(nl.nn.adapterframework.core.ISender) PipeLine(nl.nn.adapterframework.core.PipeLine) IPipe(nl.nn.adapterframework.core.IPipe) JdbcSenderBase(nl.nn.adapterframework.jdbc.JdbcSenderBase) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 18 with ISender

use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.

the class MessageSendingPipe method configure.

/**
 * Checks whether a sender is defined for this pipe.
 */
@Override
public void configure() throws ConfigurationException {
    super.configure();
    msgLog = LogUtil.getMsgLogger(getAdapter(), this);
    if (StringUtils.isNotEmpty(getStubFilename())) {
        URL stubUrl;
        try {
            stubUrl = ClassUtils.getResourceURL(this, getStubFilename());
        } catch (Throwable e) {
            throw new ConfigurationException("got exception finding resource for stubfile [" + getStubFilename() + "]", e);
        }
        if (stubUrl == null) {
            throw new ConfigurationException("could not find resource for stubfile [" + getStubFilename() + "]");
        }
        try {
            returnString = Misc.resourceToString(stubUrl, Misc.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new ConfigurationException("got exception loading stubfile [" + getStubFilename() + "] from resource [" + stubUrl.toExternalForm() + "]", e);
        }
    } else {
        propagateName();
        if (getSender() == null) {
            throw new ConfigurationException("no sender defined ");
        }
        // because sender might not have been set when addPipe() is called.
        if (getParameterList() != null && getSender() instanceof ISenderWithParameters) {
            for (Parameter p : getParameterList()) {
                if (!p.getName().equals(STUBFILENAME)) {
                    ((ISenderWithParameters) getSender()).addParameter(p);
                }
            }
        }
        try {
            // In order to be able to suppress 'xxxSender may cause potential SQL injections!' config warnings
            if (sender instanceof DirectQuerySender) {
                ((DirectQuerySender) getSender()).configure(getAdapter());
            } else {
                getSender().configure();
            }
        } catch (ConfigurationException e) {
            throw new ConfigurationException("while configuring sender", e);
        }
        if (getSender() instanceof HasPhysicalDestination) {
            log.info(getLogPrefix(null) + "has sender on " + ((HasPhysicalDestination) getSender()).getPhysicalDestinationName());
        }
        if (getListener() != null) {
            if (getSender().isSynchronous()) {
                throw new ConfigurationException("cannot have listener with synchronous sender");
            }
            try {
                getListener().configure();
            } catch (ConfigurationException e) {
                throw new ConfigurationException("while configuring listener", e);
            }
            if (getListener() instanceof HasPhysicalDestination) {
                log.info(getLogPrefix(null) + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
            }
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException("invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (isCheckXmlWellFormed() || StringUtils.isNotEmpty(getCheckRootTag())) {
            if (findForward(ILLEGAL_RESULT_FORWARD) == null)
                throw new ConfigurationException("has no forward with name [illegalResult]");
        }
        if (!ConfigurationUtils.isConfigurationStubbed(getConfigurationClassLoader())) {
            if (StringUtils.isNotEmpty(getTimeOutOnResult())) {
                throw new ConfigurationException("timeOutOnResult only allowed in stub mode");
            }
            if (StringUtils.isNotEmpty(getExceptionOnResult())) {
                throw new ConfigurationException("exceptionOnResult only allowed in stub mode");
            }
        }
        if (getMaxRetries() > 0) {
            if (getRetryMinInterval() < MIN_RETRY_INTERVAL) {
                ConfigurationWarnings.add(this, log, "retryMinInterval [" + getRetryMinInterval() + "] should be greater than or equal to [" + MIN_RETRY_INTERVAL + "], assuming the lower limit");
                setRetryMinInterval(MIN_RETRY_INTERVAL);
            }
            if (getRetryMaxInterval() > MAX_RETRY_INTERVAL) {
                ConfigurationWarnings.add(this, log, "retryMaxInterval [" + getRetryMaxInterval() + "] should be less than or equal to [" + MAX_RETRY_INTERVAL + "], assuming the upper limit");
                setRetryMaxInterval(MAX_RETRY_INTERVAL);
            }
            if (getRetryMaxInterval() < getRetryMinInterval()) {
                ConfigurationWarnings.add(this, log, "retryMaxInterval [" + getRetryMaxInterval() + "] should be greater than or equal to [" + getRetryMinInterval() + "], assuming the lower limit");
                setRetryMaxInterval(getRetryMinInterval());
            }
        }
    }
    ITransactionalStorage messageLog = getMessageLog();
    if (messageLog == null) {
        if (StringUtils.isEmpty(getStubFilename()) && !getSender().isSynchronous() && getListener() == null && !(getSender() instanceof nl.nn.adapterframework.senders.IbisLocalSender)) {
            // sender is asynchronous and not a local sender, but has no messageLog
            boolean suppressIntegrityCheckWarning = ConfigurationWarnings.isSuppressed(SuppressKeys.INTEGRITY_CHECK_SUPPRESS_KEY, getAdapter());
            if (!suppressIntegrityCheckWarning) {
                boolean legacyCheckMessageLog = AppConstants.getInstance(getConfigurationClassLoader()).getBoolean("messageLog.check", true);
                if (!legacyCheckMessageLog) {
                    ConfigurationWarnings.add(this, log, "Suppressing integrityCheck warnings by setting property 'messageLog.check=false' has been replaced by by setting property 'warnings.suppress.integrityCheck=true'");
                    suppressIntegrityCheckWarning = true;
                }
            }
            if (!suppressIntegrityCheckWarning) {
                ConfigurationWarnings.add(this, log, "asynchronous sender [" + getSender().getName() + "] without sibling listener has no messageLog. " + "Service Managers will not be able to perform an integrity check (matching messages received by the adapter to messages sent by this pipe). " + "This warning can be suppressed globally by setting property 'warnings.suppress.integrityCheck=true', " + "or for this adapter only by setting property 'warnings.suppress.integrityCheck." + getAdapter().getName() + "=true'");
            }
        }
    } else {
        if (StringUtils.isNotEmpty(getHideRegex()) && StringUtils.isEmpty(messageLog.getHideRegex())) {
            messageLog.setHideRegex(getHideRegex());
            messageLog.setHideMethod(getHideMethod());
        }
        messageLog.configure();
        if (messageLog instanceof HasPhysicalDestination) {
            String msg = getLogPrefix(null) + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName();
            log.info(msg);
            if (getAdapter() != null)
                getAdapter().getMessageKeeper().add(msg);
        }
        if (StringUtils.isNotEmpty(getAuditTrailXPath())) {
            auditTrailTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getAuditTrailNamespaceDefs(), getAuditTrailXPath(), null, OutputType.TEXT, false, null);
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), OutputType.TEXT, false, null);
        }
        if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
            labelTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), OutputType.TEXT, false, null);
        }
    }
    if (StringUtils.isNotEmpty(getRetryXPath())) {
        retryTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getRetryNamespaceDefs(), getRetryXPath(), null, OutputType.TEXT, false, null);
    }
    IValidator inputValidator = getInputValidator();
    IValidator outputValidator = getOutputValidator();
    if (inputValidator != null && outputValidator == null && inputValidator instanceof IDualModeValidator) {
        outputValidator = ((IDualModeValidator) inputValidator).getResponseValidator();
        setOutputValidator(outputValidator);
    }
    if (inputValidator != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        inputValidator.registerForward(pf);
        configure(inputValidator);
    }
    if (outputValidator != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        outputValidator.registerForward(pf);
        configure(outputValidator);
    }
    if (getInputWrapper() != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        getInputWrapper().registerForward(pf);
        if (getInputWrapper() instanceof EsbSoapWrapperPipe) {
            EsbSoapWrapperPipe eswPipe = (EsbSoapWrapperPipe) getInputWrapper();
            ISender sender = getSender();
            eswPipe.retrievePhysicalDestinationFromSender(sender);
        }
        configure(getInputWrapper());
    }
    if (getOutputWrapper() != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        getOutputWrapper().registerForward(pf);
        configure(getOutputWrapper());
    }
    registerEvent(PIPE_TIMEOUT_MONITOR_EVENT);
    registerEvent(PIPE_CLEAR_TIMEOUT_MONITOR_EVENT);
    registerEvent(PIPE_EXCEPTION_MONITOR_EVENT);
}
Also used : EsbSoapWrapperPipe(nl.nn.adapterframework.extensions.esb.EsbSoapWrapperPipe) ISenderWithParameters(nl.nn.adapterframework.core.ISenderWithParameters) IDualModeValidator(nl.nn.adapterframework.core.IDualModeValidator) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) PipeForward(nl.nn.adapterframework.core.PipeForward) URL(java.net.URL) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) IValidator(nl.nn.adapterframework.core.IValidator) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) Parameter(nl.nn.adapterframework.parameters.Parameter) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 19 with ISender

use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.

the class MessageSendingPipe method propagateName.

protected void propagateName() {
    ISender sender = getSender();
    if (sender != null && StringUtils.isEmpty(sender.getName())) {
        sender.setName(getName() + "-sender");
    }
    ICorrelatedPullingListener listener = getListener();
    if (listener != null && StringUtils.isEmpty(listener.getName())) {
        listener.setName(getName() + "-replylistener");
    }
}
Also used : ICorrelatedPullingListener(nl.nn.adapterframework.core.ICorrelatedPullingListener) ISender(nl.nn.adapterframework.core.ISender)

Example 20 with ISender

use of nl.nn.adapterframework.core.ISender in project iaf by ibissource.

the class RecordXml2Sender method handleRecord.

public Object handleRecord(IPipeLineSession session, List parsedRecord, ParameterResolutionContext prc) throws Exception {
    String xml = (String) super.handleRecord(session, parsedRecord, prc);
    ISender sender = getSender();
    if (sender instanceof ISenderWithParameters) {
        ISenderWithParameters psender = (ISenderWithParameters) sender;
        return psender.sendMessage(session.getMessageId(), xml, prc);
    } else {
        return sender.sendMessage(session.getMessageId(), xml);
    }
}
Also used : ISender(nl.nn.adapterframework.core.ISender) ISenderWithParameters(nl.nn.adapterframework.core.ISenderWithParameters)

Aggregations

ISender (nl.nn.adapterframework.core.ISender)32 HashMap (java.util.HashMap)7 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)7 SenderException (nl.nn.adapterframework.core.SenderException)7 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)7 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 ISenderWithParameters (nl.nn.adapterframework.core.ISenderWithParameters)6 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)6 IOException (java.io.IOException)5 LinkedHashMap (java.util.LinkedHashMap)5 HasSender (nl.nn.adapterframework.core.HasSender)5 Serializable (java.io.Serializable)4 IPipe (nl.nn.adapterframework.core.IPipe)4 ListenerException (nl.nn.adapterframework.core.ListenerException)4 PipeLine (nl.nn.adapterframework.core.PipeLine)4 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)4 Message (nl.nn.adapterframework.stream.Message)4 IListener (nl.nn.adapterframework.core.IListener)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)3