HttpsIotHubConnection Class

public class HttpsIotHubConnection implements IotHubTransportConnection

An HTTPS connection between a device and an IoT Hub. Contains functionality for synchronously connecting to the different IoT Hub resource URIs.

Constructor Summary

Constructor Description
HttpsIotHubConnection(ClientConfiguration config)

Constructs an instance from the given ClientConfiguration object.

Method Summary

Modifier and Type Method and Description
void close()

Closes the transport connection.

String getConnectionId()

Gives the UUID associated with this connection instance. This string is used in conjunction with the callbacks with connection status updates to ensure that all connection status updates are relevant to this connection object

void open()

Opens the transport connection object

IotHubTransportMessage receiveMessage()

Receives an IotHubTransportMessage, if one exists.

HttpsResponse sendHttpsMessage(HttpsMessage httpsMessage, HttpsMethod httpsMethod, String httpsPath, Map<String, String> additionalHeaders)

Sends an generic https message.

IotHubStatusCode sendMessage(Message message)

Sends an event message.

boolean sendMessageResult(IotHubTransportMessage message, IotHubMessageResult result)

Sends the message result for the previously received message.

void setListener(IotHubListener listener)

Sets a listener into the Transport Connection object. This listener updates the Transport layer of connection status updates, message arrivals, and message acknowledgements

Constructor Details

HttpsIotHubConnection

public HttpsIotHubConnection(ClientConfiguration config)

Constructs an instance from the given ClientConfiguration object.

Parameters:

config - the client configuration.

Method Details

close

public void close()

Closes the transport connection.

Overrides:

HttpsIotHubConnection.close()

getConnectionId

public String getConnectionId()

Gives the UUID associated with this connection instance. This string is used in conjunction with the callbacks with connection status updates to ensure that all connection status updates are relevant to this connection object

Overrides:

HttpsIotHubConnection.getConnectionId()

Returns:

the UUID associated with this connection instance

open

public void open()

Opens the transport connection object

Overrides:

HttpsIotHubConnection.open()

Throws:

TransportException - If any exceptions are encountered while opening the connection

receiveMessage

public IotHubTransportMessage receiveMessage()

Receives an IotHubTransportMessage, if one exists.

Returns:

an IotHubTransportMessage, or null if none exists.

Throws:

TransportException - if the IoT Hub could not be reached.

sendHttpsMessage

public HttpsResponse sendHttpsMessage(HttpsMessage httpsMessage, HttpsMethod httpsMethod, String httpsPath, Map additionalHeaders)

Sends an generic https message.

Parameters:

httpsMessage - the message to send.
httpsMethod - the https method (GET, POST, PUT, DELETE).
httpsPath - the path that will be added at the end of the URI with `/`.
additionalHeaders - any extra headers to be included in the http request

Returns:

the ResponseMessage including status code and payload from sending message.

Throws:

TransportException - if the IoT Hub could not be reached.

sendMessage

public IotHubStatusCode sendMessage(Message message)

Sends an event message.

Overrides:

HttpsIotHubConnection.sendMessage(Message message)

Parameters:

message - the event message.

Returns:

the IotHubStatusCode from sending the event message.

Throws:

TransportException - if the IoT Hub could not be reached.

sendMessageResult

public boolean sendMessageResult(IotHubTransportMessage message, IotHubMessageResult result)

Sends the message result for the previously received message.

Overrides:

HttpsIotHubConnection.sendMessageResult(IotHubTransportMessage message, IotHubMessageResult result)

Parameters:

message - the message that was received from the service to send the result of
result - the message result (one of COMPLETE, ABANDON, or REJECT).

Throws:

TransportException -

ifsendMessageResult 

</code> is called before <xref uid="com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection.receiveMessage()" data-throw-if-not-resolved="false" data-raw-source="receiveMessage()"></xref> is called. </p>
TransportException - if the IoT Hub could not be reached.

setListener

public void setListener(IotHubListener listener)

Sets a listener into the Transport Connection object. This listener updates the Transport layer of connection status updates, message arrivals, and message acknowledgements

Overrides:

HttpsIotHubConnection.setListener(IotHubListener listener)

Parameters:

listener - the listener for connection status updates, message arrivals, and message acknowledgements

Applies to