Example usage for org.springframework.integration.support AbstractIntegrationMessageBuilder setHeader

List of usage examples for org.springframework.integration.support AbstractIntegrationMessageBuilder setHeader

Introduction

In this page you can find the example usage for org.springframework.integration.support AbstractIntegrationMessageBuilder setHeader.

Prototype

public abstract AbstractIntegrationMessageBuilder<T> setHeader(String headerName, @Nullable Object headerValue);

Source Link

Document

Set the value for the given header name.

Usage

From source file:org.springframework.integration.aws.inbound.SnsInboundChannelAdapter.java

@Override
@SuppressWarnings("unchecked")
protected void send(Object object) {
    Message<?> message = (Message<?>) object;
    Map<String, String> payload = (HashMap<String, String>) message.getPayload();
    AbstractIntegrationMessageBuilder<?> messageToSendBuilder;
    if (this.payloadExpression != null) {
        messageToSendBuilder = getMessageBuilderFactory()
                .withPayload(this.payloadExpression.getValue(this.evaluationContext, message))
                .copyHeaders(message.getHeaders());
    } else {/*  ww w .  j ava 2  s.c  om*/
        messageToSendBuilder = getMessageBuilderFactory().fromMessage(message);
    }

    String type = payload.get("Type");
    if ("SubscriptionConfirmation".equals(type) || "UnsubscribeConfirmation".equals(type)) {
        JsonNode content = this.jackson2HttpMessageConverter.getObjectMapper().valueToTree(payload);
        NotificationStatus notificationStatus = this.notificationStatusResolver
                .resolveNotificationStatus(content);
        if (this.handleNotificationStatus) {
            messageToSendBuilder.setHeader(AwsHeaders.NOTIFICATION_STATUS, notificationStatus);
        } else {
            if ("SubscriptionConfirmation".equals(type)) {
                notificationStatus.confirmSubscription();
            }
            return;
        }
    }
    messageToSendBuilder.setHeader(AwsHeaders.SNS_MESSAGE_TYPE, type).setHeader(AwsHeaders.MESSAGE_ID,
            payload.get("MessageId"));
    super.send(messageToSendBuilder.build());
}

From source file:org.springframework.integration.amqp.inbound.AmqpMessageSource.java

@Override
protected AbstractIntegrationMessageBuilder<Object> doReceive() {
    Connection connection = this.connectionFactory.createConnection(); // NOSONAR - RabbitUtils
    Channel channel = connection.createChannel(this.transacted);
    try {/*from ww w .  ja va  2s. c  o  m*/
        GetResponse resp = channel.basicGet(this.queue, false);
        if (resp == null) {
            RabbitUtils.closeChannel(channel);
            RabbitUtils.closeConnection(connection);
            return null;
        }
        AcknowledgmentCallback callback = this.ackCallbackFactory
                .createCallback(new AmqpAckInfo(connection, channel, this.transacted, resp));
        MessageProperties messageProperties = this.propertiesConverter.toMessageProperties(resp.getProps(),
                resp.getEnvelope(), StandardCharsets.UTF_8.name());
        messageProperties.setConsumerQueue(this.queue);
        Map<String, Object> headers = this.headerMapper.toHeadersFromRequest(messageProperties);
        org.springframework.amqp.core.Message amqpMessage = new org.springframework.amqp.core.Message(
                resp.getBody(), messageProperties);
        Object payload = this.messageConverter.fromMessage(amqpMessage);
        AbstractIntegrationMessageBuilder<Object> builder = getMessageBuilderFactory().withPayload(payload)
                .copyHeaders(headers)
                .setHeader(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK, callback);
        if (this.rawMessageHeader) {
            builder.setHeader(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage);
        }
        return builder;
    } catch (IOException e) {
        RabbitUtils.closeChannel(channel);
        RabbitUtils.closeConnection(connection);
        throw RabbitExceptionTranslator.convertRabbitAccessException(e);
    }
}