protected MessageChannel resolveChannelForName(String channelName, Message<?> message) { Assert.state(this.channelResolver != null, "unable to resolve channel names, no ChannelResolver available"); MessageChannel channel = null; try { channel = this.channelResolver.resolveChannelName(channelName); } catch (ChannelResolutionException e) { if (!ignoreChannelNameResolutionFailures) throw new MessagingException(message, "failed to resolve channel name '" + channelName + "'", e); } if(channel == null && !ignoreChannelNameResolutionFailures){ throw new MessagingException(message, "failed to resolve channel name '" + channelName + "'"); } return channel; }
final Message<?> failedMessage = ex.getFailedMessage(); final Exception cause = (Exception) ex.getCause(); final String processId = ((ProcessContext) ex.getFailedMessage().getHeaders() .get(MessageRegistryConstants.MSG_HEADER_CTX)).getProcessId(); try {
public final void handle(Throwable t) { Message<?> failedMessage = (t instanceof MessagingException) ? ((MessagingException) t).getFailedMessage() : null; MessageChannel errorChannel = this.resolveErrorChannel(failedMessage); boolean sent = false; if (errorChannel != null) { try { if (this.sendTimeout >= 0) { sent = errorChannel.send(new ErrorMessage(t), this.sendTimeout); } else { sent = errorChannel.send(new ErrorMessage(t)); } } catch (Throwable errorDeliveryError) { // message will be logged only if (logger.isWarnEnabled()) { logger.warn("Error message was not delivered.", errorDeliveryError); } } } if (!sent && logger.isErrorEnabled()) { if (failedMessage != null) { logger.error("failure occurred in messaging task with message: " + failedMessage, t); } else { logger.error("failure occurred in messaging task", t); } } }
public void handleMessage(Message<?> message) { Object result = this.invokeMethod(message); if (result != null) { throw new MessagingException(message, "the MethodInvokingMessageHandler method must " + "have a void return, but '" + this + "' received a value: [" + result + "]"); } }
@Override protected Object fromMessage(Message<?> message) { try { return this.outboundMapper.fromMessage(message); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new MessagingException(message, e); } }
@Override protected Message<?> toMessage(Object object) { try { return this.inboundMapper.toMessage(object); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new MessagingException("failed to create Message", e); } }
@SuppressWarnings("unchecked") public Message<Object> receive() { if (this.invoker == null) { this.afterPropertiesSet(); } try { Object result = this.invoker.invokeMethod(new Object[] {}); if (result == null) { return null; } if (result instanceof Message) { return (Message) result; } return new GenericMessage<Object>(result); } catch (InvocationTargetException e) { throw new MessagingException( "Source method '" + this.methodName + "' threw an Exception.", e.getTargetException()); } catch (Throwable e) { throw new MessagingException("Failed to invoke source method '" + this.methodName + "'."); } }
public Object receive() { this.initializeIfNecessary(); Assert.state(this.replyChannel != null && (this.replyChannel instanceof PollableChannel), "receive is not supported, because no pollable reply channel has been configured"); Message<?> message = this.channelTemplate.receive((PollableChannel) this.replyChannel); try { return this.fromMessage(message); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else throw new MessagingException(message, e); } }
protected void addToCollection(Collection<MessageChannel> channels, Collection<?> channelIndicators, Message<?> message){ if(channelIndicators == null){ return; } for (Object channelIndicator : channelIndicators) { if (channelIndicator == null) { continue; } else if (channelIndicator instanceof String) { addChannelFromString(channels, (String)channelIndicator, message); } else if (channelIndicator instanceof MessageChannel){ channels.add((MessageChannel)channelIndicator); } else if (channelIndicator instanceof Collection){ addToCollection(channels, (Collection<?>)channelIndicator, message); } else if (channelIndicator instanceof MessageChannel[]) { channels.addAll(Arrays.asList((MessageChannel[]) channelIndicator)); } else if (channelIndicator instanceof String[]) { for (String indicatorName : (String[]) channelIndicator) { addChannelFromString(channels, indicatorName, message); } }else { throw new MessagingException("unsupported return type for router [" + channelIndicator.getClass() + "]"); } } }
protected final Object executeMethod(List<Message<?>> messages) { try { if (isMethodParameterParameterized(this.method) && isHavingActualTypeArguments(this.method) && (isActualTypeRawMessage(this.method) || isActualTypeParameterizedMessage(this.method))) { return this.invoker.invokeMethod(messages); } return this.invoker.invokeMethod(extractPayloadsFromMessages(messages)); } catch (InvocationTargetException e) { throw new MessagingException( "Method '" + this.method + "' threw an Exception.", e.getTargetException()); } catch (Exception e) { throw new MessagingException("Failed to invoke method '" + this.method + "'."); } }
public final Message<?> transform(Message<?> message) { try { Map<String, Object> headerMap = new HashMap<String, Object>(message.getHeaders()); this.transformHeaders(headerMap); return MessageBuilder.withPayload(message.getPayload()).copyHeaders(headerMap).build(); } catch (Exception e) { throw new MessagingException(message, "failed to transform message headers", e); } }
private Message<?> sendAndReceiveMessage(Message<?> message) { this.initializeIfNecessary(); Assert.notNull(message, "request message must not be null"); if (this.requestChannel == null) { throw new MessageDeliveryException(message, "No request channel available. Cannot send request message."); } if (this.replyChannel != null && this.replyMessageCorrelator == null) { this.registerReplyMessageCorrelator(); } Message<?> reply = this.channelTemplate.sendAndReceive(message, this.requestChannel); if (reply != null && this.shouldThrowErrors && reply instanceof ErrorMessage) { Throwable error = ((ErrorMessage) reply).getPayload(); if (error instanceof RuntimeException) { throw (RuntimeException) error; } throw new MessagingException("gateway received checked Exception", error); } return reply; }