/** * Gets the value of a message's {@link #APP_PROPERTY_DEVICE_ID} application property. * * @param msg The message. * @return The property value or {@code null} if not set. */ public static String getDeviceId(final Message msg) { Objects.requireNonNull(msg); return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_DEVICE_ID, String.class); }
/** * Gets the value of a message's {@link #APP_PROPERTY_TENANT_ID} application property. * * @param msg The message. * @return The property value or {@code null} if not set. */ public static String getTenantId(final Message msg) { Objects.requireNonNull(msg); return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_TENANT_ID, String.class); }
private Long getSenderTimeFromMessageProperties(final Message message) { final Long senderTime = MessageHelper.getApplicationProperty(message.getApplicationProperties(), TIME_STAMP_VARIABLE, Long.class); if (senderTime == null) { LOGGER.warn("could not get sender time from '" + TIME_STAMP_VARIABLE + "' message application property"); } return senderTime; }
/** * Gets the value of a message's {@link #APP_PROPERTY_CACHE_CONTROL} application property. * * @param msg The message to get the property from. * @return The property value or {@code null} if not set. */ public static String getCacheDirective(final Message msg) { return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_CACHE_CONTROL, String.class); }
/** * Gets the value of a message's {@link #APP_PROPERTY_DEVICE_TTD} application property. * * @param msg The message to get the property from. * @return The property value or {@code null} if not set. */ public static Integer getTimeUntilDisconnect(final Message msg) { return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_DEVICE_TTD, Integer.class); }
/** * Gets the value of a message's {@link #APP_PROPERTY_TENANT_ID} application property. * * @param msg The message. * @return The property value or {@code null} if not set. */ public static String getTenantId(final Message msg) { Objects.requireNonNull(msg); return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_TENANT_ID, String.class); }
/** * Gets the value of a message's {@link #APP_PROPERTY_DEVICE_TTD} application property. * * @param msg The message to get the property from. * @return The property value or {@code null} if not set. */ public static Integer getTimeUntilDisconnect(final Message msg) { return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_DEVICE_TTD, Integer.class); }
/** * Gets the value of a message's {@link #APP_PROPERTY_DEVICE_ID} application property. * * @param msg The message. * @return The property value or {@code null} if not set. */ public static String getDeviceId(final Message msg) { Objects.requireNonNull(msg); return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_DEVICE_ID, String.class); }
/** * Gets the value of a message's {@link #APP_PROPERTY_CACHE_CONTROL} application property. * * @param msg The message to get the property from. * @return The property value or {@code null} if not set. */ public static String getCacheDirective(final Message msg) { return getApplicationProperty(msg.getApplicationProperties(), APP_PROPERTY_CACHE_CONTROL, String.class); }
public static Symbol getResponseErrorCondition(Message responseMessage) { Symbol errorCondition = (Symbol)responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_ERROR_CONDITION); if(errorCondition == null) { errorCondition = (Symbol)responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_LEGACY_ERROR_CONDITION); } return errorCondition; }
public static String getResponseStatusDescription(Message responseMessage) { String statusDescription = (String)responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_STATUS_DESCRIPTION); if(statusDescription == null) { statusDescription = (String)responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_LEGACY_STATUS_DESCRIPTION); } return statusDescription; }
public static int getResponseStatusCode(Message responseMessage) { int statusCode = ClientConstants.REQUEST_RESPONSE_UNDEFINED_STATUS_CODE; Object codeObject = responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_STATUS_CODE); if(codeObject == null) { codeObject = responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_LEGACY_STATUS_CODE); } if(codeObject != null) { statusCode = (int)codeObject; } return statusCode; }
private void handleMessage(final String endpoint, final Message msg) { final String deviceId = MessageHelper.getDeviceId(msg); final Buffer payload = MessageHelper.getPayload(msg); LOG.info("received {} message [device: {}, content-type: {}]: {}", endpoint, deviceId, msg.getContentType(), payload); if (msg.getApplicationProperties() != null) { LOG.info("... with application properties: {}", msg.getApplicationProperties().getValue()); } }
private static String getRegistrationAssertion(final Message msg, final boolean removeAssertion) { Objects.requireNonNull(msg); String assertion = null; final ApplicationProperties properties = msg.getApplicationProperties(); if (properties != null) { Object obj = null; if (removeAssertion) { obj = properties.getValue().remove(APP_PROPERTY_REGISTRATION_ASSERTION); } else { obj = properties.getValue().get(APP_PROPERTY_REGISTRATION_ASSERTION); } if (obj instanceof String) { assertion = (String) obj; } } return assertion; }
private static boolean hasValidAction(final Message msg) { String action = MessageHelper.getApplicationProperty( msg.getApplicationProperties(), RegistrationConstants.APP_PROPERTY_ACTION, String.class); return RegistrationConstants.isValidAction(action); }
/** * Adds a property with a value from an AMQP message. * <p> * The property will only be added if the AMQP message contains * a non-{@code null} <em>application property</em> of the given name. * * @param name The name of the property. * @param msg The AMQP message to retrieve the value from. * @return This message for chaining. */ public EventBusMessage setStringProperty(final String name, final Message msg) { setProperty(name, MessageHelper.getApplicationProperty( msg.getApplicationProperties(), name, String.class)); return this; }
public Message request(Message message, long timeout, TimeUnit timeUnit) { Map<String, Object> properties = new HashMap<>(); if (message.getApplicationProperties() != null) { properties.putAll(message.getApplicationProperties().getValue()); } message.setApplicationProperties(new ApplicationProperties(properties)); if (message.getReplyTo() == null) { message.setReplyTo(replyTo); } context.runOnContext(h -> sender.send(message)); try { return replies.poll(timeout, timeUnit); } catch (InterruptedException e) { throw new RuntimeException(e); } }
private R getRequestResponseResult(final Message message) { final Integer status = MessageHelper.getApplicationProperty( message.getApplicationProperties(), MessageHelper.APP_PROPERTY_STATUS, Integer.class); if (status == null) { return null; } else { final CacheDirective cacheDirective = CacheDirective.from(MessageHelper.getCacheDirective(message)); return getResult(status, message.getContentType(), MessageHelper.getPayload(message), cacheDirective); } }
@Test public void testJSON_to_AMQP_WithNoApplicationPropertiesSection() { JsonObject jsonObject = new JsonObject(); Message protonMsg = translator.convertToAmqpMessage(jsonObject); assertNotNull("Expected converted msg", protonMsg); assertNull("expected converted msg to have no application properties section", protonMsg.getApplicationProperties()); }
/** * Verifies that the adapter's name is set on a downstream message. */ @Test public void testAddPropertiesAddsAdapterName() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat( MessageHelper.getApplicationProperty( message.getApplicationProperties(), MessageHelper.APP_PROPERTY_ORIG_ADAPTER, String.class), is(ADAPTER_NAME)); }