use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project hono by eclipse.
the class ProtonBasedCommandTest method testFromRoutedCommandMessageSucceeds.
/**
* Verifies that a command can be created from a valid message representing a routed command
* message with a <em>via</em> property containing a gateway identifier.
*/
@Test
public void testFromRoutedCommandMessageSucceeds() {
final String gatewayId = "gw-1";
final String targetDeviceId = "4711";
final String replyToId = "the-reply-to-id";
final String correlationId = "the-correlation-id";
final Map<String, Object> applicationProperties = new HashMap<>();
applicationProperties.put("via", gatewayId);
final Message message = mock(Message.class);
when(message.getAddress()).thenReturn(String.format("%s/%s/%s", CommandConstants.COMMAND_ENDPOINT, Constants.DEFAULT_TENANT, "4711"));
when(message.getApplicationProperties()).thenReturn(new ApplicationProperties(applicationProperties));
when(message.getSubject()).thenReturn("doThis");
when(message.getCorrelationId()).thenReturn(correlationId);
when(message.getReplyTo()).thenReturn(String.format("%s/%s/%s/%s", CommandConstants.NORTHBOUND_COMMAND_RESPONSE_ENDPOINT, Constants.DEFAULT_TENANT, "4711", replyToId));
final ProtonBasedCommand cmd = ProtonBasedCommand.fromRoutedCommandMessage(message);
assertTrue(cmd.isValid());
assertThat(cmd.getName()).isEqualTo("doThis");
assertThat(cmd.getTenant()).isEqualTo(Constants.DEFAULT_TENANT);
assertThat(cmd.getGatewayOrDeviceId()).isEqualTo(gatewayId);
assertThat(cmd.getGatewayId()).isEqualTo(gatewayId);
assertThat(cmd.getDeviceId()).isEqualTo(targetDeviceId);
assertThat(cmd.getReplyToId()).isEqualTo(String.format("%s/%s", targetDeviceId, replyToId));
assertThat(cmd.getCorrelationId()).isEqualTo(correlationId);
assertFalse(cmd.isOneWay());
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project hono by eclipse.
the class VertxBasedAmqpProtocolAdapterTest method testUploadCommandResponseWithoutPayloadSucceeds.
/**
* Verify that the AMQP adapter forwards command responses that do not contain a payload downstream.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUploadCommandResponseWithoutPayloadSucceeds(final VertxTestContext ctx) {
// GIVEN an AMQP adapter
givenAnAdapter(properties);
final CommandResponseSender responseSender = givenACommandResponseSenderForAnyTenant();
when(responseSender.sendCommandResponse(any(TenantObject.class), any(RegistrationAssertion.class), any(CommandResponse.class), (SpanContext) any())).thenReturn(Future.succeededFuture());
// which is enabled for the test tenant
final TenantObject tenantObject = givenAConfiguredTenant(TEST_TENANT_ID, true);
// WHEN an unauthenticated device publishes a command response
final String replyToAddress = String.format("%s/%s/%s", getCommandResponseEndpoint(), TEST_TENANT_ID, Commands.getDeviceFacingReplyToId("test-reply-id", TEST_DEVICE, MessagingType.amqp));
final Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put(MessageHelper.APP_PROPERTY_STATUS, 200);
final ApplicationProperties props = new ApplicationProperties(propertyMap);
final Message message = getFakeMessage(replyToAddress, null);
message.setCorrelationId("correlation-id");
message.setApplicationProperties(props);
final ProtonDelivery delivery = mock(ProtonDelivery.class);
adapter.onMessageReceived(AmqpContext.fromMessage(delivery, message, span, null)).onComplete(ctx.succeeding(ok -> {
ctx.verify(() -> {
// THEN the adapter forwards the command response message downstream
verify(responseSender).sendCommandResponse(eq(tenantObject), any(RegistrationAssertion.class), any(CommandResponse.class), (SpanContext) any());
// and reports the forwarded message
verify(metrics).reportCommand(eq(Direction.RESPONSE), eq(TEST_TENANT_ID), eq(tenantObject), eq(ProcessingOutcome.FORWARDED), eq(0), any());
});
ctx.completeNow();
}));
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project hono by eclipse.
the class VertxBasedAmqpProtocolAdapterTest method testMessageLimitExceededForACommandResponseMessage.
/**
* Verifies that a command response message is rejected due to the limit exceeded.
*
* @param ctx The test context to use for running asynchronous tests.
*/
@Test
public void testMessageLimitExceededForACommandResponseMessage(final VertxTestContext ctx) {
final String replyToAddress = String.format("%s/%s/%s", getCommandResponseEndpoint(), TEST_TENANT_ID, Commands.getDeviceFacingReplyToId("test-reply-id", TEST_DEVICE, MessagingType.amqp));
final Buffer payload = Buffer.buffer("payload");
final Message message = getFakeMessage(replyToAddress, payload);
message.setCorrelationId("correlation-id");
final Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put(MessageHelper.APP_PROPERTY_STATUS, 200);
final ApplicationProperties props = new ApplicationProperties(propertyMap);
message.setApplicationProperties(props);
testMessageLimitExceededForADownstreamMessage(ctx, message, s -> {
assertNoCommandResponseHasBeenSentDownstream();
verify(metrics).reportCommand(eq(Direction.RESPONSE), eq(TEST_TENANT_ID), any(TenantObject.class), eq(ProcessingOutcome.UNPROCESSABLE), eq(payload.length()), any());
});
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project azure-iot-sdk-java by Azure.
the class AmqpsTransport method iotHubMessageToProtonMessage.
/**
* Creates a proton message from the IoTHub message.
* @param message the IoTHub input message.
* @return the proton message.
*/
private MessageImpl iotHubMessageToProtonMessage(com.microsoft.azure.sdk.iot.device.Message message) {
logger.LogInfo("Started converting IoT Hub message into AmpqsMessage, method name is %s ", logger.getMethodName());
MessageImpl outgoingMessage = (MessageImpl) Proton.message();
logger.LogInfo("Content of message is %s, method name is %s ", new String(message.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET), logger.getMethodName());
Properties properties = new Properties();
if (message.getMessageId() != null) {
properties.setMessageId(message.getMessageId());
}
outgoingMessage.setProperties(properties);
// Codes_SRS_AMQPSTRANSPORT_15_038: [The function shall add all user properties to the application properties of the Proton message.]
if (message.getProperties().length > 0) {
Map<String, String> userProperties = new HashMap<>(message.getProperties().length);
for (MessageProperty messageProperty : message.getProperties()) {
if (!MessageProperty.RESERVED_PROPERTY_NAMES.contains(messageProperty.getName())) {
userProperties.put(messageProperty.getName(), messageProperty.getValue());
}
}
ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
outgoingMessage.setApplicationProperties(applicationProperties);
}
Binary binary = new Binary(message.getBytes());
Section section = new Data(binary);
outgoingMessage.setBody(section);
logger.LogInfo("Started converting IoT Hub message into AmpqsMessage, method name is %s ", logger.getMethodName());
return outgoingMessage;
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project activemq-artemis by apache.
the class AMQPMessageTest method testVerySimple.
@Test
public void testVerySimple() {
MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
protonMessage.setHeader(new Header());
Properties properties = new Properties();
properties.setTo("someNiceLocal");
protonMessage.setProperties(properties);
protonMessage.getHeader().setDeliveryCount(new UnsignedInteger(7));
protonMessage.getHeader().setDurable(Boolean.TRUE);
protonMessage.setApplicationProperties(new ApplicationProperties(new HashMap()));
AMQPMessage decoded = encodeAndDecodeMessage(protonMessage);
assertEquals(7, decoded.getHeader().getDeliveryCount().intValue());
assertEquals(true, decoded.getHeader().getDurable());
assertEquals("someNiceLocal", decoded.getAddress());
}
Aggregations