in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransport.java [323:377]
public void onMessageReceived(IotHubTransportMessage message, TransportException e)
{
if (message != null && e != null)
{
log.error("Exception encountered while receiving a message from service {}", message, e);
}
else if (message != null)
{
log.debug("Message was received from IotHub ({})", message);
this.addToReceivedMessagesQueue(message);
}
else
{
log.error("Exception encountered while receiving messages from service", e);
}
try
{
if (message != null)
{
String correlationId = message.getCorrelationId();
if (!correlationId.isEmpty())
{
CorrelationCallbackContext callbackContext = correlationCallbacks.get(correlationId);
if (callbackContext != null && callbackContext.getCallback() != null)
{
IotHubClientException clientException = null;
if (e != null)
{
// This case indicates that the transport layer failed to construct a valid message out of
// a message delivered by the service
clientException = e.toIotHubClientException();
}
else
{
// This case indicates that the transport layer constructed a valid message out of a message
// delivered by the service, but that message may contain an unsuccessful status code in cases
// such as if an operation was rejected because it was badly formatted.
IotHubStatusCode statusCode = IotHubStatusCode.getIotHubStatusCode(Integer.parseInt(message.getStatus()));
if (!IotHubStatusCode.isSuccessful(statusCode))
{
clientException = new IotHubClientException(statusCode, "Received an unsuccessful operation error code from the service: " + statusCode);
}
}
callbackContext.getCallback().onResponseReceived(message, callbackContext.getUserContext(), clientException);
}
}
}
}
catch (Exception ex)
{
log.warn("Exception thrown while calling the onResponseReceived callback in onMessageReceived", ex);
}
}