org.apache.qpid.proton.message.Message.getContentType()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中org.apache.qpid.proton.message.Message.getContentType()方法的一些代码示例,展示了Message.getContentType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getContentType()方法的具体详情如下:
包路径:org.apache.qpid.proton.message.Message
类名称:Message
方法名:getContentType

Message.getContentType介绍

暂无

代码示例

代码示例来源:origin: eclipse/hono

  1. /**
  2. * Gets the content type of the AMQP 1.0 message.
  3. *
  4. * @return The content type of the AMQP 1.0 message.
  5. */
  6. String getMessageContentType() {
  7. return message.getContentType();
  8. }

代码示例来源:origin: apache/activemq-artemis

  1. /**
  2. * Check whether the content-type field of the properties section (if present) in the given
  3. * message matches the provided string (where null matches if there is no content type
  4. * present.
  5. *
  6. * @param contentType
  7. * content type string to compare against, or null if none
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return true if content type matches
  12. */
  13. public static boolean isContentType(String contentType, Message message) {
  14. if (contentType == null) {
  15. return message.getContentType() == null;
  16. } else {
  17. return contentType.equals(message.getContentType());
  18. }
  19. }

代码示例来源:origin: org.apache.activemq/activemq-osgi

  1. /**
  2. * Check whether the content-type field of the properties section (if present) in
  3. * the given message matches the provided string (where null matches if there is
  4. * no content type present.
  5. *
  6. * @param contentType
  7. * content type string to compare against, or null if none
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return true if content type matches
  12. */
  13. public static boolean isContentType(String contentType, Message message) {
  14. if (contentType == null) {
  15. return message.getContentType() == null;
  16. } else {
  17. return contentType.equals(message.getContentType());
  18. }
  19. }

代码示例来源:origin: org.apache.activemq/activemq-all

  1. /**
  2. * Check whether the content-type field of the properties section (if present) in
  3. * the given message matches the provided string (where null matches if there is
  4. * no content type present.
  5. *
  6. * @param contentType
  7. * content type string to compare against, or null if none
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return true if content type matches
  12. */
  13. public static boolean isContentType(String contentType, Message message) {
  14. if (contentType == null) {
  15. return message.getContentType() == null;
  16. } else {
  17. return contentType.equals(message.getContentType());
  18. }
  19. }

代码示例来源:origin: org.apache.activemq/artemis-amqp-protocol

  1. /**
  2. * Check whether the content-type field of the properties section (if present) in the given
  3. * message matches the provided string (where null matches if there is no content type
  4. * present.
  5. *
  6. * @param contentType
  7. * content type string to compare against, or null if none
  8. * @param message
  9. * the AMQP message object that is being examined.
  10. *
  11. * @return true if content type matches
  12. */
  13. public static boolean isContentType(String contentType, Message message) {
  14. if (contentType == null) {
  15. return message.getContentType() == null;
  16. } else {
  17. return contentType.equals(message.getContentType());
  18. }
  19. }

代码示例来源:origin: org.eclipse.hono/hono-client

  1. /**
  2. * Gets the type of this command's payload.
  3. *
  4. * @return The content type or {@code null} if not set.
  5. * @throws IllegalStateException if this command is invalid.
  6. */
  7. public String getContentType() {
  8. if (isValid()) {
  9. return message.getContentType();
  10. } else {
  11. throw new IllegalStateException("command is invalid");
  12. }
  13. }

代码示例来源:origin: eclipse/hono

  1. private void printMessage(final String tenantId, final Message msg, final String messageType) {
  2. if (LOG.isDebugEnabled()) {
  3. final String content = MessageHelper.getPayloadAsString(msg);
  4. final String deviceId = MessageHelper.getDeviceId(msg);
  5. final StringBuilder sb = new StringBuilder("received ").
  6. append(messageType).
  7. append(" [tenant: ").append(tenantId).
  8. append(", device: ").append(deviceId).
  9. append(", content-type: ").append(msg.getContentType()).
  10. append(" ]: [").append(content).append("].");
  11. LOG.debug(sb.toString());
  12. }
  13. }

代码示例来源:origin: eclipse/hono

  1. private void handleMessage(final String endpoint, final Message msg) {
  2. final String deviceId = MessageHelper.getDeviceId(msg);
  3. final Buffer payload = MessageHelper.getPayload(msg);
  4. LOG.info("received {} message [device: {}, content-type: {}]: {}", endpoint, deviceId, msg.getContentType(),
  5. payload);
  6. if (msg.getApplicationProperties() != null) {
  7. LOG.info("... with application properties: {}", msg.getApplicationProperties().getValue());
  8. }
  9. }

代码示例来源:origin: org.eclipse.hono/hono-service-base

  1. if (Strings.isNullOrEmpty(message.getContentType()) && String.class.isInstance(prop.getValue())) {

代码示例来源:origin: eclipse/hono

  1. if (Strings.isNullOrEmpty(message.getContentType()) && String.class.isInstance(prop.getValue())) {

代码示例来源:origin: org.eclipse.hono/hono-server

  1. @Override
  2. public void processMessage(final UpstreamReceiver client, final ProtonDelivery delivery, final Message data) {
  3. LinkStatus status = statusMap.get(client.getLinkId());
  4. if (status == null) {
  5. LOG.debug("creating new link status object [{}]", client.getLinkId());
  6. status = new LinkStatus(client);
  7. statusMap.put(client.getLinkId(), status);
  8. }
  9. LOG.debug("processing telemetry data [id: {}, to: {}, content-type: {}]", data.getMessageId(), data.getAddress(),
  10. data.getContentType());
  11. if (messageConsumer != null) {
  12. messageConsumer.accept(data);
  13. }
  14. ProtonHelper.accepted(delivery, true);
  15. status.onMsgReceived();
  16. }

代码示例来源:origin: eclipse/hono

  1. /**
  2. * Adds JMS vendor properties defined by
  3. * <a href="https://www.oasis-open.org/committees/download.php/60574/amqp-bindmap-jms-v1.0-wd09.pdf"> AMQP JMS
  4. * Mapping 1.0</a> as AMQP 1.0 application properties to a given message.
  5. * <p>
  6. * The following vendor properties are added (if the message has a corresponding non-null value set):
  7. * <ul>
  8. * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_TYPE}</li>
  9. * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_ENCODING}</li>
  10. * </ul>
  11. *
  12. * @param msg the message to add the vendor properties to.
  13. */
  14. public static void addJmsVendorProperties(final Message msg) {
  15. if (!Strings.isNullOrEmpty(msg.getContentType())) {
  16. MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_TYPE, msg.getContentType());
  17. }
  18. if (!Strings.isNullOrEmpty(msg.getContentEncoding())) {
  19. MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_ENCODING, msg.getContentEncoding());
  20. }
  21. }

代码示例来源:origin: org.eclipse.hono/hono-core

  1. /**
  2. * Adds JMS vendor properties defined by
  3. * <a href="https://www.oasis-open.org/committees/download.php/60574/amqp-bindmap-jms-v1.0-wd09.pdf"> AMQP JMS
  4. * Mapping 1.0</a> as AMQP 1.0 application properties to a given message.
  5. * <p>
  6. * The following vendor properties are added (if the message has a corresponding non-null value set):
  7. * <ul>
  8. * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_TYPE}</li>
  9. * <li>{@link #JMS_VENDOR_PROPERTY_CONTENT_ENCODING}</li>
  10. * </ul>
  11. *
  12. * @param msg the message to add the vendor properties to.
  13. */
  14. public static void addJmsVendorProperties(final Message msg) {
  15. if (!Strings.isNullOrEmpty(msg.getContentType())) {
  16. MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_TYPE, msg.getContentType());
  17. }
  18. if (!Strings.isNullOrEmpty(msg.getContentEncoding())) {
  19. MessageHelper.addProperty(msg, JMS_VENDOR_PROPERTY_CONTENT_ENCODING, msg.getContentEncoding());
  20. }
  21. }

代码示例来源:origin: org.eclipse.hono/hono-server

  1. return false;
  2. } else if (msg.getBody() != null) {
  3. if (msg.getContentType() == null || !msg.getContentType().startsWith("application/json")) {
  4. LOG.trace("message [{}] content type is not JSON", msg.getMessageId());
  5. return false;

代码示例来源:origin: org.eclipse.hono/hono-server

  1. /**
  2. * Checks whether a given telemetry message contains all required properties.
  3. * <p>
  4. * For successful verification, the message must meet the following conditions
  5. * <ul>
  6. * <li>All conditions defined by {@link #verifyStandardProperties(ResourceIdentifier, Message)}</li>
  7. * <li>The message must have its {@code content-type} property set.</li>
  8. * <li>The message must have an AMQP {@code Data} typed body.</li>
  9. * </ul>
  10. *
  11. * @param linkTarget the link target address to match the telemetry message's properties against.
  12. * @param msg the message to verify.
  13. * @return {@code true} if the given message complies with the <em>Telemetry</em> API specification, {@code false}
  14. * otherwise.
  15. */
  16. public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) {
  17. if (!verifyStandardProperties(linkTarget, msg)) {
  18. return false;
  19. } else if (msg.getContentType() == null) {
  20. LOG.trace("message [{}] has no content type", msg.getMessageId());
  21. return false;
  22. } else if (msg.getBody() == null || !(msg.getBody() instanceof Data)) {
  23. LOG.trace("message [{}] has no body of type AMQP Data", msg.getMessageId());
  24. return false;
  25. } else {
  26. return true;
  27. }
  28. }
  29. }

代码示例来源:origin: org.eclipse.hono/hono-client

  1. private R getRequestResponseResult(final Message message) {
  2. final Integer status = MessageHelper.getApplicationProperty(
  3. message.getApplicationProperties(),
  4. MessageHelper.APP_PROPERTY_STATUS,
  5. Integer.class);
  6. if (status == null) {
  7. return null;
  8. } else {
  9. final CacheDirective cacheDirective = CacheDirective.from(MessageHelper.getCacheDirective(message));
  10. return getResult(status, message.getContentType(), MessageHelper.getPayload(message), cacheDirective);
  11. }
  12. }

代码示例来源:origin: org.eclipse.hono/hono-server

  1. msg.getMessageId(), msg.getAddress(), msg.getContentType(), getDownstreamContainer(), sender.getCredit(), sender.getQueued());
  2. forwardMessage(sender, msg, delivery);

代码示例来源:origin: eclipse/hono

  1. /**
  2. * Verifies that the registered default content type is set on a downstream message.
  3. */
  4. @Test
  5. public void testAddPropertiesAddsDefaultContentType() {
  6. final Message message = ProtonHelper.message();
  7. adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono"));
  8. assertThat(MessageHelper.getRegistrationAssertion(message), is("token"));
  9. assertThat(message.getContentType(), is("application/hono"));
  10. }

代码示例来源:origin: eclipse/hono

  1. /**
  2. * Verifies that the fall back content type is set on a downstream message
  3. * if no default has been configured for the device.
  4. */
  5. @Test
  6. public void testAddPropertiesAddsFallbackContentType() {
  7. final Message message = ProtonHelper.message();
  8. adapter.addProperties(message, newRegistrationAssertionResult("token"));
  9. assertThat(MessageHelper.getRegistrationAssertion(message), is("token"));
  10. assertThat(message.getContentType(), is(AbstractProtocolAdapterBase.CONTENT_TYPE_OCTET_STREAM));
  11. }

代码示例来源:origin: eclipse/hono

  1. /**
  2. * Verifies that the registered default content type is not set on a downstream message
  3. * that already contains a content type.
  4. */
  5. @Test
  6. public void testAddPropertiesDoesNotAddDefaultContentType() {
  7. final Message message = ProtonHelper.message();
  8. message.setContentType("application/existing");
  9. adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono"));
  10. assertThat(MessageHelper.getRegistrationAssertion(message), is("token"));
  11. assertThat(message.getContentType(), is("application/existing"));
  12. }

相关文章