use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project activemq-artemis by apache.
the class AmqpMessage method lazyCreateApplicationProperties.
private void lazyCreateApplicationProperties() {
if (applicationPropertiesMap == null) {
applicationPropertiesMap = new HashMap<>();
message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap));
}
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project azure-iot-sdk-java by Azure.
the class AmqpsMethodsSenderLinkHandler method iotHubMessageToProtonMessage.
@Override
protected MessageImpl iotHubMessageToProtonMessage(Message message) {
if (message.getMessageType() == MessageType.DEVICE_METHODS) {
MessageImpl protonMessage = super.iotHubMessageToProtonMessage(message);
IotHubTransportMessage deviceMethodMessage = (IotHubTransportMessage) message;
Properties properties;
if (protonMessage.getProperties() != null) {
properties = protonMessage.getProperties();
} else {
properties = new Properties();
}
if (deviceMethodMessage.getRequestId() != null) {
properties.setCorrelationId(UUID.fromString(deviceMethodMessage.getRequestId()));
}
protonMessage.setProperties(properties);
Map<String, Object> userProperties = new HashMap<>();
if (deviceMethodMessage.getStatus() != null) {
userProperties.put(APPLICATION_PROPERTY_KEY_IOTHUB_STATUS, Integer.parseInt(deviceMethodMessage.getStatus()));
}
if (protonMessage.getApplicationProperties() != null && protonMessage.getApplicationProperties().getValue() != null) {
Map<String, Object> applicationPropertiesMap = protonMessage.getApplicationProperties().getValue();
userProperties.putAll(applicationPropertiesMap);
}
ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
protonMessage.setApplicationProperties(applicationProperties);
return protonMessage;
}
return null;
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project azure-iot-sdk-java by Azure.
the class AmqpsSenderLinkHandler method iotHubMessageToProtonMessage.
MessageImpl iotHubMessageToProtonMessage(Message message) {
log.trace("Converting IoT Hub message to proton message for {} sender link with address {} and link correlation id {}. IoT Hub message correlationId {}", getLinkInstanceType(), this.senderLinkAddress, this.linkCorrelationId, message.getCorrelationId());
MessageImpl outgoingMessage = (MessageImpl) Proton.message();
Properties properties = new Properties();
if (message.getMessageId() != null) {
properties.setMessageId(message.getMessageId());
}
if (message.getCorrelationId() != null) {
properties.setCorrelationId(message.getCorrelationId());
}
if (message.getContentType() != null) {
properties.setContentType(Symbol.valueOf(message.getContentType()));
}
if (message.getContentEncoding() != null) {
properties.setContentEncoding(Symbol.valueOf(message.getContentEncoding()));
}
outgoingMessage.setProperties(properties);
Map<String, Object> userProperties = new HashMap<>();
if (message.getProperties().length > 0) {
for (MessageProperty messageProperty : message.getProperties()) {
if (!MessageProperty.RESERVED_PROPERTY_NAMES.contains(messageProperty.getName())) {
userProperties.put(messageProperty.getName(), messageProperty.getValue());
}
}
}
if (message.getConnectionDeviceId() != null) {
userProperties.put(MessageProperty.CONNECTION_DEVICE_ID, message.getConnectionDeviceId());
}
if (message.getConnectionModuleId() != null) {
userProperties.put(MessageProperty.CONNECTION_MODULE_ID, message.getConnectionModuleId());
}
if (message.getCreationTimeUTC() != null) {
userProperties.put(MessageProperty.IOTHUB_CREATION_TIME_UTC, message.getCreationTimeUTCString());
}
ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
outgoingMessage.setApplicationProperties(applicationProperties);
Map<Symbol, Object> messageAnnotationsMap = new HashMap<>();
if (message.isSecurityMessage()) {
messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.IOTHUB_SECURITY_INTERFACE_ID), MessageProperty.IOTHUB_SECURITY_INTERFACE_ID_VALUE);
}
if (message.getComponentName() != null && !message.getComponentName().isEmpty()) {
messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.COMPONENT_ID), message.getComponentName());
}
MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap);
outgoingMessage.setMessageAnnotations(messageAnnotations);
Binary binary = new Binary(message.getBytes());
Section section = new Data(binary);
outgoingMessage.setBody(section);
return outgoingMessage;
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project azure-iot-sdk-java by Azure.
the class AmqpsTelemetrySenderLinkHandler method iotHubMessageToProtonMessage.
@Override
protected MessageImpl iotHubMessageToProtonMessage(Message message) {
if ((message.getMessageType() == null) || (message.getMessageType() == MessageType.DEVICE_TELEMETRY)) {
MessageImpl protonMessage = super.iotHubMessageToProtonMessage(message);
if (message.getOutputName() != null) {
if (protonMessage.getApplicationProperties() != null && protonMessage.getApplicationProperties().getValue() != null) {
Map<String, Object> userProperties = new HashMap<>();
userProperties.put(MessageProperty.OUTPUT_NAME_PROPERTY, message.getOutputName());
userProperties.putAll(protonMessage.getApplicationProperties().getValue());
protonMessage.setApplicationProperties(new ApplicationProperties(userProperties));
}
}
return protonMessage;
}
return null;
}
use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project hono by eclipse.
the class RequestResponseApiConstants method getAmqpReply.
/**
* Creates an AMQP message from a response to a service invocation.
*
* @param endpoint The service endpoint that the operation has been invoked on.
* @param response The response message.
* @return The AMQP message.
* @throws NullPointerException if endpoint is {@code null}.
* @throws IllegalArgumentException if the response does not contain a correlation ID.
*/
public static final Message getAmqpReply(final String endpoint, final EventBusMessage response) {
Objects.requireNonNull(endpoint);
Objects.requireNonNull(response);
final Object correlationId = response.getCorrelationId();
if (correlationId == null) {
throw new IllegalArgumentException("response must contain correlation ID");
}
final String tenantId = response.getTenant();
final String deviceId = response.getDeviceId();
final Integer status = response.getStatus();
final String cacheDirective = response.getCacheDirective();
final JsonObject payload = response.getJsonPayload();
final ResourceIdentifier address = ResourceIdentifier.from(endpoint, tenantId, deviceId);
final Message message = ProtonHelper.message();
message.setMessageId(UUID.randomUUID().toString());
message.setCorrelationId(correlationId);
message.setAddress(address.toString());
final Map<String, Object> map = new HashMap<>();
map.put(MessageHelper.APP_PROPERTY_STATUS, status);
if (tenantId != null) {
map.put(MessageHelper.APP_PROPERTY_TENANT_ID, tenantId);
}
if (deviceId != null) {
map.put(MessageHelper.APP_PROPERTY_DEVICE_ID, deviceId);
}
if (cacheDirective != null) {
map.put(MessageHelper.APP_PROPERTY_CACHE_CONTROL, cacheDirective);
}
message.setApplicationProperties(new ApplicationProperties(map));
MessageHelper.setJsonPayload(message, payload);
return message;
}
Aggregations