Search in sources :

Example 1 with HasSender

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

the class ShowSecurityItems method addRegisteredAdapters.

private void addRegisteredAdapters(XmlBuilder securityItems) {
    XmlBuilder registeredAdapters = new XmlBuilder("registeredAdapters");
    securityItems.addSubElement(registeredAdapters);
    for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iAdapter;
        XmlBuilder adapterXML = new XmlBuilder("adapter");
        registeredAdapters.addSubElement(adapterXML);
        adapterXML.addAttribute("name", adapter.getName());
        Iterator recIt = adapter.getReceiverIterator();
        if (recIt.hasNext()) {
            XmlBuilder receiversXML = new XmlBuilder("receivers");
            while (recIt.hasNext()) {
                IReceiver receiver = (IReceiver) recIt.next();
                XmlBuilder receiverXML = new XmlBuilder("receiver");
                receiversXML.addSubElement(receiverXML);
                receiverXML.addAttribute("name", receiver.getName());
                if (receiver instanceof HasSender) {
                    ISender sender = ((HasSender) receiver).getSender();
                    if (sender != null) {
                        receiverXML.addAttribute("senderName", sender.getName());
                    }
                }
            }
            adapterXML.addSubElement(receiversXML);
        }
        // make list of pipes to be displayed in configuration status
        XmlBuilder pipesElem = new XmlBuilder("pipes");
        adapterXML.addSubElement(pipesElem);
        PipeLine pipeline = adapter.getPipeLine();
        for (int i = 0; i < pipeline.getPipes().size(); i++) {
            IPipe pipe = pipeline.getPipe(i);
            String pipename = pipe.getName();
            if (pipe instanceof MessageSendingPipe) {
                MessageSendingPipe msp = (MessageSendingPipe) pipe;
                XmlBuilder pipeElem = new XmlBuilder("pipe");
                pipeElem.addAttribute("name", pipename);
                ISender sender = msp.getSender();
                pipeElem.addAttribute("sender", ClassUtils.nameOf(sender));
                pipesElem.addSubElement(pipeElem);
                if (sender instanceof WebServiceSender) {
                    WebServiceSender s = (WebServiceSender) sender;
                    String certificate = s.getCertificate();
                    if (StringUtils.isNotEmpty(certificate)) {
                        XmlBuilder certElem = new XmlBuilder("certificate");
                        certElem.addAttribute("name", certificate);
                        String certificateAuthAlias = s.getCertificateAuthAlias();
                        certElem.addAttribute("authAlias", certificateAuthAlias);
                        URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                        if (certificateUrl == null) {
                            certElem.addAttribute("url", "");
                            pipeElem.addSubElement(certElem);
                            XmlBuilder infoElem = new XmlBuilder("info");
                            infoElem.setCdataValue("*** ERROR ***");
                            certElem.addSubElement(infoElem);
                        } else {
                            certElem.addAttribute("url", certificateUrl.toString());
                            pipeElem.addSubElement(certElem);
                            String certificatePassword = s.getCertificatePassword();
                            CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                            String keystoreType = s.getKeystoreType();
                            addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                        }
                    }
                } else {
                    if (sender instanceof HttpSender) {
                        HttpSender s = (HttpSender) sender;
                        String certificate = s.getCertificate();
                        if (StringUtils.isNotEmpty(certificate)) {
                            XmlBuilder certElem = new XmlBuilder("certificate");
                            certElem.addAttribute("name", certificate);
                            String certificateAuthAlias = s.getCertificateAuthAlias();
                            certElem.addAttribute("authAlias", certificateAuthAlias);
                            URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                            if (certificateUrl == null) {
                                certElem.addAttribute("url", "");
                                pipeElem.addSubElement(certElem);
                                XmlBuilder infoElem = new XmlBuilder("info");
                                infoElem.setCdataValue("*** ERROR ***");
                                certElem.addSubElement(infoElem);
                            } else {
                                certElem.addAttribute("url", certificateUrl.toString());
                                pipeElem.addSubElement(certElem);
                                String certificatePassword = s.getCertificatePassword();
                                CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                                String keystoreType = s.getKeystoreType();
                                addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                            }
                        }
                    } else {
                        if (sender instanceof FtpSender) {
                            FtpSender s = (FtpSender) sender;
                            String certificate = s.getCertificate();
                            if (StringUtils.isNotEmpty(certificate)) {
                                XmlBuilder certElem = new XmlBuilder("certificate");
                                certElem.addAttribute("name", certificate);
                                String certificateAuthAlias = s.getCertificateAuthAlias();
                                certElem.addAttribute("authAlias", certificateAuthAlias);
                                URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                                if (certificateUrl == null) {
                                    certElem.addAttribute("url", "");
                                    pipeElem.addSubElement(certElem);
                                    XmlBuilder infoElem = new XmlBuilder("info");
                                    infoElem.setCdataValue("*** ERROR ***");
                                    certElem.addSubElement(infoElem);
                                } else {
                                    certElem.addAttribute("url", certificateUrl.toString());
                                    pipeElem.addSubElement(certElem);
                                    String certificatePassword = s.getCertificatePassword();
                                    CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                                    String keystoreType = s.getCertificateType();
                                    addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) FtpSender(nl.nn.adapterframework.ftp.FtpSender) HttpSender(nl.nn.adapterframework.http.HttpSender) HasSender(nl.nn.adapterframework.core.HasSender) URL(java.net.URL) IReceiver(nl.nn.adapterframework.core.IReceiver) ISender(nl.nn.adapterframework.core.ISender) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) PipeLine(nl.nn.adapterframework.core.PipeLine) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Example 2 with HasSender

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

the class ReceiverBase method configure.

public void configure() throws ConfigurationException {
    configurationSucceeded = false;
    try {
        if (StringUtils.isEmpty(getName())) {
            if (getListener() != null) {
                setName(ClassUtils.nameOf(getListener()));
            } else {
                setName(ClassUtils.nameOf(this));
            }
        }
        eventHandler = MonitorManager.getEventHandler();
        registerEvent(RCV_CONFIGURED_MONITOR_EVENT);
        registerEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        registerEvent(RCV_STARTED_RUNNING_MONITOR_EVENT);
        registerEvent(RCV_SHUTDOWN_MONITOR_EVENT);
        registerEvent(RCV_SUSPENDED_MONITOR_EVENT);
        registerEvent(RCV_RESUMED_MONITOR_EVENT);
        registerEvent(RCV_THREAD_EXIT_MONITOR_EVENT);
        TXNEW_PROC = SpringTxManagerProxy.getTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW, getTransactionTimeout());
        // to use direct member variables).
        if (this.tmpInProcessStorage != null) {
            if (this.errorSender == null && this.errorStorage == null) {
                this.errorStorage = this.tmpInProcessStorage;
                info(getLogPrefix() + "has errorStorage in inProcessStorage, setting inProcessStorage's type to 'errorStorage'. Please update the configuration to change the inProcessStorage element to an errorStorage element, since the inProcessStorage is no longer used.");
                errorStorage.setType(JdbcTransactionalStorage.TYPE_ERRORSTORAGE);
            } else {
                info(getLogPrefix() + "has inProcessStorage defined but also has an errorStorage or errorSender. InProcessStorage is not used and can be removed from the configuration.");
            }
            // Set temporary in-process storage pointer to null
            this.tmpInProcessStorage = null;
        }
        // Do propagate-name AFTER changing the errorStorage!
        propagateName();
        if (getListener() == null) {
            throw new ConfigurationException(getLogPrefix() + "has no listener");
        }
        if (!StringUtils.isEmpty(getElementToMove()) && !StringUtils.isEmpty(getElementToMoveChain())) {
            throw new ConfigurationException("cannot have both an elementToMove and an elementToMoveChain specified");
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException(getLogPrefix() + "invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (getListener() instanceof ReceiverAware) {
            ((ReceiverAware) getListener()).setReceiver(this);
        }
        if (getListener() instanceof IPushingListener) {
            IPushingListener pl = (IPushingListener) getListener();
            pl.setHandler(this);
            pl.setExceptionListener(this);
        }
        if (getListener() instanceof IPortConnectedListener) {
            IPortConnectedListener pcl = (IPortConnectedListener) getListener();
            pcl.setReceiver(this);
        }
        if (getListener() instanceof IPullingListener) {
            setListenerContainer(createListenerContainer());
        }
        if (getListener() instanceof JdbcFacade) {
            ((JdbcFacade) getListener()).setTransacted(isTransacted());
        }
        if (getListener() instanceof JMSFacade) {
            ((JMSFacade) getListener()).setTransacted(isTransacted());
        }
        getListener().configure();
        if (getListener() instanceof HasPhysicalDestination) {
            info(getLogPrefix() + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
        }
        if (getListener() instanceof HasSender) {
            // only informational
            ISender sender = ((HasSender) getListener()).getSender();
            if (sender instanceof HasPhysicalDestination) {
                info("Listener of receiver [" + getName() + "] has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        if (getListener() instanceof ITransactionRequirements) {
            ITransactionRequirements tr = (ITransactionRequirements) getListener();
            if (tr.transactionalRequired() && !isTransacted()) {
                String msg = getLogPrefix() + "listener type [" + ClassUtils.nameOf(getListener()) + "] requires transactional processing";
                ConfigurationWarnings.getInstance().add(msg);
            // throw new ConfigurationException(msg);
            }
        }
        ISender sender = getSender();
        if (sender != null) {
            sender.configure();
            if (sender instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        ISender errorSender = getErrorSender();
        if (errorSender != null) {
            errorSender.configure();
            if (errorSender instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has errorSender to " + ((HasPhysicalDestination) errorSender).getPhysicalDestinationName());
            }
        }
        ITransactionalStorage errorStorage = getErrorStorage();
        if (errorStorage != null) {
            errorStorage.configure();
            if (errorStorage instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has errorStorage to " + ((HasPhysicalDestination) errorStorage).getPhysicalDestinationName());
            }
            registerEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
        }
        ITransactionalStorage messageLog = getMessageLog();
        if (messageLog != null) {
            messageLog.configure();
            if (messageLog instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName());
            }
            if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
                labelTp = TransformerPool.configureTransformer0(getLogPrefix(), classLoader, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), "text", false, null, isXslt2());
            }
        }
        if (isTransacted()) {
            if (errorSender == null && errorStorage == null) {
                ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                String msg = getLogPrefix() + "sets transactionAttribute=" + getTransactionAttribute() + ", but has no errorSender or errorStorage. Messages processed with errors will be lost";
                configWarnings.add(log, msg);
            } else {
            // if (errorSender!=null && !(errorSender instanceof IXAEnabled && ((IXAEnabled)errorSender).isTransacted())) {
            // warn(getLogPrefix()+"sets transacted=true, but errorSender is not. Transactional integrity is not guaranteed");
            // }
            // if (errorStorage!=null && !(errorStorage instanceof IXAEnabled && ((IXAEnabled)errorStorage).isTransacted())) {
            // warn(getLogPrefix()+"sets transacted=true, but errorStorage is not. Transactional integrity is not guaranteed");
            // }
            }
            if (getTransactionTimeout() > 0) {
                String systemTransactionTimeout = Misc.getSystemTransactionTimeout();
                if (systemTransactionTimeout != null && StringUtils.isNumeric(systemTransactionTimeout)) {
                    int stt = Integer.parseInt(systemTransactionTimeout);
                    if (getTransactionTimeout() > stt) {
                        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                        String msg = getLogPrefix() + "has a transaction timeout [" + getTransactionTimeout() + "] which exceeds the system transaction timeout [" + stt + "]";
                        configWarnings.add(log, msg);
                    }
                }
            }
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer0(getLogPrefix(), classLoader, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), "text", false, null, isXslt2());
        }
        if (adapter != null) {
            adapter.getMessageKeeper().add(getLogPrefix() + "initialization complete");
        }
        throwEvent(RCV_CONFIGURED_MONITOR_EVENT);
        configurationSucceeded = true;
    } catch (Throwable t) {
        ConfigurationException e = null;
        if (t instanceof ConfigurationException) {
            e = (ConfigurationException) t;
        } else {
            e = new ConfigurationException("Exception configuring receiver [" + getName() + "]", t);
        }
        throwEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        log.debug(getLogPrefix() + "Errors occured during configuration, setting runstate to ERROR");
        runState.setRunState(RunStateEnum.ERROR);
        throw e;
    }
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) JMSFacade(nl.nn.adapterframework.jms.JMSFacade) HasSender(nl.nn.adapterframework.core.HasSender) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) IPullingListener(nl.nn.adapterframework.core.IPullingListener) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) ITransactionRequirements(nl.nn.adapterframework.core.ITransactionRequirements) IPushingListener(nl.nn.adapterframework.core.IPushingListener) IPortConnectedListener(nl.nn.adapterframework.core.IPortConnectedListener) JdbcFacade(nl.nn.adapterframework.jdbc.JdbcFacade) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 3 with HasSender

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

the class ShowConfigurationStatus method mapAdapterReceivers.

private ArrayList<Object> mapAdapterReceivers(Adapter adapter, boolean showPendingMsgCount) {
    ArrayList<Object> receivers = new ArrayList<Object>();
    Iterator<?> recIt = adapter.getReceiverIterator();
    if (recIt.hasNext()) {
        while (recIt.hasNext()) {
            IReceiver receiver = (IReceiver) recIt.next();
            Map<String, Object> receiverInfo = new HashMap<String, Object>();
            RunStateEnum receiverRunState = receiver.getRunState();
            receiverInfo.put("started", receiverRunState.equals(RunStateEnum.STARTED));
            receiverInfo.put("state", receiverRunState.toString().toLowerCase().replace("*", ""));
            receiverInfo.put("name", receiver.getName());
            receiverInfo.put("class", ClassUtils.nameOf(receiver));
            Map<String, Object> messages = new HashMap<String, Object>(3);
            messages.put("received", receiver.getMessagesReceived());
            messages.put("retried", receiver.getMessagesRetried());
            messages.put("rejected", receiver.getMessagesRejected());
            receiverInfo.put("messages", messages);
            ISender sender = null;
            if (receiver instanceof ReceiverBase) {
                ReceiverBase rb = (ReceiverBase) receiver;
                IListener listener = rb.getListener();
                receiverInfo.put("listenerClass", ClassUtils.nameOf(listener));
                if (listener instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) rb.getListener()).getPhysicalDestinationName();
                    receiverInfo.put("listenerDestination", pd);
                }
                if (listener instanceof HasSender) {
                    sender = ((HasSender) listener).getSender();
                }
                // receiverInfo.put("hasInprocessStorage", ""+(rb.getInProcessStorage()!=null));
                ITransactionalStorage ts;
                ts = rb.getErrorStorage();
                receiverInfo.put("hasErrorStorage", (ts != null));
                if (ts != null) {
                    try {
                        if (showCountErrorStore) {
                            receiverInfo.put("errorStorageCount", ts.getMessageCount());
                        } else {
                            receiverInfo.put("errorStorageCount", "?");
                        }
                    } catch (Exception e) {
                        log.warn(e);
                        receiverInfo.put("errorStorageCount", "error");
                    }
                }
                ts = rb.getMessageLog();
                receiverInfo.put("hasMessageLog", (ts != null));
                if (ts != null) {
                    try {
                        if (showCountMessageLog) {
                            receiverInfo.put("messageLogCount", ts.getMessageCount());
                        } else {
                            receiverInfo.put("messageLogCount", "?");
                        }
                    } catch (Exception e) {
                        log.warn(e);
                        receiverInfo.put("messageLogCount", "error");
                    }
                }
                boolean isRestListener = (listener instanceof RestListener);
                receiverInfo.put("isRestListener", isRestListener);
                if (isRestListener) {
                    RestListener rl = (RestListener) listener;
                    receiverInfo.put("restUriPattern", rl.getRestUriPattern());
                    receiverInfo.put("isView", (rl.isView() == null ? false : rl.isView()));
                }
                if ((listener instanceof JmsListenerBase) && showPendingMsgCount) {
                    JmsListenerBase jlb = (JmsListenerBase) listener;
                    JmsMessageBrowser jmsBrowser;
                    if (StringUtils.isEmpty(jlb.getMessageSelector())) {
                        jmsBrowser = new JmsMessageBrowser();
                    } else {
                        jmsBrowser = new JmsMessageBrowser(jlb.getMessageSelector());
                    }
                    jmsBrowser.setName("MessageBrowser_" + jlb.getName());
                    jmsBrowser.setJmsRealm(jlb.getJmsRealName());
                    jmsBrowser.setDestinationName(jlb.getDestinationName());
                    jmsBrowser.setDestinationType(jlb.getDestinationType());
                    String numMsgs;
                    try {
                        int messageCount = jmsBrowser.getMessageCount();
                        numMsgs = String.valueOf(messageCount);
                    } catch (Throwable t) {
                        log.warn(t);
                        numMsgs = "?";
                    }
                    receiverInfo.put("pendingMessagesCount", numMsgs);
                }
                boolean isEsbJmsFFListener = false;
                if (listener instanceof EsbJmsListener) {
                    EsbJmsListener ejl = (EsbJmsListener) listener;
                    if (ejl.getMessageProtocol().equalsIgnoreCase("FF")) {
                        isEsbJmsFFListener = true;
                    }
                    if (showPendingMsgCount) {
                        String esbNumMsgs = EsbUtils.getQueueMessageCount(ejl);
                        if (esbNumMsgs == null) {
                            esbNumMsgs = "?";
                        }
                        receiverInfo.put("esbPendingMessagesCount", esbNumMsgs);
                    }
                }
                receiverInfo.put("isEsbJmsFFListener", isEsbJmsFFListener);
            }
            if (receiver instanceof HasSender) {
                ISender rsender = ((HasSender) receiver).getSender();
                if (rsender != null) {
                    // this sender has preference, but avoid overwriting listeners sender with null
                    sender = rsender;
                }
            }
            if (sender != null) {
                receiverInfo.put("senderName", sender.getName());
                receiverInfo.put("senderClass", ClassUtils.nameOf(sender));
                if (sender instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) sender).getPhysicalDestinationName();
                    receiverInfo.put("senderDestination", pd);
                }
            }
            if (receiver instanceof IThreadCountControllable) {
                IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                if (tcc.isThreadCountReadable()) {
                    receiverInfo.put("threadCount", tcc.getCurrentThreadCount());
                    receiverInfo.put("maxThreadCount", tcc.getMaxThreadCount());
                }
                if (tcc.isThreadCountControllable()) {
                    receiverInfo.put("threadCountControllable", "true");
                }
            }
            receivers.add(receiverInfo);
        }
    }
    return receivers;
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) HasSender(nl.nn.adapterframework.core.HasSender) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) RestListener(nl.nn.adapterframework.http.RestListener) JmsListenerBase(nl.nn.adapterframework.jms.JmsListenerBase) IReceiver(nl.nn.adapterframework.core.IReceiver) JmsMessageBrowser(nl.nn.adapterframework.jms.JmsMessageBrowser) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) ISender(nl.nn.adapterframework.core.ISender) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 4 with HasSender

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

the class ShowConfigurationStatus method toReceiversXml.

private XmlBuilder toReceiversXml(Configuration configurationSelected, Adapter adapter, ShowConfigurationStatusManager showConfigurationStatusManager, ShowConfigurationStatusAdapterManager showConfigurationStatusAdapterManager) {
    Iterator recIt = adapter.getReceiverIterator();
    if (!recIt.hasNext()) {
        return null;
    }
    XmlBuilder receiversXML = new XmlBuilder("receivers");
    while (recIt.hasNext()) {
        IReceiver receiver = (IReceiver) recIt.next();
        XmlBuilder receiverXML = new XmlBuilder("receiver");
        receiversXML.addSubElement(receiverXML);
        RunStateEnum receiverRunState = receiver.getRunState();
        receiverXML.addAttribute("isStarted", "" + (receiverRunState.equals(RunStateEnum.STARTED)));
        receiverXML.addAttribute("state", receiverRunState.toString());
        if (receiverRunState.equals(RunStateEnum.STARTING)) {
            showConfigurationStatusManager.countReceiverStateStarting++;
        } else if ((receiverRunState.equals(RunStateEnum.STARTED))) {
            showConfigurationStatusManager.countReceiverStateStarted++;
        } else if ((receiverRunState.equals(RunStateEnum.STOPPING))) {
            showConfigurationStatusManager.countReceiverStateStopping++;
        } else if ((receiverRunState.equals(RunStateEnum.STOPPED))) {
            showConfigurationStatusManager.countReceiverStateStopped++;
        } else if ((receiverRunState.equals(RunStateEnum.ERROR))) {
            showConfigurationStatusManager.countReceiverStateError++;
        }
        if (!showConfigurationStatusAdapterManager.stateAlert && !(receiverRunState.equals(RunStateEnum.STARTED))) {
            showConfigurationStatusAdapterManager.stateAlert = true;
        }
        receiverXML.addAttribute("name", receiver.getName());
        receiverXML.addAttribute("class", ClassUtils.nameOf(receiver));
        receiverXML.addAttribute("messagesReceived", "" + receiver.getMessagesReceived());
        receiverXML.addAttribute("messagesRetried", "" + receiver.getMessagesRetried());
        receiverXML.addAttribute("messagesRejected", "" + receiver.getMessagesRejected());
        if (configurationSelected != null) {
            ISender sender = null;
            if (receiver instanceof ReceiverBase) {
                ReceiverBase rb = (ReceiverBase) receiver;
                IListener listener = rb.getListener();
                receiverXML.addAttribute("listenerClass", ClassUtils.nameOf(listener));
                if (listener instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) rb.getListener()).getPhysicalDestinationName();
                    receiverXML.addAttribute("listenerDestination", pd);
                }
                if (listener instanceof HasSender) {
                    sender = ((HasSender) listener).getSender();
                }
                ITransactionalStorage ts;
                ts = rb.getErrorStorage();
                receiverXML.addAttribute("hasErrorStorage", "" + (ts != null));
                if (ts != null) {
                    try {
                        if (SHOW_COUNT_ERRORSTORE) {
                            receiverXML.addAttribute("errorStorageCount", ts.getMessageCount());
                        } else {
                            receiverXML.addAttribute("errorStorageCount", "?");
                        }
                    } catch (Exception e) {
                        log.warn(e);
                        receiverXML.addAttribute("errorStorageCount", "error");
                    }
                }
                ts = rb.getMessageLog();
                receiverXML.addAttribute("hasMessageLog", "" + (ts != null));
                if (ts != null) {
                    try {
                        if (SHOW_COUNT_MESSAGELOG) {
                            receiverXML.addAttribute("messageLogCount", ts.getMessageCount());
                        } else {
                            receiverXML.addAttribute("messageLogCount", "?");
                        }
                    } catch (Exception e) {
                        log.warn(e);
                        receiverXML.addAttribute("messageLogCount", "error");
                    }
                }
                boolean isRestListener = (listener instanceof RestListener);
                receiverXML.addAttribute("isRestListener", isRestListener);
                if (isRestListener) {
                    RestListener rl = (RestListener) listener;
                    receiverXML.addAttribute("restUriPattern", rl.getRestUriPattern());
                    receiverXML.addAttribute("isView", (rl.isView() == null ? false : rl.isView()));
                    String matchingPattern = RestServiceDispatcher.getInstance().findMatchingPattern("/" + rl.getUriPattern());
                    receiverXML.addAttribute("isAvailable", (matchingPattern == null ? false : true));
                }
                if (showConfigurationStatusManager.count) {
                    if (listener instanceof JmsListenerBase) {
                        JmsListenerBase jlb = (JmsListenerBase) listener;
                        JmsMessageBrowser jmsBrowser;
                        if (StringUtils.isEmpty(jlb.getMessageSelector())) {
                            jmsBrowser = new JmsMessageBrowser();
                        } else {
                            jmsBrowser = new JmsMessageBrowser(jlb.getMessageSelector());
                        }
                        jmsBrowser.setName("MessageBrowser_" + jlb.getName());
                        jmsBrowser.setJmsRealm(jlb.getJmsRealName());
                        jmsBrowser.setDestinationName(jlb.getDestinationName());
                        jmsBrowser.setDestinationType(jlb.getDestinationType());
                        String numMsgs;
                        try {
                            int messageCount = jmsBrowser.getMessageCount();
                            numMsgs = String.valueOf(messageCount);
                        } catch (Throwable t) {
                            log.warn(t);
                            numMsgs = "?";
                        }
                        receiverXML.addAttribute("pendingMessagesCount", numMsgs);
                    }
                }
                boolean isEsbJmsFFListener = false;
                if (listener instanceof EsbJmsListener) {
                    EsbJmsListener ejl = (EsbJmsListener) listener;
                    if ("FF".equalsIgnoreCase(ejl.getMessageProtocol())) {
                        isEsbJmsFFListener = true;
                    }
                    if (showConfigurationStatusManager.count) {
                        String esbNumMsgs = EsbUtils.getQueueMessageCount(ejl);
                        if (esbNumMsgs == null) {
                            esbNumMsgs = "?";
                        }
                        receiverXML.addAttribute("esbPendingMessagesCount", esbNumMsgs);
                    }
                }
                receiverXML.addAttribute("isEsbJmsFFListener", isEsbJmsFFListener);
            }
            if (receiver instanceof HasSender) {
                ISender rsender = ((HasSender) receiver).getSender();
                if (rsender != null) {
                    // this sender has preference, but
                    // avoid overwriting listeners
                    // sender with null
                    sender = rsender;
                }
            }
            if (sender != null) {
                receiverXML.addAttribute("senderName", sender.getName());
                receiverXML.addAttribute("senderClass", ClassUtils.nameOf(sender));
                if (sender instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) sender).getPhysicalDestinationName();
                    receiverXML.addAttribute("senderDestination", pd);
                }
            }
            if (receiver instanceof IThreadCountControllable) {
                IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                if (tcc.isThreadCountReadable()) {
                    receiverXML.addAttribute("threadCount", tcc.getCurrentThreadCount() + "");
                    receiverXML.addAttribute("maxThreadCount", tcc.getMaxThreadCount() + "");
                }
                if (tcc.isThreadCountControllable()) {
                    receiverXML.addAttribute("threadCountControllable", "true");
                }
            }
        }
    }
    return receiversXML;
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) HasSender(nl.nn.adapterframework.core.HasSender) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) RestListener(nl.nn.adapterframework.http.RestListener) JmsListenerBase(nl.nn.adapterframework.jms.JmsListenerBase) IReceiver(nl.nn.adapterframework.core.IReceiver) JmsMessageBrowser(nl.nn.adapterframework.jms.JmsMessageBrowser) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) ISender(nl.nn.adapterframework.core.ISender) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Aggregations

HasSender (nl.nn.adapterframework.core.HasSender)4 ISender (nl.nn.adapterframework.core.ISender)4 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)3 IReceiver (nl.nn.adapterframework.core.IReceiver)3 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)3 Iterator (java.util.Iterator)2 IListener (nl.nn.adapterframework.core.IListener)2 IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)2 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)2 RestListener (nl.nn.adapterframework.http.RestListener)2 JmsListenerBase (nl.nn.adapterframework.jms.JmsListenerBase)2 JmsMessageBrowser (nl.nn.adapterframework.jms.JmsMessageBrowser)2 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)2 RunStateEnum (nl.nn.adapterframework.util.RunStateEnum)2 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1