@Nullable public Object getErrorChannel() { return getHeader(MessageHeaders.ERROR_CHANNEL); }
@Nullable public Object getReplyChannel() { return getHeader(MessageHeaders.REPLY_CHANNEL); }
@Nullable public UUID getId() { Object value = getHeader(MessageHeaders.ID); if (value == null) { return null; } return (value instanceof UUID ? (UUID) value : UUID.fromString(value.toString())); }
@Nullable public Long getTimestamp() { Object value = getHeader(MessageHeaders.TIMESTAMP); if (value == null) { return null; } return (value instanceof Long ? (Long) value : Long.parseLong(value.toString())); }
/** * 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); } }
@Nullable public MimeType getContentType() { Object value = getHeader(MessageHeaders.CONTENT_TYPE); if (value == null) { return null; } return (value instanceof MimeType ? (MimeType) value : MimeType.valueOf(value.toString())); }
/** * Set the value for the given header name. * <p>If the provided value is {@code null}, the header will be removed. */ public void setHeader(String name, @Nullable Object value) { if (isReadOnly(name)) { throw new IllegalArgumentException("'" + name + "' header is read-only"); } verifyType(name, value); if (value != null) { // Modify header if necessary if (!ObjectUtils.nullSafeEquals(value, getHeader(name))) { this.modified = true; this.headers.getRawHeaders().put(name, value); } } else { // Remove header if available if (this.headers.containsKey(name)) { this.modified = true; this.headers.getRawHeaders().remove(name); } } }
private String doGet(MessageHeaderAccessor accessor, String key) { if (accessor instanceof NativeMessageHeaderAccessor) { NativeMessageHeaderAccessor nativeAccessor = (NativeMessageHeaderAccessor) accessor; String result = nativeAccessor.getFirstNativeHeader(key); if (result != null) { return result; } } else { Object nativeHeaders = accessor .getHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS); if (nativeHeaders instanceof Map) { Object result = ((Map) nativeHeaders).get(key); if (result instanceof List && !((List) result).isEmpty()) { return String.valueOf(((List) result).get(0)); } } } Object result = accessor.getHeader(key); if (result != null) { if (result instanceof byte[]) { return new String((byte[]) result, StandardCharsets.UTF_8); } return result.toString(); } return null; }
private void doPut(MessageHeaderAccessor accessor, String key, String value) { accessor.setHeader(key, value); if (accessor instanceof NativeMessageHeaderAccessor) { NativeMessageHeaderAccessor nativeAccessor = (NativeMessageHeaderAccessor) accessor; nativeAccessor.setNativeHeader(key, value); } else { Object nativeHeaders = accessor .getHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS); if (nativeHeaders == null) { accessor.setHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS, nativeHeaders = new LinkedMultiValueMap<>()); } if (nativeHeaders instanceof Map<?, ?>) { ((Map) nativeHeaders).put(key, Collections.singletonList(value)); } } }
static void removeAnyTraceHeaders(MessageHeaderAccessor accessor, List<String> keysToRemove) { for (String keyToRemove : keysToRemove) { accessor.removeHeader(keyToRemove); if (accessor instanceof NativeMessageHeaderAccessor) { NativeMessageHeaderAccessor nativeAccessor = (NativeMessageHeaderAccessor) accessor; nativeAccessor.removeNativeHeader(keyToRemove); } else { Object nativeHeaders = accessor .getHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS); if (nativeHeaders instanceof Map) { ((Map) nativeHeaders).remove(keyToRemove); } } } }
@Test public void resolveArgumentMessageHeaderAccessor() throws Exception { Object resolved = this.resolver.resolveArgument(this.paramMessageHeaderAccessor, this.message); assertTrue(resolved instanceof MessageHeaderAccessor); MessageHeaderAccessor headers = (MessageHeaderAccessor) resolved; assertEquals("bar", headers.getHeader("foo")); }
@Nullable public Object getErrorChannel() { return getHeader(MessageHeaders.ERROR_CHANNEL); }
@Nullable public Object getReplyChannel() { return getHeader(MessageHeaders.REPLY_CHANNEL); }
@Nullable public UUID getId() { Object value = getHeader(MessageHeaders.ID); if (value == null) { return null; } return (value instanceof UUID ? (UUID) value : UUID.fromString(value.toString())); }
@Nullable public Long getTimestamp() { Object value = getHeader(MessageHeaders.TIMESTAMP); if (value == null) { return null; } return (value instanceof Long ? (Long) value : Long.parseLong(value.toString())); }
@Nullable public MimeType getContentType() { Object value = getHeader(MessageHeaders.CONTENT_TYPE); if (value == null) { return null; } return (value instanceof MimeType ? (MimeType) value : MimeType.valueOf(value.toString())); }
/** * 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); } }
/** * Set the value for the given header name. * <p>If the provided value is {@code null}, the header will be removed. */ public void setHeader(String name, @Nullable Object value) { if (isReadOnly(name)) { throw new IllegalArgumentException("'" + name + "' header is read-only"); } verifyType(name, value); if (value != null) { // Modify header if necessary if (!ObjectUtils.nullSafeEquals(value, getHeader(name))) { this.modified = true; this.headers.getRawHeaders().put(name, value); } } else { // Remove header if available if (this.headers.containsKey(name)) { this.modified = true; this.headers.getRawHeaders().remove(name); } } }
@Nullable public Object getReplyChannel() { return getHeader(MessageHeaders.REPLY_CHANNEL); }
@Nullable public UUID getId() { Object value = getHeader(MessageHeaders.ID); if (value == null) { return null; } return (value instanceof UUID ? (UUID) value : UUID.fromString(value.toString())); }