Java Code Examples for org.apache.qpid.proton.message.Message#getBody()

The following examples show how to use org.apache.qpid.proton.message.Message#getBody() . 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: MessageSendTester.java    From enmasse with Apache License 2.0 6 votes vote down vote up
private void handleMessage(final Message message) {

            if (log.isInfoEnabled()) {
                String str = message.toString();
                if (str.length() > MAX_MESSAGE_DUMP_LENGTH) {
                    str = str.substring(0, MAX_MESSAGE_DUMP_LENGTH) + "…";
                }
                log.info("Received message - {}", str);
            }

            var body = message.getBody();
            if (!(body instanceof Data)) {
                handleInvalidMessage(message);
                return;
            }

            var json = new JsonObject(Buffer.buffer(((Data) body).getValue().getArray()));
            var testId = json.getString("test-id");
            var timestamp = json.getLong("timestamp");
            if (!this.testId.equals(testId) || timestamp == null) {
                handleInvalidMessage(message);
                return;
            }

            handleValidMessage(message, timestamp, json);
        }
 
Example 2
Source File: RouterManagement.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private List<List<?>> collectRouter(SyncRequestClient client, RouterEntity routerEntity) {
    Map<String, Object> properties = new LinkedHashMap<>();
    properties.put("operation", "QUERY");
    properties.put("entityType", routerEntity.getName());
    Map<String, Object> body = new LinkedHashMap<>();

    if (routerEntity.getAttributes() != null) {
        body.put("attributeNames", Arrays.asList(routerEntity.getAttributes()));
    }

    Message message = Proton.message();
    message.setApplicationProperties(new ApplicationProperties(properties));
    message.setBody(new AmqpValue(body));

    long timeoutSeconds = this.queryTimeout.getSeconds();
    Message response = client.request(message, timeoutSeconds, TimeUnit.SECONDS);
    if (response == null) {
        throw new IllegalArgumentException(String.format("No response received within timeout : %s(s)", timeoutSeconds));
    }
    AmqpValue value = (AmqpValue) response.getBody();
    if (value == null) {
        throw new IllegalArgumentException("Unexpected null body");
    }
    Map<?,?> values = (Map<?,?>) value.getValue();
    if (values == null) {
        throw new IllegalArgumentException("Unexpected null body value");
    }

    @SuppressWarnings("unchecked")
    List<List<?>> results = (List<List<?>>) values.get("results");
    if (results == null) {
        throw new IllegalArgumentException("Unexpected null results list");
    }
    return results;
}
 
Example 3
Source File: ProtonClientTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private Object getMessageBody(TestContext context, Message msg) {
  Section body = msg.getBody();

  context.assertNotNull(body);
  context.assertTrue(body instanceof AmqpValue);

  return ((AmqpValue) body).getValue();
}
 
Example 4
Source File: ProtonSubscriberIntTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private Object getMessageBody(TestContext context, Message msg) {
  Section body = msg.getBody();

  context.assertNotNull(body);
  context.assertTrue(body instanceof AmqpValue);

  return ((AmqpValue) body).getValue();
}
 
Example 5
Source File: ProtonPublisherIntTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private Object getMessageBody(TestContext context, Message msg) {
  Section body = msg.getBody();

  context.assertNotNull(body);
  context.assertTrue(body instanceof AmqpValue);

  return ((AmqpValue) body).getValue();
}
 
Example 6
Source File: HonoCommander.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
private void handleMessage(final String msgType, final Message msg) {
    final Data body = (Data) msg.getBody();
    LOG.debug("Type: [{}] and Message: [{}]", msgType, body != null ? body.getValue().toString() : "");
}
 
Example 7
Source File: MessageHelper.java    From hono with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Checks if a message's body consists of an AMQP <em>Data</em> section.
 *
 * @param message The message to check.
 * @return {@code true} if the body consists of a Data section, {@code false} otherwise.
 * @throws NullPointerException If message is {@code null}.
 */
public static boolean hasDataBody(final Message message) {

    Objects.requireNonNull(message);
    return message.getBody() instanceof Data;
}
 
Example 8
Source File: MessageHelper.java    From hono with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Checks if a message's body consists of an AMQP <em>AmqpValue</em> section.
 *
 * @param message The message to check.
 * @return {@code true} if the body consists of an AmqpValue section, {@code false} otherwise.
 * @throws NullPointerException If message is {@code null}.
 */
public static boolean hasAmqpValueBody(final Message message) {

    Objects.requireNonNull(message);
    return message.getBody() instanceof AmqpValue;
}