use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection in project qpid-broker-j by apache.
the class MessageConverter_from_1_0 method getJmsMessageTypeAnnotation.
static JmsMessageTypeAnnotation getJmsMessageTypeAnnotation(final Message_1_0 serverMsg) {
JmsMessageTypeAnnotation jmsMessageTypeAnnotation = null;
MessageAnnotationsSection section = serverMsg.getMessageAnnotationsSection();
if (section != null) {
Map<Symbol, Object> annotations = section.getValue();
section.dispose();
if (annotations != null && annotations.containsKey(JmsMessageTypeAnnotation.ANNOTATION_KEY)) {
Object object = annotations.get(JmsMessageTypeAnnotation.ANNOTATION_KEY);
if (object instanceof Byte) {
try {
jmsMessageTypeAnnotation = JmsMessageTypeAnnotation.valueOf(((Byte) object));
} catch (IllegalArgumentException e) {
// ignore
}
}
}
}
return jmsMessageTypeAnnotation;
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection in project qpid-broker-j by apache.
the class ConsumerTarget_1_0Test method createTestMessage.
private Message_1_0 createTestMessage(final Header header, long arrivalTime) {
DeliveryAnnotationsSection deliveryAnnotations = new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
MessageAnnotationsSection messageAnnotations = new MessageAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
ApplicationPropertiesSection applicationProperties = new ApplicationProperties(Collections.emptyMap()).createEncodingRetainingSection();
FooterSection footer = new Footer(Collections.emptyMap()).createEncodingRetainingSection();
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations, messageAnnotations, new Properties().createEncodingRetainingSection(), applicationProperties, footer, arrivalTime, 0);
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
when(storedMessage.getContent(eq(0), anyInt())).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
when(storedMessage.getMetaData()).thenReturn(metaData);
return new Message_1_0(storedMessage);
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection in project qpid-broker-j by apache.
the class MessageDecoder method parse.
public void parse() throws AmqpErrorException {
if (!_parsed) {
List<EncodingRetainingSection<?>> sections;
try (QpidByteBuffer combined = QpidByteBuffer.concatenate(_fragments)) {
sections = _sectionDecoder.parseAll(combined);
}
_fragments.forEach(QpidByteBuffer::dispose);
Iterator<EncodingRetainingSection<?>> iter = sections.iterator();
EncodingRetainingSection<?> s = iter.hasNext() ? iter.next() : null;
if (s instanceof HeaderSection) {
_headerSection = (HeaderSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof DeliveryAnnotationsSection) {
_deliveryAnnotationsSection = (DeliveryAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof MessageAnnotationsSection) {
_messageAnnotationsSection = (MessageAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof PropertiesSection) {
_propertiesSection = (PropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof ApplicationPropertiesSection) {
_applicationPropertiesSection = (ApplicationPropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof AmqpValueSection) {
_contentSize = s.getEncodedSize();
_dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} else if (s instanceof DataSection) {
do {
_contentSize += s.getEncodedSize();
_dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof DataSection);
} else if (s instanceof AmqpSequenceSection) {
do {
_contentSize += s.getEncodedSize();
_dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof AmqpSequenceSection);
}
if (s instanceof FooterSection) {
_footerSection = (FooterSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s != null) {
throw new IllegalStateException(String.format("Encountered unexpected section '%s'", s.getClass().getSimpleName()));
}
_parsed = true;
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection in project qpid-broker-j by apache.
the class MessageFormat_1_0 method createMessageMetaData.
private MessageMetaData_1_0 createMessageMetaData(final List<EncodingRetainingSection<?>> allSections, final List<EncodingRetainingSection<?>> dataSections) {
long contentSize = 0L;
HeaderSection headerSection = null;
PropertiesSection propertiesSection = null;
DeliveryAnnotationsSection deliveryAnnotationsSection = null;
MessageAnnotationsSection messageAnnotationsSection = null;
ApplicationPropertiesSection applicationPropertiesSection = null;
FooterSection footerSection = null;
Iterator<EncodingRetainingSection<?>> iter = allSections.iterator();
EncodingRetainingSection<?> s = iter.hasNext() ? iter.next() : null;
if (s instanceof HeaderSection) {
headerSection = (HeaderSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof DeliveryAnnotationsSection) {
deliveryAnnotationsSection = (DeliveryAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof MessageAnnotationsSection) {
messageAnnotationsSection = (MessageAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof PropertiesSection) {
propertiesSection = (PropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof ApplicationPropertiesSection) {
applicationPropertiesSection = (ApplicationPropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof AmqpValueSection) {
contentSize = s.getEncodedSize();
dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} else if (s instanceof DataSection) {
do {
contentSize += s.getEncodedSize();
dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof DataSection);
} else if (s instanceof AmqpSequenceSection) {
do {
contentSize += s.getEncodedSize();
dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof AmqpSequenceSection);
}
if (s instanceof FooterSection) {
footerSection = (FooterSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s != null) {
throw new ConnectionScopedRuntimeException(String.format("Encountered unexpected section '%s'", s.getClass().getSimpleName()));
}
return new MessageMetaData_1_0(headerSection, deliveryAnnotationsSection, messageAnnotationsSection, propertiesSection, applicationPropertiesSection, footerSection, System.currentTimeMillis(), contentSize);
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection in project qpid-broker-j by apache.
the class Message_1_0_Mutator method create.
@Override
public Message_1_0 create() {
final long contentSize = _message.getSize();
HeaderSection headerSection = null;
if (_header != null) {
headerSection = _header.createEncodingRetainingSection();
}
DeliveryAnnotationsSection deliveryAnnotationsSection = null;
if (_deliveryAnnotations != null) {
deliveryAnnotationsSection = new DeliveryAnnotations(_deliveryAnnotations).createEncodingRetainingSection();
}
MessageAnnotationsSection messageAnnotationsSection = null;
if (_messageAnnotations != null) {
messageAnnotationsSection = new MessageAnnotations(_messageAnnotations).createEncodingRetainingSection();
}
PropertiesSection propertiesSection = null;
if (_properties != null) {
propertiesSection = _properties.createEncodingRetainingSection();
}
ApplicationPropertiesSection applicationPropertiesSection = null;
if (_applicationProperties != null) {
applicationPropertiesSection = new ApplicationProperties(_applicationProperties).createEncodingRetainingSection();
}
FooterSection footerSection = null;
if (_footer != null) {
footerSection = new Footer(_footer).createEncodingRetainingSection();
}
final QpidByteBuffer content = _message.getContent();
final MessageMetaData_1_0 mmd = new MessageMetaData_1_0(headerSection, deliveryAnnotationsSection, messageAnnotationsSection, propertiesSection, applicationPropertiesSection, footerSection, _message.getArrivalTime(), contentSize);
final MessageHandle<MessageMetaData_1_0> handle = _messageStore.addMessage(mmd);
if (content != null) {
handle.addContent(content);
}
return new Message_1_0(handle.allContentAdded(), _message.getConnectionReference());
}
Aggregations