Search in sources :

Example 11 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class EsbJmsListenerChecker method doCheck.

public static void doCheck(IbisManager ibisManager, PlatformTransactionManager txManager, String logPrefix) {
    long idleTimeout = AppConstants.getInstance().getInt("check.esbJmsListeners.idleTimeout", 300) * 1000;
    for (Configuration configuration : ibisManager.getConfigurations()) {
        String msg;
        List<String> jmsRealmNames = new ArrayList<String>();
        for (IAdapter adapter : configuration.getRegisteredAdapters()) {
            if (adapter instanceof Adapter) {
                for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                    IReceiver receiver = (IReceiver) receiverIt.next();
                    if (receiver instanceof ReceiverBase) {
                        ReceiverBase rb = (ReceiverBase) receiver;
                        if (rb.getRunState().equals(RunStateEnum.STARTED)) {
                            // if (true) {
                            long lastMessageDate = rb.getLastMessageDate();
                            if (lastMessageDate == 0 || System.currentTimeMillis() - lastMessageDate > idleTimeout) {
                                IListener listener = rb.getListener();
                                if (listener instanceof EsbJmsListener) {
                                    EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
                                    if (esbJmsListener.getMessageProtocol().equals("FF")) {
                                        Object managedConnectionFactory = null;
                                        try {
                                            managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
                                            if (managedConnectionFactory == null) {
                                                msg = logPrefix + "could not get managed connection factory";
                                                warn(adapter, msg);
                                            } else {
                                                String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
                                                String providerURL = getProviderURL(managedConnectionFactory);
                                                String authDataAlias = getAuthDataAlias(managedConnectionFactory);
                                                String username = null;
                                                String password = null;
                                                msg = logPrefix + "found esbJmsListener [" + esbJmsListener.getName() + "] with managedConnectionFactoryClassname [" + managedConnectionFactory.getClass().getName() + "] having contextFactoryClassname [" + contextFactoryClassname + "] providerURL [" + providerURL + "] authDataAlias [" + authDataAlias + "]";
                                                if (authDataAlias != null) {
                                                    CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
                                                    username = cf.getUsername();
                                                    password = cf.getPassword();
                                                }
                                                if (contextFactoryClassname != null && contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
                                                    log.debug(msg + ", checking...");
                                                    long age = getTibcoQueueFirstMessageAge(providerURL, authDataAlias, username, password, esbJmsListener.getPhysicalDestinationShortName(), esbJmsListener.getMessageSelector());
                                                    if (age > idleTimeout) {
                                                        msg = logPrefix + "most probably esbJmsListener [" + esbJmsListener.getName() + "] has lost connection with queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                                        warn(adapter, msg);
                                                    }
                                                } else {
                                                    log.debug(msg + ", ignoring...");
                                                }
                                            }
                                        } catch (Throwable t) {
                                            msg = logPrefix + "exception on checking queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                            warn(adapter, msg, t);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IReceiver(nl.nn.adapterframework.core.IReceiver) Iterator(java.util.Iterator) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 12 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class PipeLine method configure.

/**
 * Configures the pipes of this Pipeline and does some basic checks. It also
 * registers the <code>PipeLineSession</code> object at the pipes.
 * @see IPipe
 */
public void configure() throws ConfigurationException {
    INamedObject owner = getOwner();
    IAdapter adapter = null;
    if (owner instanceof IAdapter) {
        adapter = (IAdapter) owner;
    }
    if (cache != null) {
        cache.configure(owner.getName() + "-Pipeline");
    }
    for (int i = 0; i < pipes.size(); i++) {
        IPipe pipe = getPipe(i);
        log.debug("Pipeline of [" + owner.getName() + "] configuring Pipe [" + pipe.getName() + "]");
        // forward is defined, it is not overwritten by the globals
        for (String gfName : globalForwards.keySet()) {
            PipeForward pipeForward = globalForwards.get(gfName);
            pipe.registerForward(pipeForward);
        }
        if (pipe instanceof FixedForwardPipe) {
            FixedForwardPipe ffpipe = (FixedForwardPipe) pipe;
            if (ffpipe.findForward("success") == null) {
                int i2 = i + 1;
                if (i2 < pipes.size()) {
                    String nextPipeName = getPipe(i2).getName();
                    PipeForward pf = new PipeForward();
                    pf.setName("success");
                    pf.setPath(nextPipeName);
                    pipe.registerForward(pf);
                } else {
                    PipeLineExit plexit = findExitByState("success");
                    if (plexit != null) {
                        PipeForward pf = new PipeForward();
                        pf.setName("success");
                        pf.setPath(plexit.getPath());
                        pipe.registerForward(pf);
                    }
                }
            }
        }
        configure(pipe);
    }
    if (pipeLineExits.size() < 1) {
        throw new ConfigurationException("no PipeLine Exits specified");
    }
    if (this.firstPipe == null) {
        throw new ConfigurationException("no firstPipe defined");
    }
    if (getPipe(firstPipe) == null) {
        throw new ConfigurationException("no pipe found for firstPipe [" + firstPipe + "]");
    }
    IPipe inputValidator = getInputValidator();
    IPipe outputValidator = getOutputValidator();
    if (inputValidator != null && outputValidator == null && inputValidator instanceof IDualModeValidator) {
        outputValidator = ((IDualModeValidator) inputValidator).getResponseValidator();
        setOutputValidator(outputValidator);
    }
    if (inputValidator != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring InputValidator");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        inputValidator.registerForward(pf);
        inputValidator.setName(INPUT_VALIDATOR_NAME);
        configure(inputValidator);
    }
    if (outputValidator != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring OutputValidator");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        outputValidator.registerForward(pf);
        outputValidator.setName(OUTPUT_VALIDATOR_NAME);
        configure(outputValidator);
    }
    if (getInputWrapper() != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring InputWrapper");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        getInputWrapper().registerForward(pf);
        getInputWrapper().setName(INPUT_WRAPPER_NAME);
        configure(getInputWrapper());
    }
    if (getOutputWrapper() != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring OutputWrapper");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        if (getOutputWrapper() instanceof AbstractPipe && adapter instanceof Adapter) {
            ((AbstractPipe) getOutputWrapper()).setRecoverAdapter(((Adapter) adapter).isRecover());
        }
        getOutputWrapper().registerForward(pf);
        getOutputWrapper().setName(OUTPUT_WRAPPER_NAME);
        if (getOutputWrapper() instanceof EsbSoapWrapperPipe) {
            EsbSoapWrapperPipe eswPipe = (EsbSoapWrapperPipe) getOutputWrapper();
            boolean stop = false;
            Iterator<IReceiver> recIt = adapter.getReceiverIterator();
            if (recIt.hasNext()) {
                while (recIt.hasNext() && !stop) {
                    IReceiver receiver = recIt.next();
                    if (receiver instanceof ReceiverBase) {
                        ReceiverBase rb = (ReceiverBase) receiver;
                        IListener listener = rb.getListener();
                        try {
                            if (eswPipe.retrievePhysicalDestinationFromListener(listener)) {
                                stop = true;
                            }
                        } catch (JmsException e) {
                            throw new ConfigurationException(e);
                        }
                    }
                }
            }
        }
        configure(getOutputWrapper());
    }
    requestSizeStats = new SizeStatisticsKeeper("- pipeline in");
    if (isTransacted() && 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 = "Pipeline of [" + owner.getName() + "] has a transaction timeout [" + getTransactionTimeout() + "] which exceeds the system transaction timeout [" + stt + "]";
                configWarnings.add(log, msg);
            }
        }
    }
    int txOption = this.getTransactionAttributeNum();
    if (log.isDebugEnabled())
        log.debug("creating TransactionDefinition for transactionAttribute [" + getTransactionAttribute() + "], timeout [" + getTransactionTimeout() + "]");
    txDef = SpringTxManagerProxy.getTransactionDefinition(txOption, getTransactionTimeout());
    log.debug("Pipeline of [" + owner.getName() + "] successfully configured");
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) EsbSoapWrapperPipe(nl.nn.adapterframework.extensions.esb.EsbSoapWrapperPipe) ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) JmsException(nl.nn.adapterframework.jms.JmsException) SizeStatisticsKeeper(nl.nn.adapterframework.statistics.SizeStatisticsKeeper) ICacheAdapter(nl.nn.adapterframework.cache.ICacheAdapter) AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FixedForwardPipe(nl.nn.adapterframework.pipes.FixedForwardPipe)

Example 13 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class DefaultIbisManager method unload.

private void unload(Configuration configuration) {
    configuration.setUnloadInProgressOrDone(true);
    while (configuration.getStartAdapterThreads().size() > 0) {
        log.debug("Waiting for start threads to end: " + configuration.getStartAdapterThreads());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.warn("Interrupted waiting for start threads to end", e);
        }
    }
    stopAdapters(configuration);
    while (configuration.getStopAdapterThreads().size() > 0) {
        log.debug("Waiting for stop threads to end: " + configuration.getStopAdapterThreads());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.warn("Interrupted waiting for stop threads to end", e);
        }
    }
    // destroy all jmsContainers
    for (int i = 0; i < configuration.getRegisteredAdapters().size(); i++) {
        IAdapter adapter = configuration.getRegisteredAdapter(i);
        Iterator recIt = adapter.getReceiverIterator();
        if (recIt.hasNext()) {
            while (recIt.hasNext()) {
                IReceiver receiver = (IReceiver) recIt.next();
                if (receiver instanceof ReceiverBase) {
                    ReceiverBase rb = (ReceiverBase) receiver;
                    IListener listener = rb.getListener();
                    if (listener instanceof PushingJmsListener) {
                        PushingJmsListener pjl = (PushingJmsListener) listener;
                        pjl.destroy();
                    }
                }
            }
        }
    }
    while (configuration.getRegisteredAdapters().size() > 0) {
        IAdapter adapter = configuration.getRegisteredAdapter(0);
        AdapterService adapterService = configuration.getAdapterService();
        adapterService.unRegisterAdapter(adapter);
    }
    configurations.remove(configuration);
}
Also used : AdapterService(nl.nn.adapterframework.configuration.AdapterService) IReceiver(nl.nn.adapterframework.core.IReceiver) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) Iterator(java.util.Iterator) PushingJmsListener(nl.nn.adapterframework.jms.PushingJmsListener) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 14 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class IbisSoapServlet method listRestServices.

protected void listRestServices(HttpServletRequest req, Writer w) throws IOException {
    w.write("<h2>Available REST services:</h2>");
    w.write("<ol>");
    int count = 0;
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) a;
        Iterator recIt = adapter.getReceiverIterator();
        while (recIt.hasNext()) {
            IReceiver receiver = (IReceiver) recIt.next();
            if (receiver instanceof ReceiverBase) {
                ReceiverBase rb = (ReceiverBase) receiver;
                IListener listener = rb.getListener();
                if (listener instanceof RestListener) {
                    RestListener rl = (RestListener) listener;
                    if (rl.isView()) {
                        count++;
                        w.write("<li>");
                        w.write("<a href=../" + rl.getRestUriPattern() + ">" + rb.getName() + "</a>");
                        w.write("</li>");
                    }
                }
            }
        }
    }
    w.write("</ol>");
    if (count == 0) {
        w.write("No rest listeners found");
    }
}
Also used : RestListener(nl.nn.adapterframework.http.RestListener) IReceiver(nl.nn.adapterframework.core.IReceiver) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) Iterator(java.util.Iterator) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 15 with ReceiverBase

use of nl.nn.adapterframework.receivers.ReceiverBase in project iaf by ibissource.

the class WsdlUtils method getListeners.

public static Collection<IListener> getListeners(IAdapter a) {
    List<IListener> result = new ArrayList<IListener>();
    Iterator j = a.getReceiverIterator();
    while (j.hasNext()) {
        Object o = j.next();
        if (o instanceof ReceiverBase) {
            ReceiverBase r = (ReceiverBase) o;
            result.add(r.getListener());
        }
    }
    return result;
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Aggregations

ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)19 IAdapter (nl.nn.adapterframework.core.IAdapter)11 Iterator (java.util.Iterator)10 Adapter (nl.nn.adapterframework.core.Adapter)10 IListener (nl.nn.adapterframework.core.IListener)10 IReceiver (nl.nn.adapterframework.core.IReceiver)10 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 RestListener (nl.nn.adapterframework.http.RestListener)5 Configuration (nl.nn.adapterframework.configuration.Configuration)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)3 IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)3 PipeLine (nl.nn.adapterframework.core.PipeLine)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)3 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)3