Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2014 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.messaging.core;
 
 import java.util.Map;
 
An extension of AbstractMessageSendingTemplate that adds support for receive as well as request-reply style operations as defined by MessageReceivingOperations and MessageRequestReplyOperations.

Author(s):
Mark Fisher
Rossen Stoyanchev
Since:
4.0
 
 public abstract class AbstractMessagingTemplate<D> extends AbstractMessageSendingTemplate<D>
 
 
 	public Message<?> receive() {
 	}
 
 	public Message<?> receive(D destination) {
 		return doReceive(destination);
 	}
 
 	protected abstract Message<?> doReceive(D destination);
 
 
 	public <T> T receiveAndConvert(Class<T> targetClass) {
 	}
 
 	@SuppressWarnings("unchecked")
 	public <T> T receiveAndConvert(D destinationClass<T> targetClass) {
 		Message<?> message = doReceive(destination);
 		if (message != null) {
 			return (T) getMessageConverter().fromMessage(messagetargetClass);
 		}
 		else {
 			return null;
 		}
 	}
 
 	public Message<?> sendAndReceive(Message<?> requestMessage) {
 		return sendAndReceive(getRequiredDefaultDestination(), requestMessage);
 	}
 
 	public Message<?> sendAndReceive(D destinationMessage<?> requestMessage) {
 		return doSendAndReceive(destinationrequestMessage);
 	}
 
 	protected abstract Message<?> doSendAndReceive(D destinationMessage<?> requestMessage);
 
 
 	public <T> T convertSendAndReceive(Object requestClass<T> targetClass) {
 		return convertSendAndReceive(getRequiredDefaultDestination(), requesttargetClass);
 	}
 
 	public <T> T convertSendAndReceive(D destinationObject requestClass<T> targetClass) {
 		return convertSendAndReceive(destinationrequestnulltargetClass);
 	}
 
 	public <T> T convertSendAndReceive(D destinationObject requestMap<StringObjectheadersClass<T> targetClass) {
 		return convertSendAndReceive(destinationrequestheaderstargetClassnull);
 	}
 
 	public <T> T convertSendAndReceive(Object requestClass<T> targetClassMessagePostProcessor postProcessor) {
 		return convertSendAndReceive(getRequiredDefaultDestination(), requesttargetClasspostProcessor);
 	}
	public <T> T convertSendAndReceive(D destinationObject requestClass<T> targetClassMessagePostProcessor postProcessor) {
		return convertSendAndReceive(destinationrequestnulltargetClasspostProcessor);
	}
	@SuppressWarnings("unchecked")
	public <T> T convertSendAndReceive(D destinationObject requestMap<StringObjectheaders,
			Class<T> targetClassMessagePostProcessor postProcessor) {
		MessageHeaders messageHeaders = (headers != null ? new MessageHeaders(headers) : null);
		Message<?> requestMessage = getMessageConverter().toMessage(requestmessageHeaders);
		if (requestMessage == null) {
			String payloadType = (request != null ? request.getClass().getName() : null);
			Object contentType = (messageHeaders != null ? messageHeaders.get(.) : null);
			throw new MessageConversionException("Unable to convert payload with type '" + payloadType +
					"', contentType='" + contentType + "', converter=[" + getMessageConverter() + "]");
		}
		if (postProcessor != null) {
			requestMessage = postProcessor.postProcessMessage(requestMessage);
		}
		Message<?> replyMessage = sendAndReceive(destinationrequestMessage);
		return (replyMessage != null ? (T) getMessageConverter().fromMessage(replyMessagetargetClass) : null);
	}
New to GrepCode? Check out our FAQ X