org.springframework.integration.support.AbstractIntegrationMessageBuilder.copyHeadersIfAbsent()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中org.springframework.integration.support.AbstractIntegrationMessageBuilder.copyHeadersIfAbsent()方法的一些代码示例,展示了AbstractIntegrationMessageBuilder.copyHeadersIfAbsent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractIntegrationMessageBuilder.copyHeadersIfAbsent()方法的具体详情如下:
包路径:org.springframework.integration.support.AbstractIntegrationMessageBuilder
类名称:AbstractIntegrationMessageBuilder
方法名:copyHeadersIfAbsent

AbstractIntegrationMessageBuilder.copyHeadersIfAbsent介绍

[英]Copy the name-value pairs from the provided Map. This operation will not overwrite any existing values.
[中]从提供的映射复制名称-值对。此操作不会覆盖任何现有值。

代码示例

代码示例来源:origin: spring-projects/spring-integration

/**
 * Remove headers from the provided map matching to the provided pattens
 * and only after that copy the result into the target message headers.
 * @param headersToCopy a map of headers to copy.
 * @param headerPatternsToFilter an arrays of header patterns to filter before copying.
 * @return the current {@link AbstractIntegrationMessageBuilder}.
 * @since 5.1
 * @see #copyHeadersIfAbsent(Map)
 */
public AbstractIntegrationMessageBuilder<T> filterAndCopyHeadersIfAbsent(Map<String, ?> headersToCopy,
    String... headerPatternsToFilter) {
  Map<String, ?> headers = headersToCopy;
  if (!ObjectUtils.isEmpty(headerPatternsToFilter)) {
    headers = new HashMap<>(headersToCopy);
    headers.entrySet()
        .removeIf(entry -> PatternMatchUtils.simpleMatch(headerPatternsToFilter, entry.getKey()));
  }
  return copyHeadersIfAbsent(headers);
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> toMessage(Object object, @Nullable Map<String, Object> headers) throws Exception {
  if (object instanceof Message<?>) {
    return (Message<?>) object;
  }
  return object != null
      ? this.messageBuilderFactory.withPayload(object).copyHeadersIfAbsent(headers).build()
      : null;
}

代码示例来源:origin: spring-projects/spring-integration

private Message<?> buildMessage(Map<String, Object> headers, Object messageOrPayload,
    EvaluationContext methodInvocationEvaluationContext) {
  AbstractIntegrationMessageBuilder<?> builder =
      (messageOrPayload instanceof Message)
          ? this.messageBuilderFactory.fromMessage((Message<?>) messageOrPayload)
          : this.messageBuilderFactory.withPayload(messageOrPayload);
  builder.copyHeadersIfAbsent(headers);
  // Explicit headers in XML override any @Header annotations...
  if (!CollectionUtils.isEmpty(GatewayMethodInboundMessageMapper.this.headerExpressions)) {
    Map<String, Object> evaluatedHeaders = evaluateHeaders(methodInvocationEvaluationContext,
        GatewayMethodInboundMessageMapper.this.headerExpressions);
    builder.copyHeaders(evaluatedHeaders);
  }
  // ...whereas global (default) headers do not...
  if (!CollectionUtils.isEmpty(GatewayMethodInboundMessageMapper.this.globalHeaderExpressions)) {
    Map<String, Object> evaluatedHeaders = evaluateHeaders(methodInvocationEvaluationContext,
        GatewayMethodInboundMessageMapper.this.globalHeaderExpressions);
    builder.copyHeadersIfAbsent(evaluatedHeaders);
  }
  if (GatewayMethodInboundMessageMapper.this.headers != null) {
    builder.copyHeadersIfAbsent(GatewayMethodInboundMessageMapper.this.headers);
  }
  return builder.build();
}

代码示例来源:origin: spring-projects/spring-integration

@Nullable
@Override
public Message<?> toMessage(Object object, @Nullable MessageHeaders messageHeaders) {
  Assert.isInstanceOf(Map.class, object, "This converter expects a Map");
  @SuppressWarnings("unchecked")
  Map<String, ?> map = (Map<String, ?>) object;
  Object payload = map.get("payload");
  Assert.notNull(payload, "'payload' entry cannot be null");
  AbstractIntegrationMessageBuilder<?> messageBuilder = getMessageBuilderFactory().withPayload(payload);
  @SuppressWarnings("unchecked")
  Map<String, ?> headers = (Map<String, ?>) map.get("headers");
  if (headers != null) {
    if (this.filterHeadersInToMessage) {
      headers.keySet().retainAll(Arrays.asList(this.headerNames));
    }
    messageBuilder.copyHeaders(headers);
  }
  return messageBuilder
      .copyHeadersIfAbsent(messageHeaders)
      .build();
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> toMessage(Object object, @Nullable Map<String, Object> headers) throws Exception {
  if (object == null) {
    return null;
  }
  if (object instanceof Message<?>) {
    return (Message<?>) object;
  }
  return getMessageBuilderFactory()
      .withPayload(object)
      .copyHeadersIfAbsent(headers)
      .build();
}

代码示例来源:origin: spring-projects/spring-integration

@Override
protected Message<?> parseWithHeaders(JsonParser parser, String jsonMessage,
    @Nullable Map<String, Object> headersToAdd) throws Exception {
  String error = AbstractJsonInboundMessageMapper.MESSAGE_FORMAT_ERROR + jsonMessage;
  Assert.isTrue(JsonToken.START_OBJECT == parser.nextToken(), error);
  Map<String, Object> headers = null;
  Object payload = null;
  while (JsonToken.END_OBJECT != parser.nextToken()) {
    Assert.isTrue(JsonToken.FIELD_NAME == parser.getCurrentToken(), error);
    boolean isHeadersToken = "headers".equals(parser.getCurrentName());
    boolean isPayloadToken = "payload".equals(parser.getCurrentName());
    Assert.isTrue(isHeadersToken || isPayloadToken, error);
    if (isHeadersToken) {
      Assert.isTrue(parser.nextToken() == JsonToken.START_OBJECT, error);
      headers = readHeaders(parser, jsonMessage);
    }
    else if (isPayloadToken) {
      parser.nextToken();
      payload = this.readPayload(parser, jsonMessage);
    }
  }
  Assert.notNull(headers, error);
  return getMessageBuilderFactory()
      .withPayload(payload)
      .copyHeaders(headers)
      .copyHeadersIfAbsent(headersToAdd)
      .build();
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public final Object processMessageGroup(MessageGroup group) {
  Assert.notNull(group, "MessageGroup must not be null");
  Map<String, Object> headers = this.aggregateHeaders(group);
  Object payload = this.aggregatePayloads(group, headers);
  AbstractIntegrationMessageBuilder<?> builder;
  if (payload instanceof Message<?>) {
    builder = getMessageBuilderFactory().fromMessage((Message<?>) payload);
  }
  else if (payload instanceof AbstractIntegrationMessageBuilder) {
    builder = (AbstractIntegrationMessageBuilder<?>) payload;
  }
  else {
    builder = getMessageBuilderFactory().withPayload(payload);
  }
  return builder.copyHeadersIfAbsent(headers);
}

代码示例来源:origin: spring-projects/spring-integration

.setHeader(IpHeaders.PORT, port)
.setHeader(IpHeaders.PACKET_ADDRESS, packet.getSocketAddress())
.copyHeadersIfAbsent(headers)
.build();

代码示例来源:origin: spring-projects/spring-integration

private AbstractIntegrationMessageBuilder<?> createBuilder(Object item, Map<String, Object> headers,
    Object correlationId, int sequenceNumber, int sequenceSize) {
  AbstractIntegrationMessageBuilder<?> builder;
  if (item instanceof Message) {
    builder = getMessageBuilderFactory().fromMessage((Message<?>) item);
  }
  else if (item instanceof AbstractIntegrationMessageBuilder) {
    builder = (AbstractIntegrationMessageBuilder<?>) item;
  }
  else {
    builder = getMessageBuilderFactory().withPayload(item);
  }
  builder.copyHeadersIfAbsent(headers);
  if (this.applySequence) {
    builder.pushSequenceDetails(correlationId, sequenceNumber, sequenceSize);
  }
  return builder;
}

代码示例来源:origin: spring-projects/spring-integration

@SuppressWarnings("unchecked")
@Override
public Message<?> toMessage(TcpConnection connection, @Nullable Map<String, Object> headers) throws Exception {
  Message<Object> message = null;
  Object payload = connection.getPayload();
  if (payload != null) {
    AbstractIntegrationMessageBuilder<Object> messageBuilder;
    if (this.bytesMessageMapper != null && payload instanceof byte[]) {
      messageBuilder = (AbstractIntegrationMessageBuilder<Object>) getMessageBuilderFactory()
          .fromMessage(this.bytesMessageMapper.toMessage((byte[]) payload));
    }
    else {
      messageBuilder = getMessageBuilderFactory()
          .withPayload(payload);
    }
    MessageHeaders messageHeaders = new MutableMessageHeaders(null);
    addStandardHeaders(connection, messageHeaders);
    addCustomHeaders(connection, messageHeaders);
    message = messageBuilder
        .copyHeaders(messageHeaders)
        .copyHeadersIfAbsent(headers)
        .build();
  }
  else {
    if (this.logger.isWarnEnabled()) {
      this.logger.warn("Null payload from connection " + connection.getConnectionId());
    }
  }
  return message;
}

代码示例来源:origin: spring-projects/spring-integration

protected AbstractIntegrationMessageBuilder<?> buildReply(MessageConverter converter,
    org.springframework.amqp.core.Message amqpReplyMessage) {
  Object replyObject = converter.fromMessage(amqpReplyMessage);
  AbstractIntegrationMessageBuilder<?> builder = (replyObject instanceof Message)
      ? this.getMessageBuilderFactory().fromMessage((Message<?>) replyObject)
      : this.getMessageBuilderFactory().withPayload(replyObject);
  Map<String, ?> headers = getHeaderMapper().toHeadersFromReply(amqpReplyMessage.getMessageProperties());
  builder.copyHeadersIfAbsent(headers);
  return builder;
}

代码示例来源:origin: spring-projects/spring-integration

getMessageBuilderFactory()
    .fromMessage((Message<Object>) payload)
    .copyHeadersIfAbsent(headers);

代码示例来源:origin: spring-projects/spring-integration

? getMessageBuilderFactory().fromMessage((Message<?>) object)
        : getMessageBuilderFactory().withPayload(object);
return builder.copyHeadersIfAbsent(mappedHeaders);

代码示例来源:origin: spring-projects/spring-integration

.copyHeadersIfAbsent(headers);

代码示例来源:origin: spring-projects/spring-integration

.setSequenceNumber(1)
    .setSequenceSize(2)
    .copyHeadersIfAbsent(headers1)
    .build();
Map<String, Object> headers2 = new HashMap<>();
    .setSequenceNumber(2)
    .setSequenceSize(2)
    .copyHeadersIfAbsent(headers2)
    .build();
messages = Arrays.asList(message1, message2);

代码示例来源:origin: spring-projects/spring-integration

protected Message<?> buildReturnedMessage(org.springframework.amqp.core.Message message,
    int replyCode, String replyText, String exchange, String routingKey, MessageConverter converter) {
  Object returnedObject = converter.fromMessage(message);
  AbstractIntegrationMessageBuilder<?> builder = (returnedObject instanceof Message)
      ? this.getMessageBuilderFactory().fromMessage((Message<?>) returnedObject)
      : this.getMessageBuilderFactory().withPayload(returnedObject);
  Map<String, ?> headers = getHeaderMapper().toHeadersFromReply(message.getMessageProperties());
  if (this.errorMessageStrategy == null) {
    builder.copyHeadersIfAbsent(headers)
        .setHeader(AmqpHeaders.RETURN_REPLY_CODE, replyCode)
        .setHeader(AmqpHeaders.RETURN_REPLY_TEXT, replyText)
        .setHeader(AmqpHeaders.RETURN_EXCHANGE, exchange)
        .setHeader(AmqpHeaders.RETURN_ROUTING_KEY, routingKey);
  }
  Message<?> returnedMessage = builder.build();
  if (this.errorMessageStrategy != null) {
    returnedMessage = this.errorMessageStrategy.buildErrorMessage(new ReturnedAmqpMessageException(
        returnedMessage, message, replyCode, replyText, exchange, routingKey), null);
  }
  return returnedMessage;
}

代码示例来源:origin: org.springframework.integration/spring-integration-core

@Override
public Message<?> toMessage(Object object, @Nullable Map<String, Object> headers) throws Exception {
  if (object instanceof Message<?>) {
    return (Message<?>) object;
  }
  return object != null
      ? this.messageBuilderFactory.withPayload(object).copyHeadersIfAbsent(headers).build()
      : null;
}

代码示例来源:origin: org.springframework.integration/spring-integration-core

@Override
public Message<?> toMessage(Object object, @Nullable Map<String, Object> headers) throws Exception {
  if (object == null) {
    return null;
  }
  if (object instanceof Message<?>) {
    return (Message<?>) object;
  }
  return getMessageBuilderFactory()
      .withPayload(object)
      .copyHeadersIfAbsent(headers)
      .build();
}

代码示例来源:origin: org.springframework.integration/spring-integration-core

@Override
public final Object processMessageGroup(MessageGroup group) {
  Assert.notNull(group, "MessageGroup must not be null");
  Map<String, Object> headers = this.aggregateHeaders(group);
  Object payload = this.aggregatePayloads(group, headers);
  AbstractIntegrationMessageBuilder<?> builder;
  if (payload instanceof Message<?>) {
    builder = getMessageBuilderFactory().fromMessage((Message<?>) payload);
  }
  else if (payload instanceof AbstractIntegrationMessageBuilder) {
    builder = (AbstractIntegrationMessageBuilder<?>) payload;
  }
  else {
    builder = getMessageBuilderFactory().withPayload(payload);
  }
  return builder.copyHeadersIfAbsent(headers);
}

代码示例来源:origin: org.springframework.integration/spring-integration-amqp

protected AbstractIntegrationMessageBuilder<?> buildReply(MessageConverter converter,
    org.springframework.amqp.core.Message amqpReplyMessage) {
  Object replyObject = converter.fromMessage(amqpReplyMessage);
  AbstractIntegrationMessageBuilder<?> builder = (replyObject instanceof Message)
      ? this.getMessageBuilderFactory().fromMessage((Message<?>) replyObject)
      : this.getMessageBuilderFactory().withPayload(replyObject);
  Map<String, ?> headers = getHeaderMapper().toHeadersFromReply(amqpReplyMessage.getMessageProperties());
  builder.copyHeadersIfAbsent(headers);
  return builder;
}

相关文章