/**
  * Copy the name-value pairs from the provided Map.
  *
  * <p>This operation will overwrite any existing values. Use {@link #copyHeadersIfAbsent(Map)} to
  * avoid overwriting values.
  */
 public void copyHeaders(Map<String, ?> headersToCopy) {
   if (headersToCopy != null) {
     for (Map.Entry<String, ?> entry : headersToCopy.entrySet()) {
       if (!isReadOnly(entry.getKey())) {
         setHeader(entry.getKey(), entry.getValue());
       }
     }
   }
 }
  @Test
  public void wrapMessageAndModifyHeaders() {
    Map<String, Object> original = new HashMap<>();
    original.put("foo", "bar");
    original.put("bar", "baz");
    GenericMessage<String> message = new GenericMessage<>("p", original);

    MessageHeaderAccessor headers = new MessageHeaderAccessor(message);
    headers.setHeader("foo", "BAR");
    Map<String, Object> actual = headers.toMap();

    assertEquals(4, actual.size());
    assertNotNull(actual.get(MessageHeaders.ID));
    assertNotNull(actual.get(MessageHeaders.TIMESTAMP));
    assertEquals("BAR", actual.get("foo"));
    assertEquals("baz", actual.get("bar"));
  }
 public void setErrorChannel(MessageChannel errorChannel) {
   setHeader(MessageHeaders.ERROR_CHANNEL, errorChannel);
 }
 public void setErrorChannelName(String errorChannelName) {
   setHeader(MessageHeaders.ERROR_CHANNEL, errorChannelName);
 }
 public void setReplyChannel(MessageChannel replyChannel) {
   setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel);
 }
 public void setReplyChannelName(String replyChannelName) {
   setHeader(MessageHeaders.REPLY_CHANNEL, replyChannelName);
 }
 public void setContentType(MimeType contentType) {
   setHeader(MessageHeaders.CONTENT_TYPE, contentType);
 }
 /** Remove the value for the given header name. */
 public void removeHeader(String headerName) {
   if (StringUtils.hasLength(headerName) && !isReadOnly(headerName)) {
     setHeader(headerName, null);
   }
 }
 /**
  * Set the value for the given header name only if the header name is not already associated with
  * a value.
  */
 public void setHeaderIfAbsent(String name, Object value) {
   if (getHeader(name) == null) {
     setHeader(name, value);
   }
 }