Search in sources :

Example 26 with ISender

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

the class JmsListenerBase method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    if (isSoap()) {
        // ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
        // String msg = getLogPrefix()+"the use of attribute soap=true has been deprecated. Please change to SoapWrapperPipe";
        // configWarnings.add(log, msg);
        soapWrapper = SoapWrapper.getInstance();
    }
    ISender sender = getSender();
    if (sender != null) {
        sender.configure();
    }
    configurexPathLogging();
    if (paramList != null) {
        paramList.configure();
    }
}
Also used : ISender(nl.nn.adapterframework.core.ISender)

Example 27 with ISender

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

the class ShowConfigurationStatus method mapAdapterReceivers.

private ArrayList<Object> mapAdapterReceivers(Adapter adapter, boolean showPendingMsgCount) {
    ArrayList<Object> receivers = new ArrayList<Object>();
    for (Receiver<?> receiver : adapter.getReceivers()) {
        Map<String, Object> receiverInfo = new HashMap<>();
        RunState receiverRunState = receiver.getRunState();
        receiverInfo.put("name", receiver.getName());
        receiverInfo.put("state", receiverRunState.name().toLowerCase());
        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);
        Set<ProcessState> knownStates = receiver.knownProcessStates();
        Map<ProcessState, Object> tsInfo = new LinkedHashMap<ProcessState, Object>();
        for (ProcessState state : knownStates) {
            IMessageBrowser<?> ts = receiver.getMessageBrowser(state);
            if (ts != null) {
                Map<String, Object> info = new HashMap<>();
                try {
                    info.put("numberOfMessages", ts.getMessageCount());
                } catch (Exception e) {
                    log.warn("Cannot determine number of messages in process state [" + state + "]", e);
                    info.put("numberOfMessages", "error");
                }
                info.put("name", state.getName());
                tsInfo.put(state, info);
            }
        }
        receiverInfo.put("transactionalStores", tsInfo);
        ISender sender = null;
        IListener<?> listener = receiver.getListener();
        if (listener != null) {
            Map<String, Object> listenerInfo = new HashMap<String, Object>();
            listenerInfo.put("name", listener.getName());
            listenerInfo.put("class", ClassUtils.nameOf(listener));
            if (listener instanceof HasPhysicalDestination) {
                String pd = ((HasPhysicalDestination) receiver.getListener()).getPhysicalDestinationName();
                listenerInfo.put("destination", pd);
            }
            if (listener instanceof HasSender) {
                sender = ((HasSender) listener).getSender();
            }
            boolean isRestListener = (listener instanceof RestListener);
            listenerInfo.put("isRestListener", isRestListener);
            if (isRestListener) {
                RestListener rl = (RestListener) listener;
                listenerInfo.put("restUriPattern", rl.getRestUriPattern());
                listenerInfo.put("isView", rl.isView());
            }
            receiverInfo.put("listener", listenerInfo);
        }
        if ((listener instanceof JmsListenerBase) && showPendingMsgCount) {
            JmsListenerBase jlb = (JmsListenerBase) listener;
            JmsBrowser<javax.jms.Message> jmsBrowser;
            if (StringUtils.isEmpty(jlb.getMessageSelector())) {
                jmsBrowser = new JmsBrowser<>();
            } else {
                jmsBrowser = new JmsBrowser<>(jlb.getMessageSelector());
            }
            jmsBrowser.setName("MessageBrowser_" + jlb.getName());
            jmsBrowser.setJmsRealm(jlb.getJmsRealmName());
            jmsBrowser.setDestinationName(jlb.getDestinationName());
            jmsBrowser.setDestinationType(jlb.getDestinationType());
            String numMsgs;
            try {
                int messageCount = jmsBrowser.getMessageCount();
                numMsgs = String.valueOf(messageCount);
            } catch (Throwable t) {
                log.warn("Cannot determine number of messages in errorstore [" + jmsBrowser.getName() + "]", t);
                numMsgs = "?";
            }
            receiverInfo.put("pendingMessagesCount", numMsgs);
        }
        boolean isEsbJmsFFListener = false;
        if (listener instanceof EsbJmsListener) {
            EsbJmsListener ejl = (EsbJmsListener) listener;
            if (ejl.getMessageProtocol() != null) {
                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);
        ISender rsender = 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.isThreadCountReadable()) {
            receiverInfo.put("threadCount", receiver.getCurrentThreadCount());
            receiverInfo.put("maxThreadCount", receiver.getMaxThreadCount());
        }
        if (receiver.isThreadCountControllable()) {
            receiverInfo.put("threadCountControllable", "true");
        }
        receivers.add(receiverInfo);
    }
    return receivers;
}
Also used : MessageKeeperMessage(nl.nn.adapterframework.util.MessageKeeperMessage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ISender(nl.nn.adapterframework.core.ISender) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) HasSender(nl.nn.adapterframework.core.HasSender) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) RunState(nl.nn.adapterframework.util.RunState) ProcessState(nl.nn.adapterframework.core.ProcessState) RestListener(nl.nn.adapterframework.http.RestListener) JmsListenerBase(nl.nn.adapterframework.jms.JmsListenerBase) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 28 with ISender

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

the class SenderSeries method doSendMessage.

@Override
public Message doSendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    String correlationID = session == null ? null : session.getMessageId();
    long t1 = System.currentTimeMillis();
    for (ISender sender : getSenders()) {
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + "sending correlationID [" + correlationID + "] message [" + message + "] to sender [" + sender.getName() + "]");
        message = sender.sendMessage(message, session);
        long t2 = System.currentTimeMillis();
        StatisticsKeeper sk = getStatisticsKeeper(sender);
        sk.addValue(t2 - t1);
        t1 = t2;
    }
    return message;
}
Also used : ISender(nl.nn.adapterframework.core.ISender) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper)

Example 29 with ISender

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

the class JavascriptSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException {
    Object jsResult = "";
    int numberOfParameters = 0;
    JavascriptEngine<?> jsInstance = engine.create();
    try {
        jsInstance.startRuntime();
    } catch (JavascriptException e) {
        throw new SenderException("unable to start Javascript engine", e);
    }
    // Create a Parameter Value List
    ParameterValueList pvl = null;
    try {
        if (getParameterList() != null) {
            pvl = getParameterList().getValues(message, session);
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + " exception extracting parameters", e);
    }
    if (pvl != null) {
        numberOfParameters = pvl.size();
    }
    // This array will contain the parameters given in the configuration
    Object[] jsParameters = new Object[numberOfParameters];
    for (int i = 0; i < numberOfParameters; i++) {
        ParameterValue pv = pvl.getParameterValue(i);
        Object value = pv.getValue();
        try {
            jsParameters[i] = value instanceof Message ? ((Message) value).asString() : value;
        } catch (IOException e) {
            throw new SenderException(getLogPrefix(), e);
        }
    }
    for (ISender sender : getSenders()) {
        jsInstance.registerCallback(sender, session);
    }
    try {
        // Compile the given Javascript and execute the given Javascript function
        jsInstance.executeScript(adaptES6Literals(fileInput));
        jsResult = jsInstance.executeFunction(jsFunctionName, jsParameters);
    } catch (JavascriptException e) {
        throw new SenderException("unable to execute script/function", e);
    } finally {
        jsInstance.closeRuntime();
    }
    // Pass jsResult, the result of the Javascript function.
    // It is recommended to have the result of the Javascript function be of type String, which will be the output of the sender
    String result = String.valueOf(jsResult);
    if (StringUtils.isEmpty(result) || "null".equals(result) || "undefined".equals(result)) {
        return Message.nullMessage();
    }
    return new Message(result);
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) Message(nl.nn.adapterframework.stream.Message) IOException(java.io.IOException) ISender(nl.nn.adapterframework.core.ISender) JavascriptException(nl.nn.adapterframework.extensions.javascript.JavascriptException) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 30 with ISender

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

the class Receiver method propagateName.

protected void propagateName() {
    IListener<M> listener = getListener();
    if (listener != null && StringUtils.isEmpty(listener.getName())) {
        listener.setName("listener of [" + getName() + "]");
    }
    ISender errorSender = getErrorSender();
    if (errorSender != null) {
        errorSender.setName("errorSender of [" + getName() + "]");
    }
    ITransactionalStorage<Serializable> errorStorage = getErrorStorage();
    if (errorStorage != null) {
        errorStorage.setName("errorStorage of [" + getName() + "]");
    }
    ISender answerSender = getSender();
    if (answerSender != null) {
        answerSender.setName("answerSender of [" + getName() + "]");
    }
}
Also used : Serializable(java.io.Serializable) ISender(nl.nn.adapterframework.core.ISender)

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