/** * Returns the Message payload (or null if the Message is null). */ public Object fromMessage(Message<?> message) { if (message == null || message.getPayload() == null) { return null; } return message.getPayload(); }
protected boolean isOrchestrationMessage(Message<?> message) { return (message.getPayload() instanceof IOrchestrationPayload); }
protected boolean isOrchestrationMessage(Message<?> message) { return (message.getPayload() instanceof IOrchestrationPayload); }
@Override protected MessageChannel determineTargetChannel(Message<?> message) { return this.payloadTypeChannelMap.get(message.getPayload().getClass()); }
private List<?> extractPayloadsFromMessages(List<Message<?>> messages) { List<Object> payloadList = new ArrayList<Object>(); for (Message<?> message : messages) { payloadList.add(message.getPayload()); } return payloadList; }
public boolean accept(Message<?> message) { Assert.notNull(message, "'message' must not be null"); Object payload = message.getPayload(); Assert.notNull(payload, "'payload' must not be null"); for (Class<?> type : this.acceptedTypes) { if (type.isAssignableFrom(payload.getClass())) { return true; } } return false; }
protected final Object splitMessage(Message<?> message) { Object payload = message.getPayload(); if (payload instanceof String && this.delimiters != null) { List<String> tokens = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer((String) payload, this.delimiters); while (tokenizer.hasMoreElements()) { tokens.add(tokenizer.nextToken()); } return tokens; } return payload; }
@Override protected MessageChannel determineTargetChannel(Message<?> message) { MessageChannel channel = null; Object payload = message.getPayload(); if (payload != null && (payload instanceof Throwable)) { Throwable mostSpecificCause = (Throwable) payload; while (mostSpecificCause != null) { MessageChannel mappedChannel = this.exceptionTypeChannelMap.get(mostSpecificCause.getClass()); if (mappedChannel != null) { channel = mappedChannel; } mostSpecificCause = mostSpecificCause.getCause(); } } return channel; }
/** * Create a builder for a new {@link Message} instance pre-populated with * all of the headers copied from the provided message. The payload of the * provided Message will also be used as the payload for the new message. * * @param messageToCopy the Message from which the payload and all headers * will be copied */ public static <T> MessageBuilder<T> fromMessage(Message<T> message) { Assert.notNull(message, "message must not be null"); MessageBuilder<T> builder = new MessageBuilder<T>(message.getPayload(), message); return builder; }
/** * Create a builder for a new {@link Message} instance pre-populated with * all of the headers copied from the provided message. The payload of the * provided Message will also be used as the payload for the new message. * * @param messageToCopy the Message from which the payload and all headers * will be copied */ public static <T> RelaxedMessageBuilder<T> fromMessage(Message<T> message) { Assert.notNull(message, "message must not be null"); RelaxedMessageBuilder<T> builder = new RelaxedMessageBuilder<T>(message.getPayload(), message); return builder; }
public Method resolveHandlerMethod(Message<?> message) { Method method = this.methodMap.get(message.getClass()); if (method == null) { Class<?> payloadType = message.getPayload().getClass(); method = this.methodMap.get(payloadType); if (method == null) { method = this.findClosestMatch(payloadType); } if (method == null) { method = this.fallbackMethod; } } return method; }
/** * {@inheritDoc} */ @Override protected Message<?> aggregateMessages(List<Message<?>> messages) { List<Object> payloads = new ArrayList<Object>(messages.size()); for (Message<?> message : messages) { payloads.add(message.getPayload()); } return MessageBuilder.withPayload(payloads).build(); }
/** * That is 'template method' pattern implementation. Extensions of this * class should not worry about deleting blob after it was downloaded and * transformed to some other form. * * @param message * @return * @throws BlobTransformException * @see org.opencredo.cloud.storage.si.transformer.BlobTransformer#transform(org.springframework.integration.core.Message) */ public Message<T> transform(Message<BlobDetails> message) throws BlobTransformException { Assert.notNull(message.getPayload(), "Transformer expects message payload"); Message<T> result = doTransform(message); deleteBlobIfNeeded(message.getPayload().getContainerName(), message.getPayload().getName()); return result; }
public final void handleMessage(Message<?> message) { Assert.notNull(message == null, "Message must not be null"); Assert.notNull(message.getPayload(), "Message payload must not be null"); if (this.logger.isDebugEnabled()) { this.logger.debug(this + " received message: " + message); } try { this.handleMessageInternal(message); } catch (Exception e) { if (e instanceof MessagingException) { throw (MessagingException) e; } throw new MessageHandlingException(message, "error occurred in message handler [" + this + "]", e); } }
@Override public final void handleRequestMessage(Message<?> message, ReplyMessageHolder replyHolder) { if (!(message.getPayload() instanceof Serializable)) { throw new MessageHandlingException(message, this.getClass().getName() + " expects a Serializable payload type " + "but encountered [" + message.getPayload().getClass().getName() + "]"); } Message<?> requestMessage = MessageBuilder.fromMessage(message).build(); try { Message<?> reply = this.handlerProxy.handle(requestMessage); if (reply != null) { replyHolder.set(reply); } } catch (RemoteAccessException e) { throw new MessageHandlingException(message, "unable to handle message remotely", e); } }
/** * Checks whether cloning is required for given message. * Orchestration messages are excluded from cloning. * @param message * @return true whenever cloning is required, false otherwise */ protected boolean isCloningRequired(Message<?> message) { if (isOrchestrationMessage(message)) { // always excluding orchestration messages from cloning return false; } else { if (isMutable!=null) { return isMutable; } else { // flag wasn't explicitely declared inferring... return !immutabilityInspector.isImmutable( message.getPayload()); } } }
/** * Checks whether cloning is required for given message. * Orchestration messages are excluded from cloning. * @param message * @return true whenever cloning is required, false otherwise */ protected boolean isCloningRequired(Message<?> message) { if (isOrchestrationMessage(message)) { // always excluding orchestration messages from cloning return false; } else { if (isMutable!=null) { return isMutable; } else { // flag wasn't explicitely declared inferring... return !immutabilityInspector.isImmutable( message.getPayload()); } } }
/** * @param message */ protected Message<String> doTransform(Message<BlobDetails> message) throws BlobTransformException { if (LOG.isDebugEnabled()) { LOG.debug("Transform blob to string: '{}'", String.valueOf(message.getPayload())); } BlobDetails payload = message.getPayload(); String blobAsString = getTemplate().receiveAsString(payload.getContainerName(), payload.getName()); MessageBuilder<String> builder = (MessageBuilder<String>) MessageBuilder.withPayload(blobAsString)// .copyHeaders(message.getHeaders()); Message<String> blobMessage = builder.build(); return blobMessage; } }
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); } }
public final Message<?> transform(Message<?> message) { try { @SuppressWarnings("unchecked") U result = this.transformPayload((T) message.getPayload()); return MessageBuilder.withPayload(result).copyHeaders(message.getHeaders()).build(); } catch (MessageTransformationException e) { throw e; } catch (Exception e) { throw new MessageTransformationException(message, "failed to transform message payload", e); } }