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;
}
Aggregations