use of org.apache.qpid.server.protocol.v1_0.type.messaging.Header in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testDurableConversion.
@Test
public void testDurableConversion() {
final Header header = new Header();
header.setDurable(true);
Message_1_0 message = createTestMessage(header);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final DeliveryProperties deliveryProperties = convertedMessage.getStoredMessage().getMetaData().getDeliveryProperties();
assertEquals("Unexpected deliveryMode", MessageDeliveryMode.PERSISTENT, deliveryProperties.getDeliveryMode());
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Header in project qpid-broker-j by apache.
the class PropertyConverter_0_8_to_1_0Test method testPriorityConversion.
@Test
public void testPriorityConversion() {
BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
final byte priority = 5;
basicContentHeaderProperties.setPriority(priority);
AMQMessage message = createTestMessage(basicContentHeaderProperties);
final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
Header header = convertedMessage.getHeaderSection().getValue();
assertEquals("Unexpected priority", (long) priority, (long) header.getPriority().byteValue());
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Header in project qpid-broker-j by apache.
the class PropertyConverter_0_8_to_1_0Test method testExpirationConversion.
@Test
public void testExpirationConversion() {
BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
long timestamp = System.currentTimeMillis();
int ttl = 100000;
final long expiration = timestamp + ttl;
basicContentHeaderProperties.setExpiration(expiration);
AMQMessage message = createTestMessage(basicContentHeaderProperties, timestamp);
final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
Header header = convertedMessage.getHeaderSection().getValue();
assertEquals("Unexpected TTL", (long) ttl, header.getTtl().longValue());
Properties properties = convertedMessage.getPropertiesSection().getValue();
assertNull("Unexpected expiration", properties.getAbsoluteExpiryTime());
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Header in project qpid-broker-j by apache.
the class MessageConverter_0_10_to_1_0 method convertMetaData.
@Override
protected MessageMetaData_1_0 convertMetaData(MessageTransferMessage serverMessage, final EncodingRetainingSection<?> bodySection, SectionEncoder sectionEncoder) {
Properties props = new Properties();
props.setCreationTime(new Date(serverMessage.getArrivalTime()));
final MessageProperties msgProps = serverMessage.getHeader().getMessageProperties();
final DeliveryProperties deliveryProps = serverMessage.getHeader().getDeliveryProperties();
Header header = new Header();
if (deliveryProps != null) {
header.setDurable(deliveryProps.hasDeliveryMode() && deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT);
if (deliveryProps.hasPriority()) {
header.setPriority(UnsignedByte.valueOf((byte) deliveryProps.getPriority().getValue()));
}
if (deliveryProps.hasTtl()) {
header.setTtl(UnsignedInteger.valueOf(deliveryProps.getTtl()));
} else if (deliveryProps.hasExpiration()) {
long ttl = Math.max(0, deliveryProps.getExpiration() - serverMessage.getArrivalTime());
header.setTtl(UnsignedInteger.valueOf(ttl));
}
if (deliveryProps.hasTimestamp()) {
props.setCreationTime(new Date(deliveryProps.getTimestamp()));
}
String to = deliveryProps.getExchange();
if (deliveryProps.getRoutingKey() != null) {
String routingKey = deliveryProps.getRoutingKey();
if (to != null && !"".equals(to)) {
to += "/" + routingKey;
} else {
to = routingKey;
}
}
props.setTo(to);
}
ApplicationProperties applicationProperties = null;
String originalContentMimeType = null;
if (msgProps != null) {
if (msgProps.hasContentEncoding() && !GZIPUtils.GZIP_CONTENT_ENCODING.equals(msgProps.getContentEncoding()) && bodySection instanceof DataSection) {
props.setContentEncoding(Symbol.valueOf(msgProps.getContentEncoding()));
}
if (msgProps.hasCorrelationId()) {
CharsetDecoder charsetDecoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
try {
String correlationIdAsString = charsetDecoder.decode(ByteBuffer.wrap(msgProps.getCorrelationId())).toString();
props.setCorrelationId(correlationIdAsString);
} catch (CharacterCodingException e) {
props.setCorrelationId(new Binary(msgProps.getCorrelationId()));
}
}
if (msgProps.hasMessageId()) {
props.setMessageId(msgProps.getMessageId());
}
if (msgProps.hasReplyTo()) {
ReplyTo replyTo = msgProps.getReplyTo();
String to = null;
if (replyTo.hasExchange() && !"".equals(replyTo.getExchange())) {
to = replyTo.getExchange();
}
if (replyTo.hasRoutingKey()) {
if (to != null) {
to += "/" + replyTo.getRoutingKey();
} else {
to = replyTo.getRoutingKey();
}
}
props.setReplyTo(to);
}
if (msgProps.hasContentType()) {
originalContentMimeType = msgProps.getContentType();
final Symbol contentType = MessageConverter_to_1_0.getContentType(originalContentMimeType);
props.setContentType(contentType);
}
if (msgProps.hasUserId()) {
props.setUserId(new Binary(msgProps.getUserId()));
}
Map<String, Object> applicationPropertiesMap = msgProps.getApplicationHeaders();
if (applicationPropertiesMap != null) {
applicationPropertiesMap = new LinkedHashMap<>(applicationPropertiesMap);
if (applicationPropertiesMap.containsKey("x-jms-type")) {
props.setSubject(String.valueOf(applicationPropertiesMap.get("x-jms-type")));
applicationPropertiesMap.remove("x-jms-type");
}
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");
}
}
try {
applicationProperties = new ApplicationProperties(applicationPropertiesMap);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 1.0 because application headers conversion failed.", e);
}
}
}
final MessageAnnotations messageAnnotation = MessageConverter_to_1_0.createMessageAnnotation(bodySection, originalContentMimeType);
return new MessageMetaData_1_0(header.createEncodingRetainingSection(), null, messageAnnotation == null ? null : messageAnnotation.createEncodingRetainingSection(), props.createEncodingRetainingSection(), applicationProperties == null ? null : applicationProperties.createEncodingRetainingSection(), null, serverMessage.getArrivalTime(), bodySection.getEncodedSize());
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Header in project qpid-broker-j by apache.
the class Utils method splitPayload.
public static QpidByteBuffer[] splitPayload(final String messageContent, int numberOfParts) {
MessageEncoder messageEncoder = new MessageEncoder();
final Header header = new Header();
messageEncoder.setHeader(header);
messageEncoder.addData(messageContent);
final QpidByteBuffer[] result;
try (QpidByteBuffer payload = messageEncoder.getPayload()) {
long size = (long) payload.remaining();
result = new QpidByteBuffer[numberOfParts];
int chunkSize = (int) size / numberOfParts;
int lastChunkSize = (int) size - chunkSize * (numberOfParts - 1);
for (int i = 0; i < numberOfParts; i++) {
result[i] = QpidByteBuffer.allocate(false, i == numberOfParts - 1 ? lastChunkSize : chunkSize);
final int remaining = result[i].remaining();
try (QpidByteBuffer view = payload.view(0, remaining)) {
result[i].put(view);
}
result[i].flip();
payload.position(payload.position() + remaining);
}
}
return result;
}
Aggregations