Java Code Examples for org.apache.qpid.proton.amqp.messaging.MessageAnnotations#getValue()
The following examples show how to use
org.apache.qpid.proton.amqp.messaging.MessageAnnotations#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmqpCoreConverter.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected static ServerJMSMessage processMessageAnnotations(ServerJMSMessage jms, MessageAnnotations annotations) throws Exception { if (annotations != null && annotations.getValue() != null) { for (Map.Entry<?, ?> entry : annotations.getValue().entrySet()) { String key = entry.getKey().toString(); if ("x-opt-delivery-time".equals(key) && entry.getValue() != null) { long deliveryTime = ((Number) entry.getValue()).longValue(); jms.setLongProperty(HDR_SCHEDULED_DELIVERY_TIME.toString(), deliveryTime); } else if ("x-opt-delivery-delay".equals(key) && entry.getValue() != null) { long delay = ((Number) entry.getValue()).longValue(); if (delay > 0) { jms.setLongProperty(HDR_SCHEDULED_DELIVERY_TIME.toString(), System.currentTimeMillis() + delay); } } try { setProperty(jms, JMS_AMQP_MESSAGE_ANNOTATION_PREFIX + key, entry.getValue()); } catch (ActiveMQPropertyConversionException e) { encodeUnsupportedMessagePropertyType(jms, JMS_AMQP_ENCODED_MESSAGE_ANNOTATION_PREFIX + key, entry.getValue()); } } } return jms; }
Example 2
Source File: JMSMappingOutboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void doTestConvertMessageWithJMSDestination(Destination jmsDestination, Object expectedAnnotationValue) throws Exception { ServerJMSTextMessage textMessage = createTextMessage(); textMessage.setText("myTextMessageContent"); textMessage.setJMSDestination(jmsDestination); AMQPMessage amqp = AMQPConverter.getInstance().fromCore(textMessage.getInnerMessage(), null); MessageAnnotations ma = amqp.getMessageAnnotations(); Map<Symbol, Object> maMap = ma == null ? null : ma.getValue(); if (maMap != null) { Object actualValue = maMap.get(AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION); assertEquals("Unexpected annotation value", expectedAnnotationValue, actualValue); } else if (expectedAnnotationValue != null) { fail("Expected annotation value, but there were no annotations"); } if (jmsDestination != null) { assertEquals("Unexpected 'to' address", AMQPMessageSupport.toAddress(jmsDestination), amqp.getAddress()); } }
Example 3
Source File: JMSMappingOutboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void doTestConvertMessageWithJMSReplyTo(Destination jmsReplyTo, Object expectedAnnotationValue) throws Exception { ServerJMSTextMessage textMessage = createTextMessage(); textMessage.setText("myTextMessageContent"); textMessage.setJMSReplyTo(jmsReplyTo); AMQPMessage amqp = AMQPConverter.getInstance().fromCore(textMessage.getInnerMessage(), null); MessageAnnotations ma = amqp.getMessageAnnotations(); Map<Symbol, Object> maMap = ma == null ? null : ma.getValue(); if (maMap != null) { Object actualValue = maMap.get(AMQPMessageSupport.JMS_REPLY_TO_TYPE_MSG_ANNOTATION); assertEquals("Unexpected annotation value", expectedAnnotationValue, actualValue); } else if (expectedAnnotationValue != null) { fail("Expected annotation value, but there were no annotations"); } if (jmsReplyTo != null) { assertEquals("Unexpected 'reply-to' address", AMQPMessageSupport.toAddress(jmsReplyTo).toString(), amqp.getReplyTo().toString()); } }
Example 4
Source File: MessageAnnotationsExtractAdapter.java From hono with Eclipse Public License 2.0 | 5 votes |
private Map<?, ?> getPropertiesMap() { final MessageAnnotations messageAnnotations = message.getMessageAnnotations(); if (messageAnnotations == null || messageAnnotations.getValue() == null) { return Collections.emptyMap(); } final Object annotationValue = messageAnnotations.getValue().get(Symbol.getSymbol(propertiesMapName)); if (!(annotationValue instanceof Map)) { if (annotationValue != null) { LOG.debug("Value of '{}' annotation is not of type Map; actual type: {}", propertiesMapName, annotationValue.getClass().getName()); } return Collections.emptyMap(); } return (Map<?, ?>) annotationValue; }
Example 5
Source File: MessageAnnotationsTypeCodecTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void doTestDecodeMessageAnnotationsSeries(int size) throws IOException { final Symbol SYMBOL_1 = Symbol.valueOf("test1"); final Symbol SYMBOL_2 = Symbol.valueOf("test2"); final Symbol SYMBOL_3 = Symbol.valueOf("test3"); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(SYMBOL_1, UnsignedByte.valueOf((byte) 128)); annotations.getValue().put(SYMBOL_2, UnsignedShort.valueOf((short) 128)); annotations.getValue().put(SYMBOL_3, UnsignedInteger.valueOf(128)); for (int i = 0; i < size; ++i) { encoder.writeObject(annotations); } buffer.clear(); for (int i = 0; i < size; ++i) { final Object result = decoder.readObject(); assertNotNull(result); assertTrue(result instanceof MessageAnnotations); MessageAnnotations readAnnotations = (MessageAnnotations) result; Map<Symbol, Object> resultMap = readAnnotations.getValue(); assertEquals(annotations.getValue().size(), resultMap.size()); assertEquals(resultMap.get(SYMBOL_1), UnsignedByte.valueOf((byte) 128)); assertEquals(resultMap.get(SYMBOL_2), UnsignedShort.valueOf((short) 128)); assertEquals(resultMap.get(SYMBOL_3), UnsignedInteger.valueOf(128)); } }
Example 6
Source File: MessageAnnotationsTypeCodecTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testEncodeAndDecodeAnnoationsWithEmbeddedMaps() throws IOException { final Symbol SYMBOL_1 = Symbol.valueOf("x-opt-test1"); final Symbol SYMBOL_2 = Symbol.valueOf("x-opt-test2"); final String VALUE_1 = "string"; final UnsignedInteger VALUE_2 = UnsignedInteger.valueOf(42); final UUID VALUE_3 = UUID.randomUUID(); Map<String, Object> stringKeyedMap = new HashMap<>(); stringKeyedMap.put("key1", VALUE_1); stringKeyedMap.put("key2", VALUE_2); stringKeyedMap.put("key3", VALUE_3); Map<Symbol, Object> symbolKeyedMap = new HashMap<>(); symbolKeyedMap.put(Symbol.valueOf("key1"), VALUE_1); symbolKeyedMap.put(Symbol.valueOf("key2"), VALUE_2); symbolKeyedMap.put(Symbol.valueOf("key3"), VALUE_3); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(SYMBOL_1, stringKeyedMap); annotations.getValue().put(SYMBOL_2, symbolKeyedMap); encoder.writeObject(annotations); buffer.clear(); final Object result = decoder.readObject(); assertNotNull(result); assertTrue(result instanceof MessageAnnotations); MessageAnnotations readAnnotations = (MessageAnnotations) result; Map<Symbol, Object> resultMap = readAnnotations.getValue(); assertEquals(annotations.getValue().size(), resultMap.size()); assertEquals(resultMap.get(SYMBOL_1), stringKeyedMap); assertEquals(resultMap.get(SYMBOL_2), symbolKeyedMap); }
Example 7
Source File: AmqpCoreConverter.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static byte parseQueueAnnotation(MessageAnnotations annotations, Symbol symbol) { Object value = (annotations != null && annotations.getValue() != null ? annotations.getValue().get(symbol) : AMQPMessageSupport.QUEUE_TYPE); byte queueType; if (value == null || !(value instanceof Number)) { queueType = AMQPMessageSupport.QUEUE_TYPE; } else { queueType = ((Number)value).byteValue(); } return queueType; }
Example 8
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doTestJMSMessageEncodingAddsProperMessageAnnotations(byte msgType, byte toType, byte replyToType) throws Exception { final AmqpJmsMessageFacade message = createMessageFacadeFromTypeId(msgType); final JmsDestination to = createDestinationFromTypeId(toType); final JmsDestination replyTo = createDestinationFromTypeId(replyToType); message.setDestination(to); message.setReplyTo(replyTo); // Allows the code to run through what should be cached in the TLS portion of the codec // and not be using the globally cached bits, this checks that nothing NPEs or otherwise // fails and should show in test coverage that the cache fill + cache use is exercised. for (int i = 0; i <= 2; ++i) { MessageImpl amqpMessage = (MessageImpl) AmqpMessageSupport.decodeMessage(AmqpCodec.encodeMessage(message)); MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations(); assertNotNull(messageAnnotations); assertNotNull(messageAnnotations.getValue()); Map<Symbol, Object> messageAnnotationsMap = messageAnnotations.getValue(); assertTrue(messageAnnotationsMap.containsKey(AmqpMessageSupport.JMS_MSG_TYPE)); if (toType != AmqpDestinationHelper.UNKNOWN_TYPE) { assertTrue(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); assertEquals(toType, messageAnnotationsMap.get(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); } else { assertFalse(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); } if (replyToType != AmqpDestinationHelper.UNKNOWN_TYPE) { assertTrue(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL)); assertEquals(replyToType, messageAnnotationsMap.get(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); } else { assertFalse(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL)); } } }
Example 9
Source File: MessageAnnotationsType.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Override protected Map wrap(MessageAnnotations val) { return val.getValue(); }
Example 10
Source File: AmqpJmsMessageFacade.java From qpid-jms with Apache License 2.0 | 4 votes |
void setMessageAnnotations(MessageAnnotations messageAnnotations) { if (messageAnnotations != null) { this.messageAnnotationsMap = messageAnnotations.getValue(); } }
Example 11
Source File: AmqpMessageSupport.java From qpid-jms with Apache License 2.0 | 3 votes |
/** * Safe way to access message annotations which will check internal structure and * either return the annotation if it exists or null if the annotation or any annotations * are present. * * @param key * the Symbol key to use to lookup an annotation. * @param messageAnnotations * the AMQP message annotations object that is being examined. * * @return the given annotation value or null if not present in the message. */ public static Object getMessageAnnotation(Symbol key, MessageAnnotations messageAnnotations) { if (messageAnnotations != null && messageAnnotations.getValue() != null) { Map<Symbol, Object> annotations = messageAnnotations.getValue(); return annotations.get(key); } return null; }