use of nl.nn.adapterframework.stream.IStreamingSender in project iaf by ibissource.
the class MessageSendingPipe method sendMessage.
protected PipeRunResult sendMessage(Message input, PipeLineSession session, ISender sender, Map<String, Object> threadContext) throws SenderException, TimeoutException, IOException, InterruptedException {
long startTime = System.currentTimeMillis();
PipeRunResult sendResult = null;
String exitState = null;
try {
PipeLine pipeline = getPipeLine();
if (pipeline != null) {
Adapter adapter = pipeline.getAdapter();
if (adapter != null) {
if (getPresumedTimeOutInterval() >= 0 && !isConfigurationStubbed) {
long lastExitIsTimeoutDate = adapter.getLastExitIsTimeoutDate(getName());
if (lastExitIsTimeoutDate > 0) {
long duration = startTime - lastExitIsTimeoutDate;
if (duration < (1000L * getPresumedTimeOutInterval())) {
exitState = PRESUMED_TIMEOUT_FORWARD;
throw new TimeoutException(getLogPrefix(session) + exitState);
}
}
}
}
}
try {
if (sender instanceof IStreamingSender && canStreamToNextPipe() && getOutputValidator() == null && getOutputWrapper() == null && !isStreamResultToServlet()) {
sendResult = ((IStreamingSender) sender).sendMessage(input, session, getNextPipe());
} else {
// sendResult has a messageID for async senders, the result for sync senders
Message result = sender.sendMessage(input, session);
sendResult = new PipeRunResult(null, result);
}
} catch (SenderException se) {
exitState = PipeForward.EXCEPTION_FORWARD_NAME;
throw se;
} catch (TimeoutException toe) {
exitState = TIMEOUT_FORWARD;
throw toe;
}
if (Thread.currentThread().isInterrupted()) {
exitState = INTERRUPT_FORWARD;
throw new InterruptedException();
}
Message sendResultMessage = sendResult.getResult();
if (sendResultMessage.asObject() instanceof String) {
String result = (String) sendResultMessage.asObject();
if (StringUtils.isNotEmpty(getTimeOutOnResult()) && getTimeOutOnResult().equals(result)) {
exitState = TIMEOUT_FORWARD;
throw new TimeoutException(getLogPrefix(session) + "timeOutOnResult [" + getTimeOutOnResult() + "]");
}
if (StringUtils.isNotEmpty(getExceptionOnResult()) && getExceptionOnResult().equals(result)) {
exitState = PipeForward.EXCEPTION_FORWARD_NAME;
throw new SenderException(getLogPrefix(session) + "exceptionOnResult [" + getExceptionOnResult() + "]");
}
}
} finally {
if (exitState == null) {
exitState = PipeForward.SUCCESS_FORWARD_NAME;
}
PipeLine pipeline = getPipeLine();
if (pipeline != null) {
Adapter adapter = pipeline.getAdapter();
if (adapter != null) {
if (getPresumedTimeOutInterval() >= 0 && !ConfigurationUtils.isConfigurationStubbed(getConfigurationClassLoader())) {
if (!PRESUMED_TIMEOUT_FORWARD.equals(exitState)) {
adapter.setLastExitState(getName(), System.currentTimeMillis(), exitState);
}
}
String duration;
if (msgLogHumanReadable) {
duration = Misc.getAge(startTime);
} else {
duration = Misc.getDurationInMs(startTime);
}
if (msgLog.getLevel().isMoreSpecificThan(MSGLOG_LEVEL_TERSE)) {
msgLog.log(MSGLOG_LEVEL_TERSE, String.format("Sender [%s] class [%s] duration [%s] got exit-state [%s]", sender.getName(), ClassUtils.nameOf(sender), duration, exitState));
}
}
}
}
return sendResult;
}
Aggregations