Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2002-2013 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
  * 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.
 import java.util.List;
 import java.util.Map;
An extension of MessageHeaderAccessor that also stores and provides read/write access to message headers from an external source -- e.g. a Spring org.springframework.messaging.Message created to represent a STOMP message received from a STOMP client or message broker. Native message headers are kept in a org.springframework.util.MultiValueMap under the key NATIVE_HEADERS.

This class is not intended for direct use but is rather expected to be consumed through sub-classes such as StompHeaderAccessor. Such sub-classes may provide factory methods to translate message headers from an external messaging source (e.g. STOMP) to Spring org.springframework.messaging.Message headers and reversely to translate Spring org.springframework.messaging.Message headers to a message to send to an external source.

Rossen Stoyanchev
 	public static final String NATIVE_HEADERS = "nativeHeaders";
 	// wrapped native headers
 	private final Map<StringList<String>> originalNativeHeaders;
 	// native header updates
A constructor for creating new headers, accepting an optional native header map.
 	protected NativeMessageHeaderAccessor(Map<StringList<String>> nativeHeaders) {
 		this. = nativeHeaders;

A constructor for accessing and modifying existing message headers.
 	protected NativeMessageHeaderAccessor(Message<?> message) {
 	private static Map<StringList<String>> initNativeHeaders(Message<?> message) {
 		if (message != null) {
 			Map<StringList<String>> headers = (Map<StringList<String>>) message.getHeaders().get();
 			if (headers != null) {
 				return headers;
 		return null;
 	public Map<StringObjecttoMap() {
 		Map<StringObjectresult = super.toMap();
 		return result;
 	public boolean isModified() {
 		return (super.isModified() || (!this..isEmpty()));

Return a map with native headers including original, wrapped headers (if any) plus additional header updates made through accessor methods.
		Map<StringList<String>> result = new HashMap<StringList<String>>();
		if (this. != null) {
		for (String key : this..keySet()) {
			List<Stringvalue = this..get(key);
			if (value == null) {
			else {
		return result;

Return all values for the specified native header or null.
	public List<StringgetNativeHeader(String headerName) {
		if (this..containsKey(headerName)) {
			return this..get(headerName);
		else if (this. != null) {
			return this..get(headerName);
		return null;

Return the first value for the specified native header of null.
	public String getFirstNativeHeader(String headerName) {
		List<Stringvalues = getNativeHeader(headerName);
		return CollectionUtils.isEmpty(values) ? null : values.get(0);

Set the specified native header value.
	public void setNativeHeader(String nameString value) {
		if (!ObjectUtils.nullSafeEquals(valuegetHeader(name))) {

Add the specified native header value.
	public void addNativeHeader(String nameString value) {
New to GrepCode? Check out our FAQ X