All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.messaging.core.AbstractMessagingTemplate Maven / Gradle / Ivy

There is a newer version: 6.1.6
Show newest version
/*
 * Copyright 2002-2018 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;

import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;

/**
 * An extension of {@link AbstractMessageReceivingTemplate} that adds support for
 * request-reply style operations as defined by {@link MessageRequestReplyOperations}.
 *
 * @author Mark Fisher
 * @author Rossen Stoyanchev
 * @author Stephane Nicoll
 * @since 4.0
 * @param  the destination type
 */
public abstract class AbstractMessagingTemplate extends AbstractMessageReceivingTemplate
		implements MessageRequestReplyOperations {

	@Override
	@Nullable
	public Message sendAndReceive(Message requestMessage) {
		return sendAndReceive(getRequiredDefaultDestination(), requestMessage);
	}

	@Override
	@Nullable
	public Message sendAndReceive(D destination, Message requestMessage) {
		return doSendAndReceive(destination, requestMessage);
	}

	@Nullable
	protected abstract Message doSendAndReceive(D destination, Message requestMessage);


	@Override
	@Nullable
	public  T convertSendAndReceive(Object request, Class targetClass) {
		return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass);
	}

	@Override
	@Nullable
	public  T convertSendAndReceive(D destination, Object request, Class targetClass) {
		return convertSendAndReceive(destination, request, null, targetClass);
	}

	@Override
	@Nullable
	public  T convertSendAndReceive(
			D destination, Object request, @Nullable Map headers, Class targetClass) {

		return convertSendAndReceive(destination, request, headers, targetClass, null);
	}

	@Override
	@Nullable
	public  T convertSendAndReceive(
			Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor) {

		return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass, postProcessor);
	}

	@Override
	@Nullable
	public  T convertSendAndReceive(D destination, Object request, Class targetClass,
			@Nullable MessagePostProcessor postProcessor) {

		return convertSendAndReceive(destination, request, null, targetClass, postProcessor);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Nullable
	public  T convertSendAndReceive(D destination, Object request, @Nullable Map headers,
			Class targetClass, @Nullable MessagePostProcessor postProcessor) {

		Message requestMessage = doConvert(request, headers, postProcessor);
		Message replyMessage = sendAndReceive(destination, requestMessage);
		return (replyMessage != null ? (T) getMessageConverter().fromMessage(replyMessage, targetClass) : null);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy