use of com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException in project azure-iot-sdk-java by Azure.
the class ProvisioningAmqpOperations method sendAmqpMessage.
private synchronized void sendAmqpMessage(String msgType, String operationId, byte[] msgBody) throws ProvisioningDeviceClientException {
try {
AmqpMessage outgoingMessage = new AmqpMessage();
Map<String, Object> userProperties = new HashMap<>();
userProperties.put(AMQP_OP_TYPE_PROPERTY, msgType);
if (operationId != null && !operationId.isEmpty()) {
userProperties.put(AMQP_OPERATION_ID, operationId);
}
outgoingMessage.setApplicationProperty(userProperties);
if (msgBody != null && msgBody.length > 0) {
outgoingMessage.setBody(msgBody);
}
this.amqpConnection.sendAmqpMessage(outgoingMessage);
} catch (Exception e) {
throw new ProvisioningDeviceTransportException("Failure sending AMQP message", e);
}
}
use of com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceTransportException in project azure-iot-sdk-java by Azure.
the class ContractAPIAmqp method getRegistrationStatus.
/**
* Gets the registration status over AMQP
* @param requestData A non {@code null} value with all the request data
* @param responseCallback A non {@code null} value for the callback
* @param callbackContext An object for context. Can be {@code null}
* @throws ProvisioningDeviceClientException If any of the parameters are invalid ({@code null} or empty)
* @throws ProvisioningDeviceTransportException If any of the API calls to transport fail
* @throws ProvisioningDeviceHubException If hub responds back with an invalid status
*/
public synchronized void getRegistrationStatus(RequestData requestData, ResponseCallback responseCallback, Object callbackContext) throws ProvisioningDeviceClientException {
// SRS_ContractAPIAmqp_07_009: [If requestData is null this method shall throw ProvisioningDeviceClientException.]
if (requestData == null) {
throw new ProvisioningDeviceClientException(new IllegalArgumentException("requestData cannot be null"));
}
// SRS_ContractAPIAmqp_07_010: [If requestData.getOperationId() is null or empty, this method shall throw ProvisioningDeviceClientException.]
String operationId = requestData.getOperationId();
if (operationId == null || operationId.isEmpty()) {
throw new ProvisioningDeviceClientException(new IllegalArgumentException("operationId cannot be null or empty"));
}
// SRS_ContractAPIAmqp_07_011: [If responseCallback is null, this method shall throw ProvisioningDeviceClientException.]
if (responseCallback == null) {
throw new ProvisioningDeviceClientException("responseCallback cannot be null");
}
// SRS_ContractAPIAmqp_07_012: [If amqpConnection is null or not connected, this method shall throw ProvisioningDeviceConnectionException.]
try {
if (!this.provisioningAmqpOperations.isAmqpConnected()) {
throw new ProvisioningDeviceConnectionException("Amqp is not connected");
}
} catch (Exception e) {
throw new ProvisioningDeviceClientException(e);
}
// SRS_ContractAPIAmqp_07_013: [This method shall send an AMQP message with the property of iotdps-get-operationstatus and the OperationId.]
this.provisioningAmqpOperations.sendStatusMessage(operationId, responseCallback, callbackContext);
}
Aggregations