com.solace.spring.cloud.stream.binder.util.StaticMessageHeaderMapAccessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-cloud-stream-binder-solace Show documentation
Show all versions of spring-cloud-stream-binder-solace Show documentation
A Spring Cloud Stream Binder implementation using the Solace Java API (JCSMP)
The newest version!
package com.solace.spring.cloud.stream.binder.util;
import java.util.Map;
/**
* Utility class to perform generic header accessing operations without needing to create a
* {@link org.springframework.messaging.MessageHeaders MessageHeaders} object.
*/
public final class StaticMessageHeaderMapAccessor {
public static T get(Map headers, String key, Class type) {
Object value = headers.get(key);
if (value == null) {
return null;
}
if (!type.isAssignableFrom(value.getClass())) {
throw new IllegalArgumentException(String.format(
"Incorrect type specified for header '%s'. Expected [%s] but actual type is [%s]",
key, type, value.getClass()));
}
@SuppressWarnings("unchecked")
T toReturn = (T) value;
return toReturn;
}
}