use of org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo in project qpid-broker-j by apache.
the class MessageConverter_0_8_to_1_0 method convertMetaData.
@Override
protected MessageMetaData_1_0 convertMetaData(final AMQMessage serverMessage, final EncodingRetainingSection<?> bodySection, SectionEncoder sectionEncoder) {
Header header = new Header();
Properties props = new Properties();
header.setDurable(serverMessage.isPersistent());
BasicContentHeaderProperties contentHeader = serverMessage.getContentHeaderBody().getProperties();
header.setPriority(UnsignedByte.valueOf(contentHeader.getPriority()));
if (contentHeader.hasExpiration()) {
final long expiration = serverMessage.getExpiration();
final long arrivalTime = serverMessage.getArrivalTime();
header.setTtl(UnsignedInteger.valueOf(Math.max(0, expiration - arrivalTime)));
}
if (!GZIPUtils.GZIP_CONTENT_ENCODING.equals(contentHeader.getEncodingAsString()) && bodySection instanceof DataSection) {
props.setContentEncoding(Symbol.valueOf(contentHeader.getEncodingAsString()));
}
Symbol contentType = getContentType(contentHeader.getContentTypeAsString());
props.setContentType(contentType);
final AMQShortString correlationId = contentHeader.getCorrelationId();
if (correlationId != null) {
final byte[] correlationIdAsBytes = correlationId.getBytes();
final String correlationIdAsString = contentHeader.getCorrelationIdAsString();
if (Arrays.equals(correlationIdAsBytes, correlationIdAsString.getBytes(StandardCharsets.UTF_8))) {
props.setCorrelationId(correlationIdAsString);
} else {
props.setCorrelationId(correlationIdAsBytes);
}
}
final AMQShortString messageId = contentHeader.getMessageId();
if (messageId != null) {
props.setMessageId(messageId.toString());
}
if (contentHeader.getReplyTo() != null) {
props.setReplyTo(convertReplyTo(contentHeader.getReplyTo()));
}
if (contentHeader.getUserId() != null) {
props.setUserId(new Binary(contentHeader.getUserId().getBytes()));
}
if (contentHeader.hasTimestamp()) {
props.setCreationTime(new Date(contentHeader.getTimestamp()));
} else {
props.setCreationTime(new Date(serverMessage.getArrivalTime()));
}
if (contentHeader.getType() != null) {
props.setSubject(contentHeader.getType().toString());
}
Map<String, Object> applicationPropertiesMap = new LinkedHashMap<>(FieldTable.convertToMap(contentHeader.getHeaders()));
if (applicationPropertiesMap.containsKey("qpid.subject")) {
props.setSubject(String.valueOf(applicationPropertiesMap.get("qpid.subject")));
applicationPropertiesMap.remove("qpid.subject");
}
if (applicationPropertiesMap.containsKey("JMSXGroupID")) {
props.setGroupId(String.valueOf(applicationPropertiesMap.get("JMSXGroupID")));
applicationPropertiesMap.remove("JMSXGroupID");
}
if (applicationPropertiesMap.containsKey("JMSXGroupSeq")) {
Object jmsxGroupSeq = applicationPropertiesMap.get("JMSXGroupSeq");
if (jmsxGroupSeq instanceof Integer) {
props.setGroupSequence(UnsignedInteger.valueOf((Integer) jmsxGroupSeq));
applicationPropertiesMap.remove("JMSXGroupSeq");
}
}
MessagePublishInfo messagePublishInfo = serverMessage.getMessagePublishInfo();
String to = AMQShortString.toString(messagePublishInfo.getExchange());
if (messagePublishInfo.getRoutingKey() != null) {
String routingKey = AMQShortString.toString(messagePublishInfo.getRoutingKey());
if (to != null && !"".equals(to)) {
to += "/" + routingKey;
} else {
to = routingKey;
}
}
props.setTo(to);
final ApplicationProperties applicationProperties;
try {
applicationProperties = new ApplicationProperties(applicationPropertiesMap);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-8 to 1.0 because headers conversion failed.", e);
}
MessageAnnotations messageAnnotations = createMessageAnnotation(bodySection, contentHeader.getContentTypeAsString());
return new MessageMetaData_1_0(header.createEncodingRetainingSection(), null, messageAnnotations == null ? null : messageAnnotations.createEncodingRetainingSection(), props.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), null, serverMessage.getArrivalTime(), bodySection.getEncodedSize());
}
use of org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8 method createMessagePublishInfo.
private MessagePublishInfo createMessagePublishInfo(final MessageMetaData_1_0.MessageHeader_1_0 header, final NamedAddressSpace addressSpace) {
final String to = header.getTo();
final String subject = header.getSubject() == null ? "" : header.getSubject();
final String exchangeName;
final String routingKey;
if (to != null && !"".equals(to)) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination instanceof Queue) {
exchangeName = "";
routingKey = messageDestination.getName();
} else if (messageDestination instanceof Exchange) {
exchangeName = messageDestination.getName();
routingKey = "".equals(destinationAddress.getRoutingKey()) ? subject : destinationAddress.getRoutingKey();
} else {
exchangeName = "";
routingKey = to;
}
} else {
exchangeName = "";
routingKey = subject;
}
return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
use of org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo in project qpid-broker-j by apache.
the class MessageFormat_0_9_1 method convertToMessageFormat.
@Override
public QpidByteBuffer convertToMessageFormat(final AMQMessage message) {
final MessagePublishInfo messagePublishInfo = message.getMessagePublishInfo();
final ContentHeaderBody contentHeaderBody = message.getContentHeaderBody();
AMQShortString exchange = messagePublishInfo.getExchange();
AMQShortString routingKey = messagePublishInfo.getRoutingKey();
int length = contentHeaderBody.getSize() + (exchange == null ? 0 : exchange.length()) + (routingKey == null ? 0 : routingKey.length()) + 3;
try (QpidByteBuffer headerBuf = QpidByteBuffer.allocateDirect(length);
QpidByteBuffer content = message.getContent()) {
EncodingUtils.writeShortStringBytes(headerBuf, exchange);
EncodingUtils.writeShortStringBytes(headerBuf, routingKey);
byte flags = messagePublishInfo.isMandatory() ? (byte) 0 : MANDATORY_MASK;
if (messagePublishInfo.isImmediate()) {
flags |= IMMEDIATE_MASK;
}
headerBuf.put(flags);
headerBuf.flip();
contentHeaderBody.writePayload(headerBuf);
return QpidByteBuffer.concatenate(headerBuf, content);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo in project qpid-broker-j by apache.
the class ProtocolOutputConverterImpl method createEncodedDeliverBody.
private AMQBody createEncodedDeliverBody(AMQMessage message, boolean isRedelivered, final long deliveryTag, final AMQShortString consumerTag) {
final AMQShortString exchangeName;
final AMQShortString routingKey;
final MessagePublishInfo pb = message.getMessagePublishInfo();
exchangeName = pb.getExchange();
routingKey = pb.getRoutingKey();
return new EncodedDeliveryBody(deliveryTag, routingKey, exchangeName, consumerTag, isRedelivered);
}
use of org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo in project qpid-broker-j by apache.
the class MessageConverter_0_8_to_InternalTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
when(_handle.getMetaData()).thenReturn(_metaData);
when(_metaData.getMessageHeader()).thenReturn(_header);
when(_metaData.getMessagePublishInfo()).thenReturn(new MessagePublishInfo());
when(_metaData.getContentHeaderBody()).thenReturn(_contentHeaderBody);
when(_contentHeaderBody.getProperties()).thenReturn(_basicContentHeaderProperties);
}
Aggregations