Example usage for com.rabbitmq.client BasicProperties getContentType

List of usage examples for com.rabbitmq.client BasicProperties getContentType

Introduction

In this page you can find the example usage for com.rabbitmq.client BasicProperties getContentType.

Prototype

public abstract String getContentType();

Source Link

Document

Retrieve the value in the contentType field.

Usage

From source file:net.echinopsii.ariane.community.messaging.rabbitmq.MsgTranslator.java

License:Open Source License

/**
 * Decode given Message into Map message
 * @param message a RabbitMQ friendly message
 * @return Map message//ww  w . java2  s . c  om
 */
@Override
public Map<String, Object> decode(Message message) {
    Envelope envelope = message.getEnvelope();
    BasicProperties properties = (BasicProperties) message.getProperties();
    byte[] body = message.getBody();

    LinkedHashMap<String, Object> decodedMessage = new LinkedHashMap<String, Object>();
    if (envelope != null) {
        decodedMessage.put(MSG_RBQ_DELIVERY_TAG, envelope.getDeliveryTag());
        decodedMessage.put(MSG_RBQ_EXCHANGE, envelope.getExchange());
        decodedMessage.put(MSG_RBQ_ROUTINGKEY, envelope.getRoutingKey());
    }

    if (properties != null) {
        decodedMessage.put(MSG_APPLICATION_ID, properties.getAppId());
        decodedMessage.put(MSG_RBQ_CONTENT_ENCODING, properties.getContentEncoding());
        decodedMessage.put(MSG_RBQ_CONTENT_TYPE, properties.getContentType());
        decodedMessage.put(MSG_CORRELATION_ID, properties.getCorrelationId());
        decodedMessage.put(MSG_DELIVERY_MODE, properties.getDeliveryMode());
        decodedMessage.put(MSG_EXPIRATION, properties.getExpiration());
        decodedMessage.put(MSG_MESSAGE_ID, properties.getMessageId());
        decodedMessage.put(MSG_PRIORITY, properties.getPriority());
        decodedMessage.put(MSG_REPLY_TO, properties.getReplyTo());
        decodedMessage.put(MSG_TIMESTAMP, properties.getTimestamp());
        decodedMessage.put(MSG_TYPE, properties.getType());
        decodedMessage.put(MSG_RBQ_USER_ID, properties.getUserId());
        Map<String, Object> headerFields = properties.getHeaders();
        if (headerFields != null) {
            for (String key : headerFields.keySet())
                if (headerFields.get(key) != null) {
                    if (headerFields.get(key) instanceof LongString)
                        decodedMessage.put(key, headerFields.get(key).toString());
                    else
                        decodedMessage.put(key, headerFields.get(key));
                } else
                    decodedMessage.put(key, headerFields.get(key));
        }
    }

    if (body.length == 0)
        decodedMessage.put(MSG_BODY, null);
    else
        decodedMessage.put(MSG_BODY, body);

    return decodedMessage;
}

From source file:org.apache.axis2.transport.amqp.common.AMQPUtils.java

License:Apache License

/**
 * Set the SOAPEnvelope to the Axis2 MessageContext, from the AMQP Message
 * passed in/*from   www.j  ava  2  s.c om*/
 * 
 * @param message
 *            the AMQP message read
 * @param msgContext
 *            the Axis2 MessageContext to be populated
 * @param contentType
 *            content type for the message
 * @throws AxisFault
 * @throws AMQPException
 */
public static void setSOAPEnvelope(AMQPMessage message, MessageContext msgContext, String contentType)
        throws AxisFault, AMQPException {
    BasicProperties msg_prop = message.getProperties();

    if (contentType == null) {
        contentType = msg_prop.getContentType();
        log.debug("No content type specified; assuming " + contentType);

    }

    int index = contentType.indexOf(';');
    String type = index > 0 ? contentType.substring(0, index) : contentType;
    Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
    if (builder == null) {
        if (log.isDebugEnabled()) {
            log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
        }
        builder = new SOAPBuilder();
    }

    OMElement documentElement;
    if (contentType.equals("application/octet-stream")) {
        // Extract the charset encoding from the content type and
        // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder
        // relies on this.
        String charSetEnc = null;
        try {
            if (contentType != null) {
                charSetEnc = new ContentType(contentType).getParameter("charset");
            }
        } catch (ParseException ex) {
            // ignore
        }
        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);

        if (builder instanceof DataSourceMessageBuilder) {
            documentElement = ((DataSourceMessageBuilder) builder)
                    .processDocument(new ByteArrayInputStream(message.getBody()), contentType, msgContext);
        } else {
            documentElement = builder.processDocument(new ByteArrayInputStream(message.getBody()), contentType,
                    msgContext);
        }
    } else if (contentType.equals("text/plain")) {
        TextMessageBuilder textMessageBuilder;
        if (builder instanceof TextMessageBuilder) {
            textMessageBuilder = (TextMessageBuilder) builder;
        } else {
            textMessageBuilder = new TextMessageBuilderAdapter(builder);
        }
        String content = new String(message.getBody());
        documentElement = textMessageBuilder.processDocument(content, contentType, msgContext);
    } else {
        handleException("Unsupported AMQP message type " + message.getClass().getName());
        return; // Make compiler happy
    }
    msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}

From source file:org.eclipse.ditto.services.connectivity.messaging.rabbitmq.RabbitMQConsumerActor.java

License:Open Source License

private void handleDelivery(final Delivery delivery) {
    final BasicProperties properties = delivery.getProperties();
    final Envelope envelope = delivery.getEnvelope();
    final byte[] body = delivery.getBody();
    final String hashKey = envelope.getExchange() + ":" + envelope.getRoutingKey();

    Map<String, String> headers = null;
    try {/*w ww . j a  va  2  s. c  o  m*/
        final String correlationId = properties.getCorrelationId();
        LogUtil.enhanceLogWithCorrelationId(log, correlationId);
        if (log.isDebugEnabled()) {
            log.debug("Received message from RabbitMQ ({}//{}): {}", envelope, properties,
                    new String(body, StandardCharsets.UTF_8));
        }
        headers = extractHeadersFromMessage(properties, envelope);
        final ExternalMessageBuilder externalMessageBuilder = ExternalMessageFactory
                .newExternalMessageBuilder(headers);
        final String contentType = properties.getContentType();
        final String text = new String(body, CharsetDeterminer.getInstance().apply(contentType));
        if (shouldBeInterpretedAsBytes(contentType)) {
            externalMessageBuilder.withBytes(body);
        } else {
            externalMessageBuilder.withTextAndBytes(text, body);
        }
        externalMessageBuilder.withAuthorizationContext(authorizationContext);
        externalMessageBuilder.withEnforcement(headerEnforcementFilterFactory.getFilter(headers));
        externalMessageBuilder.withHeaderMapping(headerMapping);
        externalMessageBuilder.withSourceAddress(sourceAddress);
        final ExternalMessage externalMessage = externalMessageBuilder.build();
        inboundMonitor.success(externalMessage);
        forwardToMappingActor(externalMessage, hashKey);
    } catch (final DittoRuntimeException e) {
        log.warning("Processing delivery {} failed: {}", envelope.getDeliveryTag(), e.getMessage());
        if (headers != null) {
            // send response if headers were extracted successfully
            forwardToMappingActor(e.setDittoHeaders(DittoHeaders.of(headers)), hashKey);
            inboundMonitor.failure(headers, e);
        } else {
            inboundMonitor.failure(e);
        }
    } catch (final Exception e) {
        log.warning("Processing delivery {} failed: {}", envelope.getDeliveryTag(), e.getMessage());
        if (headers != null) {
            inboundMonitor.exception(headers, e);
        } else {
            inboundMonitor.exception(e);
        }
    }
}

From source file:org.eclipse.ditto.services.connectivity.messaging.rabbitmq.RabbitMQConsumerActor.java

License:Open Source License

private static Map<String, String> extractHeadersFromMessage(final BasicProperties properties,
        final Envelope envelope) {

    final Map<String, String> headersFromProperties = getHeadersFromProperties(properties.getHeaders());

    // set headers specific to rmq messages
    if (properties.getReplyTo() != null) {
        headersFromProperties.put(ExternalMessage.REPLY_TO_HEADER, properties.getReplyTo());
    }//from   w  w  w .ja  va 2s.  co  m
    if (properties.getCorrelationId() != null) {
        headersFromProperties.put(DittoHeaderDefinition.CORRELATION_ID.getKey(), properties.getCorrelationId());
    }
    if (properties.getContentType() != null) {
        headersFromProperties.put(ExternalMessage.CONTENT_TYPE_HEADER, properties.getContentType());
    }
    headersFromProperties.put(MESSAGE_ID_HEADER, Long.toString(envelope.getDeliveryTag()));

    return headersFromProperties;
}

From source file:org.kairosdb.plugin.rabbitmq.core.RabbitmqConsumer.java

License:MIT License

/**
 * Consumes and save messages in KairosDB.
 * /*from   w  w  w  . jav a  2s  . com*/
 * @param routingKey
 *            the routing key
 * @param body
 *            the body
 * @param props
 *            the props
 */
private void consumeMessage(String routingKey, byte[] body, BasicProperties props) {

    try {

        // KairosDB Metric name = RMQ RoutingKey
        String metricName = routingKey;

        Validator.validateNotNullOrEmpty("metricName", metricName);

        // Gets consumer implementation
        ConsumerFactory factory = new ConsumerFactory(fieldValue, fieldTimestamp, fieldTags, seperator);
        Consumer consumer = factory.getConsumer(props.getContentType(), defaultContentType);

        // Consumes message
        if (consumer.consume(body)) {

            String value = consumer.getValue();
            Long timestamp = consumer.getTimestamp();

            // Hold data point in a set
            DataPointSet dps = new DataPointSet(metricName);

            // Construct Data Point
            if (NumberUtils.isNumber(value)) {
                if (value.contains(".")) {
                    dps.addDataPoint(new DoubleDataPoint(timestamp, Double.parseDouble(value)));
                } else {
                    dps.addDataPoint(new LongDataPoint(timestamp, Util.parseLong(value)));
                }
            } else {
                throw new IllegalArgumentException("The value of the consumed message is not a number.");
            }

            // Get Tags
            Map<String, String> tags = consumer.getTags();
            for (Map.Entry<String, String> entry : tags.entrySet())
                dps.addTag(entry.getKey(), entry.getValue());

            // Push Data Points
            for (DataPoint dataPoint : dps.getDataPoints()) {
                datastore.putDataPoint(dps.getName(), dps.getTags(), dataPoint);
            }

            LOGGER.debug("[KRMQ] Message consumed:" + "\n  Metric: " + metricName + "\n  Datapoints: " + dps
                    + "\n  Tags: " + tags + "\n  ContentType: " + props.getContentType() + "\n  Consumer: "
                    + consumer.getClass().getName() + "\n  Message: " + new String(body, "UTF-8"));

        } else {

            LOGGER.debug("[KRMQ] Message was not consumed due to incorrect format:" + "\n  RoutingKey: "
                    + routingKey + "\n  Message: " + new String(body, "UTF-8"));

        }

    } catch (InvalidContentType | DatastoreException | ValidationException | UnsupportedEncodingException e) {
        LOGGER.error("[KRMQ] An error occurred: ", e);
    }

}

From source file:org.mule.transport.amqp.AmqpMuleMessageFactory.java

License:Open Source License

private void addBasicProperties(final DefaultMuleMessage muleMessage,
        final Map<String, Object> messageProperties, final BasicProperties amqpProperties) {
    if (amqpProperties == null)
        return;//from  w w  w  .  ja v a2s.c o  m

    putIfNonNull(messageProperties, AmqpConstants.APP_ID, amqpProperties.getAppId());
    putIfNonNull(messageProperties, AmqpConstants.CONTENT_ENCODING, amqpProperties.getContentEncoding());
    putIfNonNull(messageProperties, AmqpConstants.CONTENT_TYPE, amqpProperties.getContentType());

    final String correlationId = amqpProperties.getCorrelationId();
    putIfNonNull(messageProperties, AmqpConstants.CORRELATION_ID, correlationId);
    putIfNonNull(messageProperties, MuleProperties.MULE_CORRELATION_ID_PROPERTY, correlationId);
    muleMessage.setCorrelationId(correlationId);

    putIfNonNull(messageProperties, AmqpConstants.DELIVERY_MODE, amqpProperties.getDeliveryMode());
    putIfNonNull(messageProperties, AmqpConstants.EXPIRATION, amqpProperties.getExpiration());

    final String messageId = amqpProperties.getMessageId();
    putIfNonNull(messageProperties, AmqpConstants.MESSAGE_ID, messageId);
    putIfNonNull(messageProperties, MuleProperties.MULE_MESSAGE_ID_PROPERTY, messageId);
    muleMessage.setUniqueId(messageId);

    putIfNonNull(messageProperties, AmqpConstants.PRIORITY, amqpProperties.getPriority());

    final String replyTo = amqpProperties.getReplyTo();
    putIfNonNull(messageProperties, AmqpConstants.REPLY_TO, replyTo);
    muleMessage.setReplyTo(replyTo);

    putIfNonNull(messageProperties, AmqpConstants.TIMESTAMP, amqpProperties.getTimestamp());
    putIfNonNull(messageProperties, AmqpConstants.TYPE, amqpProperties.getType());
    putIfNonNull(messageProperties, AmqpConstants.USER_ID, amqpProperties.getUserId());

    messageProperties.putAll(amqpProperties.getHeaders());
}

From source file:org.mule.transport.amqp.AmqpMuleMessageFactoryTestCase.java

License:Open Source License

public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) {
    assertEquals(amqpMessage.getConsumerTag(),
            muleMessage.getProperty(AmqpConstants.CONSUMER_TAG, PropertyScope.INBOUND));

    final Envelope envelope = amqpMessage.getEnvelope();
    assertEquals(envelope.getDeliveryTag(),
            muleMessage.getProperty(AmqpConstants.DELIVERY_TAG, PropertyScope.INBOUND));
    assertEquals(envelope.isRedeliver(),
            muleMessage.getProperty(AmqpConstants.REDELIVER, PropertyScope.INBOUND));
    assertEquals(envelope.getExchange(),
            muleMessage.getProperty(AmqpConstants.EXCHANGE, PropertyScope.INBOUND));
    assertEquals(envelope.getRoutingKey(),
            muleMessage.getProperty(AmqpConstants.ROUTING_KEY, PropertyScope.INBOUND));

    final BasicProperties amqpProperties = amqpMessage.getProperties();
    assertEquals(amqpProperties.getAppId(),
            muleMessage.getProperty(AmqpConstants.APP_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentEncoding(),
            muleMessage.getProperty(AmqpConstants.CONTENT_ENCODING, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentType(),
            muleMessage.getProperty(AmqpConstants.CONTENT_TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(),
            muleMessage.getProperty(AmqpConstants.CORRELATION_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId());
    assertEquals(amqpProperties.getDeliveryMode(),
            muleMessage.getProperty(AmqpConstants.DELIVERY_MODE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getExpiration(),
            muleMessage.getProperty(AmqpConstants.EXPIRATION, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(),
            muleMessage.getProperty(AmqpConstants.MESSAGE_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId());
    assertEquals(amqpProperties.getPriority(),
            muleMessage.getProperty(AmqpConstants.PRIORITY, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(),
            muleMessage.getProperty(AmqpConstants.REPLY_TO, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo());
    assertEquals(amqpProperties.getTimestamp(),
            muleMessage.getProperty(AmqpConstants.TIMESTAMP, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getType(), muleMessage.getProperty(AmqpConstants.TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getUserId(),
            muleMessage.getProperty(AmqpConstants.USER_ID, PropertyScope.INBOUND));

    for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) {
        assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND));
    }/*from www  .ja  v  a 2 s  .c om*/
}

From source file:org.mule.transport.amqp.internal.domain.AmqpMuleMessageFactory.java

License:Open Source License

private void addBasicProperties(final BasicProperties amqpProperties, final DefaultMuleMessage muleMessage,
        final Map<String, Object> messageProperties) {
    if (amqpProperties == null)
        return;/*from ww w  .j a va2s. c  om*/

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_APP_ID, amqpProperties.getAppId(), messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CONTENT_ENCODING, amqpProperties.getContentEncoding(),
            messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CONTENT_TYPE, amqpProperties.getContentType(),
            messageProperties);

    final String correlationId = amqpProperties.getCorrelationId();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CORRELATION_ID, correlationId, messageProperties);
    putIfNonNull(MuleProperties.MULE_CORRELATION_ID_PROPERTY, correlationId, messageProperties);
    muleMessage.setCorrelationId(correlationId);

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_MODE, amqpProperties.getDeliveryMode(),
            messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_EXPIRATION, amqpProperties.getExpiration(), messageProperties);

    final String messageId = amqpProperties.getMessageId();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_MESSAGE_ID, messageId, messageProperties);
    putIfNonNull(MuleProperties.MULE_MESSAGE_ID_PROPERTY, messageId, messageProperties);
    muleMessage.setUniqueId(messageId == null ? UUID.getUUID() : messageId);

    final String clusterId = amqpProperties.getClusterId();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CLUSTER_ID, clusterId, messageProperties);

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_PRIORITY, amqpProperties.getPriority(), messageProperties);

    final String replyTo = amqpProperties.getReplyTo();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_REPLY_TO, replyTo, messageProperties);
    muleMessage.setReplyTo(replyTo);

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_TIMESTAMP, amqpProperties.getTimestamp(), messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_TYPE, amqpProperties.getType(), messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_USER_ID, amqpProperties.getUserId(), messageProperties);
}

From source file:org.mule.transport.amqp.internal.domain.AmqpMuleMessageFactoryTestCase.java

License:Open Source License

public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) {
    assertEquals(amqpMessage.getConsumerTag(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONSUMER_TAG, PropertyScope.INBOUND));

    final Envelope envelope = amqpMessage.getEnvelope();
    assertEquals(envelope.getDeliveryTag(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_TAG, PropertyScope.INBOUND));
    assertEquals(envelope.isRedeliver(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REDELIVER, PropertyScope.INBOUND));
    assertEquals(envelope.getExchange(),
            muleMessage.getProperty(AmqpConnector.EXCHANGE, PropertyScope.INBOUND));
    assertEquals(envelope.getRoutingKey(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_ROUTING_KEY, PropertyScope.INBOUND));

    final BasicProperties amqpProperties = amqpMessage.getProperties();
    assertEquals(amqpProperties.getAppId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_APP_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentEncoding(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_ENCODING, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentType(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getClusterId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CLUSTER_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CORRELATION_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId());
    assertEquals(amqpProperties.getDeliveryMode(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_MODE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getExpiration(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_EXPIRATION, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_MESSAGE_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId());
    assertEquals(amqpProperties.getPriority(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_PRIORITY, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REPLY_TO, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo());
    assertEquals(amqpProperties.getTimestamp(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TIMESTAMP, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getType(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getUserId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_USER_ID, PropertyScope.INBOUND));

    for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) {
        assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND));
    }/*ww w .j a v a 2 s.  co m*/
}

From source file:org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter.java

License:Apache License

public MessageProperties toMessageProperties(final BasicProperties source, final Envelope envelope,
        final String charset) {
    MessageProperties target = new MessageProperties();
    Map<String, Object> headers = source.getHeaders();
    if (!CollectionUtils.isEmpty(headers)) {
        for (Map.Entry<String, Object> entry : headers.entrySet()) {
            Object value = entry.getValue();
            if (value instanceof LongString) {
                value = this.convertLongString((LongString) value, charset);
            }//from   ww  w  . j av  a  2s  .  c om
            target.setHeader(entry.getKey(), value);
        }
    }
    target.setTimestamp(source.getTimestamp());
    target.setMessageId(source.getMessageId());
    target.setUserId(source.getUserId());
    target.setAppId(source.getAppId());
    target.setClusterId(source.getClusterId());
    target.setType(source.getType());
    Integer deliverMode = source.getDeliveryMode();
    if (deliverMode != null) {
        target.setDeliveryMode(MessageDeliveryMode.fromInt(deliverMode));
    }
    target.setExpiration(source.getExpiration());
    target.setPriority(source.getPriority());
    target.setContentType(source.getContentType());
    target.setContentEncoding(source.getContentEncoding());
    String correlationId = source.getCorrelationId();
    if (correlationId != null) {
        try {
            target.setCorrelationId(source.getCorrelationId().getBytes(charset));
        } catch (UnsupportedEncodingException ex) {
            throw new AmqpUnsupportedEncodingException(ex);
        }
    }
    String replyTo = source.getReplyTo();
    if (replyTo != null) {
        target.setReplyTo(replyTo);
    }
    if (envelope != null) {
        target.setReceivedExchange(envelope.getExchange());
        target.setReceivedRoutingKey(envelope.getRoutingKey());
        target.setRedelivered(envelope.isRedeliver());
        target.setDeliveryTag(envelope.getDeliveryTag());
    }
    return target;
}