@Override public void onSuccess(Object result) { Message<?> replyMessage = null; try { replyMessage = createOutputMessage(result, requestHeaders); sendOutput(replyMessage, theReplyChannel, false); } catch (Exception e) { Exception exceptionToLogAndSend = e; if (!(e instanceof MessagingException)) { exceptionToLogAndSend = new MessageHandlingException(requestMessage, e); if (replyMessage != null) { exceptionToLogAndSend = new MessagingException(replyMessage, exceptionToLogAndSend); } } logger.error("Failed to send async reply: " + result.toString(), exceptionToLogAndSend); onFailure(exceptionToLogAndSend); } }
protected void sendErrorMessage(final Message<?> requestMessage, Throwable ex) { Object errorChannel = resolveErrorChannel(requestMessage.getHeaders()); Throwable result = ex; if (!(ex instanceof MessagingException)) { result = new MessageHandlingException(requestMessage, ex); } if (errorChannel == null) { logger.error("Async exception received and no 'errorChannel' header exists and no default " + "'errorChannel' found", result); } else { try { sendOutput(new ErrorMessage(result), errorChannel, true); } catch (Exception e) { Exception exceptionToLog = e; if (!(e instanceof MessagingException)) { exceptionToLog = new MessageHandlingException(requestMessage, e); } logger.error("Failed to send async reply", exceptionToLog); } } }
private void doProduceOutput(final Message<?> requestMessage, final MessageHeaders requestHeaders, Object reply, Object replyChannel) { if (this.async && (reply instanceof ListenableFuture<?> || reply instanceof Publisher<?>)) { if (reply instanceof ListenableFuture<?> || !(getOutputChannel() instanceof ReactiveStreamsSubscribableChannel)) { asyncNonReactiveReply(requestMessage, requestHeaders, reply, replyChannel); } else { ((ReactiveStreamsSubscribableChannel) getOutputChannel()) .subscribeTo( Flux.from((Publisher<?>) reply) .map(result -> createOutputMessage(result, requestHeaders))); } } else { sendOutput(createOutputMessage(reply, requestHeaders), replyChannel, false); } }
protected void sendErrorMessage(final Message<?> requestMessage, Throwable ex) { Object errorChannel = resolveErrorChannel(requestMessage.getHeaders()); Throwable result = ex; if (!(ex instanceof MessagingException)) { result = new MessageHandlingException(requestMessage, ex); } if (errorChannel == null) { logger.error("Async exception received and no 'errorChannel' header exists and no default " + "'errorChannel' found", result); } else { try { sendOutput(new ErrorMessage(result), errorChannel, true); } catch (Exception e) { Exception exceptionToLog = e; if (!(e instanceof MessagingException)) { exceptionToLog = new MessageHandlingException(requestMessage, e); } logger.error("Failed to send async reply", exceptionToLog); } } }
@Override public void onSuccess(Object result) { Message<?> replyMessage = null; try { replyMessage = createOutputMessage(result, requestHeaders); sendOutput(replyMessage, theReplyChannel, false); } catch (Exception e) { Exception exceptionToLogAndSend = e; if (!(e instanceof MessagingException)) { exceptionToLogAndSend = new MessageHandlingException(requestMessage, e); if (replyMessage != null) { exceptionToLogAndSend = new MessagingException(replyMessage, exceptionToLogAndSend); } } logger.error("Failed to send async reply: " + result.toString(), exceptionToLogAndSend); onFailure(exceptionToLogAndSend); } }
private void doProduceOutput(final Message<?> requestMessage, final MessageHeaders requestHeaders, Object reply, Object replyChannel) { if (this.async && (reply instanceof ListenableFuture<?> || reply instanceof Publisher<?>)) { if (reply instanceof ListenableFuture<?> || !(getOutputChannel() instanceof ReactiveStreamsSubscribableChannel)) { asyncNonReactiveReply(requestMessage, requestHeaders, reply, replyChannel); } else { ((ReactiveStreamsSubscribableChannel) getOutputChannel()) .subscribeTo( Flux.from((Publisher<?>) reply) .map(result -> createOutputMessage(result, requestHeaders))); } } else { sendOutput(createOutputMessage(reply, requestHeaders), replyChannel, false); } }