/** * Gets the content type of the AMQP 1.0 message. * * @return The content type of the AMQP 1.0 message. */ String getMessageContentType() { return message.getContentType(); }
/** * Check whether the content-type field of the properties section (if present) in the given * message matches the provided string (where null matches if there is no content type * present. * * @param contentType * content type string to compare against, or null if none * @param message * the AMQP message object that is being examined. * * @return true if content type matches */ public static boolean isContentType(String contentType, Message message) { if (contentType == null) { return message.getContentType() == null; } else { return contentType.equals(message.getContentType()); } }
/** * Check whether the content-type field of the properties section (if present) in * the given message matches the provided string (where null matches if there is * no content type present. * * @param contentType * content type string to compare against, or null if none * @param message * the AMQP message object that is being examined. * * @return true if content type matches */ public static boolean isContentType(String contentType, Message message) { if (contentType == null) { return message.getContentType() == null; } else { return contentType.equals(message.getContentType()); } }
/** * Check whether the content-type field of the properties section (if present) in * the given message matches the provided string (where null matches if there is * no content type present. * * @param contentType * content type string to compare against, or null if none * @param message * the AMQP message object that is being examined. * * @return true if content type matches */ public static boolean isContentType(String contentType, Message message) { if (contentType == null) { return message.getContentType() == null; } else { return contentType.equals(message.getContentType()); } }
/** * Check whether the content-type field of the properties section (if present) in the given * message matches the provided string (where null matches if there is no content type * present. * * @param contentType * content type string to compare against, or null if none * @param message * the AMQP message object that is being examined. * * @return true if content type matches */ public static boolean isContentType(String contentType, Message message) { if (contentType == null) { return message.getContentType() == null; } else { return contentType.equals(message.getContentType()); } }
/** * Gets the type of this command's payload. * * @return The content type or {@code null} if not set. * @throws IllegalStateException if this command is invalid. */ public String getContentType() { if (isValid()) { return message.getContentType(); } else { throw new IllegalStateException("command is invalid"); } }
private void printMessage(final String tenantId, final Message msg, final String messageType) { if (LOG.isDebugEnabled()) { final String content = MessageHelper.getPayloadAsString(msg); final String deviceId = MessageHelper.getDeviceId(msg); final StringBuilder sb = new StringBuilder("received "). append(messageType). append(" [tenant: ").append(tenantId). append(", device: ").append(deviceId). append(", content-type: ").append(msg.getContentType()). append(" ]: [").append(content).append("]."); LOG.debug(sb.toString()); } }
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()); } }
if (Strings.isNullOrEmpty(message.getContentType()) && String.class.isInstance(prop.getValue())) {
if (Strings.isNullOrEmpty(message.getContentType()) && String.class.isInstance(prop.getValue())) {
@Override public void processMessage(final UpstreamReceiver client, final ProtonDelivery delivery, final Message data) { LinkStatus status = statusMap.get(client.getLinkId()); if (status == null) { LOG.debug("creating new link status object [{}]", client.getLinkId()); status = new LinkStatus(client); statusMap.put(client.getLinkId(), status); } LOG.debug("processing telemetry data [id: {}, to: {}, content-type: {}]", data.getMessageId(), data.getAddress(), data.getContentType()); if (messageConsumer != null) { messageConsumer.accept(data); } ProtonHelper.accepted(delivery, true); status.onMsgReceived(); }
/** * Adds JMS vendor properties defined by * <a href="https://www.oasis-open.org/committees/download.php/60574/amqp-bindmap-jms-v1.0-wd09.pdf"> AMQP JMS * Mapping 1.0</a> as AMQP 1.0 application properties to a given message. * <p> * The following vendor properties are added (if the message has a corresponding non-null value set): * <ul> * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_TYPE}</li> * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_ENCODING}</li> * </ul> * * @param msg the message to add the vendor properties to. */ public static void addJmsVendorProperties(final Message msg) { if (!Strings.isNullOrEmpty(msg.getContentType())) { MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_TYPE, msg.getContentType()); } if (!Strings.isNullOrEmpty(msg.getContentEncoding())) { MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_ENCODING, msg.getContentEncoding()); } }
/** * Adds JMS vendor properties defined by * <a href="https://www.oasis-open.org/committees/download.php/60574/amqp-bindmap-jms-v1.0-wd09.pdf"> AMQP JMS * Mapping 1.0</a> as AMQP 1.0 application properties to a given message. * <p> * The following vendor properties are added (if the message has a corresponding non-null value set): * <ul> * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_TYPE}</li> * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_ENCODING}</li> * </ul> * * @param msg the message to add the vendor properties to. */ public static void addJmsVendorProperties(final Message msg) { if (!Strings.isNullOrEmpty(msg.getContentType())) { MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_TYPE, msg.getContentType()); } if (!Strings.isNullOrEmpty(msg.getContentEncoding())) { MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_ENCODING, msg.getContentEncoding()); } }
return false; } else if (msg.getBody() != null) { if (msg.getContentType() == null || !msg.getContentType().startsWith("application/json")) { LOG.trace("message [{}] content type is not JSON", msg.getMessageId()); return false;
/** * Checks whether a given telemetry message contains all required properties. * <p> * For successful verification, the message must meet the following conditions * <ul> * <li>All conditions defined by {@link #verifyStandardProperties(ResourceIdentifier, Message)}</li> * <li>The message must have its {@code content-type} property set.</li> * <li>The message must have an AMQP {@code Data} typed body.</li> * </ul> * * @param linkTarget the link target address to match the telemetry message's properties against. * @param msg the message to verify. * @return {@code true} if the given message complies with the <em>Telemetry</em> API specification, {@code false} * otherwise. */ public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) { if (!verifyStandardProperties(linkTarget, msg)) { return false; } else if (msg.getContentType() == null) { LOG.trace("message [{}] has no content type", msg.getMessageId()); return false; } else if (msg.getBody() == null || !(msg.getBody() instanceof Data)) { LOG.trace("message [{}] has no body of type AMQP Data", msg.getMessageId()); return false; } else { return true; } } }
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); } }
msg.getMessageId(), msg.getAddress(), msg.getContentType(), getDownstreamContainer(), sender.getCredit(), sender.getQueued()); forwardMessage(sender, msg, delivery);
/** * Verifies that the registered default content type is set on a downstream message. */ @Test public void testAddPropertiesAddsDefaultContentType() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is("application/hono")); }
/** * Verifies that the fall back content type is set on a downstream message * if no default has been configured for the device. */ @Test public void testAddPropertiesAddsFallbackContentType() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is(AbstractProtocolAdapterBase.CONTENT_TYPE_OCTET_STREAM)); }
/** * Verifies that the registered default content type is not set on a downstream message * that already contains a content type. */ @Test public void testAddPropertiesDoesNotAddDefaultContentType() { final Message message = ProtonHelper.message(); message.setContentType("application/existing"); adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is("application/existing")); }