Search in sources :

Example 11 with JavaListener

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

the class IbisLocalSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String result = null;
    HashMap context = null;
    if (paramList != null) {
        try {
            context = (HashMap) prc.getValueMap(paramList);
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
        }
    } else {
        if (StringUtils.isNotEmpty(getReturnedSessionKeys())) {
            context = new HashMap();
        }
    }
    if (StringUtils.isNotEmpty(getServiceName())) {
        try {
            if (isIsolated()) {
                if (isSynchronous()) {
                    log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in separate Thread");
                    result = isolatedServiceCaller.callServiceIsolated(getServiceName(), correlationID, message, context, false);
                } else {
                    log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in asynchronously");
                    isolatedServiceCaller.callServiceAsynchronous(getServiceName(), correlationID, message, context, false);
                    result = message;
                }
            } else {
                log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in same Thread");
                result = ServiceDispatcher.getInstance().dispatchRequest(getServiceName(), correlationID, message, context);
            }
        } catch (ListenerException e) {
            if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
                throw new TimeOutException(getLogPrefix() + "timeout calling service [" + getServiceName() + "]", e);
            } else {
                throw new SenderException(getLogPrefix() + "exception calling service [" + getServiceName() + "]", e);
            }
        } finally {
            if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
                log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
            }
            if (prc != null) {
                Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
            }
        }
    } else {
        String javaListener;
        if (StringUtils.isNotEmpty(getJavaListenerSessionKey())) {
            javaListener = (String) prc.getSession().get(getJavaListenerSessionKey());
        } else {
            javaListener = getJavaListener();
        }
        try {
            JavaListener listener = JavaListener.getListener(javaListener);
            if (listener == null) {
                String msg = "could not find JavaListener [" + javaListener + "]";
                if (isThrowJavaListenerNotFoundException()) {
                    throw new SenderException(msg);
                } else {
                    log.info(getLogPrefix() + msg);
                    return "<error>" + msg + "</error>";
                }
            }
            if (isIsolated()) {
                if (isSynchronous()) {
                    log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in separate Thread");
                    result = isolatedServiceCaller.callServiceIsolated(javaListener, correlationID, message, context, true);
                } else {
                    log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in asynchronously");
                    isolatedServiceCaller.callServiceAsynchronous(javaListener, correlationID, message, context, true);
                    result = message;
                }
            } else {
                log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in same Thread");
                result = listener.processRequest(correlationID, message, context);
            }
        } catch (ListenerException e) {
            if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
                throw new TimeOutException(getLogPrefix() + "timeout calling JavaListener [" + javaListener + "]", e);
            } else {
                throw new SenderException(getLogPrefix() + "exception calling JavaListener [" + javaListener + "]", e);
            }
        } finally {
            if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
                log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
            }
            if (prc != null) {
                Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
            }
        }
    }
    return result;
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) HashMap(java.util.HashMap) JavaListener(nl.nn.adapterframework.receivers.JavaListener) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

JavaListener (nl.nn.adapterframework.receivers.JavaListener)11 ListenerException (nl.nn.adapterframework.core.ListenerException)7 SenderException (nl.nn.adapterframework.core.SenderException)7 HashMap (java.util.HashMap)6 WebServiceListener (nl.nn.adapterframework.http.WebServiceListener)6 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 IbisWebServiceSender (nl.nn.adapterframework.http.IbisWebServiceSender)4 WebServiceSender (nl.nn.adapterframework.http.WebServiceSender)4 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)4 JmsSender (nl.nn.adapterframework.jms.JmsSender)4 PullingJmsListener (nl.nn.adapterframework.jms.PullingJmsListener)4 DelaySender (nl.nn.adapterframework.senders.DelaySender)4 IbisJavaSender (nl.nn.adapterframework.senders.IbisJavaSender)4 Iterator (java.util.Iterator)3 TimeOutException (nl.nn.adapterframework.core.TimeOutException)3 TimeoutException (nl.nn.adapterframework.core.TimeoutException)3 FileNotFoundException (java.io.FileNotFoundException)2 ParseException (java.text.ParseException)2