ProvisioningServiceClient 类

定义

Device Provisioning Service Client.

The IoT Hub Device Provisioning Service is a helper service for IoT Hub that enables automatic device provisioning to a specified IoT hub without requiring human intervention. You can use the Device Provisioning Service to provision millions of devices in a secure and scalable manner.

This java SDK provides an API to help developers to create and maintain Enrollments on the IoT Hub Device Provisioning Service, it translate the rest API in java Objects and Methods.

To use the this SDK, you must include the follow package on your application.

// Include the following imports to use the Device Provisioning Service APIs.
import com.microsoft.azure.sdk.iot.provisioning.service.*;

</code></pre></p>

The main APIs are exposed by the ProvisioningServiceClient, it contains the public Methods that the application shall call to create and maintain the Enrollments. The Objects in the configs package shall be filled and passed as parameters of the public API, for example, to create a new enrollment, the application shall create the object IndividualEnrollment with the appropriate enrollment configurations, and call the createOrUpdateIndividualEnrollment(IndividualEnrollment individualEnrollment).

The IoT Hub Device Provisioning Service supports SQL queries too. The application can create a new query using one of the queries factories, for instance createIndividualEnrollmentQuery(QuerySpecification querySpecification), passing the QuerySpecification, with the SQL query. This factory returns a Query object, which is an active iterator.

This java SDK can be represented in the follow diagram, the first layer are the public APIs the your application shall use:


    +===============+       +==========================================+                           +============+   +===+

    |    configs    |------>|         ProvisioningServiceClient        |                        +->|    Query   |   |   |

    +===============+       +==+=================+==================+==+                        |  +======+=====+   | e |

                              /                  |                   \                          |         |         | x |

                             /                   |                    \                         |         |         | c |

    +-----------------------+-----+  +-----------+------------+  +-----+---------------------+  |         |         | e |

    | IndividualEnrollmentManager |  | EnrollmentGroupManager |  | RegistrationStatusManager |  |         |         | p |

    +---------------+------+------+  +-----------+------+-----+  +-------------+-------+-----+  |         |         | t |

                     \      \                    |       \                     |        \       |         |         | i |

                      \      +----------------------------+------------------------------+------+         |         | o |

                       \                         |                             |                          |         | n |

     +--------+      +--+------------------------+-----------------------------+--------------------------+-----+   | s |

     |  auth  |----->|                                     ContractApiHttp                                      |   |   |

     +--------+      +-------------------------------------------+----------------------------------------------+   +===+

                                                                 |

                                                                 |

                           +-------------------------------------+------------------------------------------+

                           |                 com.microsoft.azure.sdk.iot.deps.transport.http                |

                           +--------------------------------------------------------------------------------+

    

  

public class ProvisioningServiceClient
继承
java.lang.Object
ProvisioningServiceClient

方法

createEnrollmentGroupQuery(QuerySpecification querySpecification)

Factory to create an enrollmentGroup query.

This method will create a new enrollment group query on Device Provisioning Service and return it as a Query iterator.

The Device Provisioning Service expects a SQL query in the QuerySpecification, for instance "SELECT * FROM enrollments" 

</code> .</p>

createEnrollmentGroupQuery(QuerySpecification querySpecification, int pageSize)

Factory to create an enrollmentGroup query.

This method will create a new enrollment group query on Device Provisioning Service and return it as a Query iterator.

The Device Provisioning Service expects a SQL query in the QuerySpecification, for instance "SELECT * FROM enrollments" 

</code> .</p>

For each iteration, the Query will return a List of objects correspondent to the query result. The maximum number of items per iteration can be specified by the pageSize. It is optional, you can provide 0 for default pageSize or use the API createEnrollmentGroupQuery(QuerySpecification querySpecification).

createEnrollmentGroupRegistrationStateQuery(QuerySpecification querySpecification, String enrollmentGroupId)

Factory to create a registration status query.

This method will create a new registration status query for a specific enrollment group on the Device Provisioning Service and return it as a Query iterator.

The Device Provisioning Service expects a SQL query in the QuerySpecification, for instance "SELECT * FROM enrollments" 

</code> .</p>

createEnrollmentGroupRegistrationStateQuery(QuerySpecification querySpecification, String enrollmentGroupId, int pageSize)

Factory to create a registration status query.

This method will create a new registration status query for a specific enrollment group on the Device Provisioning Service and return it as a Query iterator.

The Device Provisioning Service expects a SQL query in the QuerySpecification, for instance "SELECT * FROM enrollments" 

</code> .</p>

For each iteration, the Query will return a List of objects correspondent to the query result. The maximum number of items per iteration can be specified by the pageSize. It is optional, you can provide 0 for default pageSize or use the API createIndividualEnrollmentQuery(QuerySpecification querySpecification).

createEnrollmentGroupRegistrationStatusQuery(QuerySpecification querySpecification, String enrollmentGroupId)

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>As of release 1.0.0, replaced by <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupRegistrationStateQuery(QuerySpecification,String)" data-throw-if-not-resolved="false" data-raw-source="createEnrollmentGroupRegistrationStateQuery(QuerySpecification, String)"></xref> ()} </p>

</xrefdescription>

createEnrollmentGroupRegistrationStatusQuery(QuerySpecification querySpecification, String enrollmentGroupId, int pageSize)

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>As of release 1.0.0, replaced by <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupRegistrationStateQuery(QuerySpecification,String,int)" data-throw-if-not-resolved="false" data-raw-source="createEnrollmentGroupRegistrationStateQuery(QuerySpecification, String, int)"></xref> ()} </p>

</xrefdescription>

createFromConnectionString(String connectionString)

Create a new instance of theDeviceProvisioningServiceClient 

</code> that exposes the API to the Device Provisioning Service.</p>

The Device Provisioning Service Client is created based on a Provisioning Connection String.

Once you create a Device Provisioning Service on Azure, you can get the connection string on the Azure portal.

createIndividualEnrollmentQuery(QuerySpecification querySpecification)

Factory to create a individualEnrollment query.

This method will create a new individualEnrollment query for Device Provisioning Service and return it as a Query iterator.

The Device Provisioning Service expects a SQL query in the QuerySpecification, for instance "SELECT * FROM enrollments" 

</code> .</p>

createIndividualEnrollmentQuery(QuerySpecification querySpecification, int pageSize)

Factory to create a individualEnrollment query.

This method will create a new individualEnrollment query for Device Provisioning Service and return it as a Query iterator.

The Device Provisioning Service expects a SQL query in the QuerySpecification, for instance "SELECT * FROM enrollments" 

</code> .</p>

For each iteration, the Query will return a List of objects correspondent to the query result. The maximum number of items per iteration can be specified by the pageSize. It is optional, you can provide 0 for default pageSize or use the API createIndividualEnrollmentQuery(QuerySpecification querySpecification).

createOrUpdateEnrollmentGroup(EnrollmentGroup enrollmentGroup)

Create or update an enrollment group record.

This API creates a new enrollment group or update a existed one. All enrollment group in the Device Provisioning Service contains a unique identifier called enrollmentGroupId. If this API is called with an enrollmentGroupId that already exists, it will replace the existed enrollmentGroup information by the new one. On the other hand, if the enrollmentGroupId does not exit, it will be created.

To use the Device Provisioning Service API, you must include the follow package on your application.

// Include the following imports to use the Device Provisioning Service APIs.
    import com.microsoft.azure.sdk.iot.provisioning.service.*;
    

Sample:

The follow code will create a new enrollmentGroup that will provisioning multiple devices to the ContosoHub.azure-devices.net.

// EnrollmentGroup information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String ENROLLMENT_GROUP_ID = "enrollmentGroupId-1";
    private static final String IOTHUB_HOST_NAME = "ContosoHub.azure-devices.net";
    private static String PUBLIC_CERTIFICATE_STRING =
            "-----BEGIN CERTIFICATE-----\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" +
            "-----END CERTIFICATE-----\n";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Create a new enrollmentGroup configurations.
        Attestation attestation = X509Attestation.createFromSigningCertificates(PUBLIC_KEY_CERTIFICATE_STRING);
        EnrollmentGroup enrollmentGroup =
            new EnrollmentGroup(
                enrollmentGroupId,
                attestation);
        enrollmentGroup.setIotHubHostName(IOTHUB_HOST_NAME);
        enrollmentGroup.setProvisioningStatus(ProvisioningStatus.ENABLED);
    
        // Create a new enrollmentGroup.
        EnrollmentGroup enrollmentGroupResult =  provisioningServiceClient.createOrUpdateEnrollmentGroup(enrollmentGroup);
    }
    

createOrUpdateIndividualEnrollment(IndividualEnrollment individualEnrollment)

Create or update a individual Device Enrollment record.

This API creates a new individualEnrollment or update a existed one. All enrollments in the Device Provisioning Service contains a unique identifier called registrationId. If this API is called for an individualEnrollment with a registrationId that already exists, it will replace the existed individualEnrollment information by the new one. On the other hand, if the registrationId does not exit, this API will create a new individualEnrollment.

To use the Device Provisioning Service API, you must include the follow package on your application.

// Include the following imports to use the Device Provisioning Service APIs.
    import com.microsoft.azure.sdk.iot.provisioning.service.*;
    

Sample:

The follow code will create a new individualEnrollment that will provisioning the ContosoDevice1000 to the ContosoHub.azure-devices.net using TPM attestation.

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String TPM_ENDORSEMENT_KEY = "tpm-endorsement-key";
    private static final String REGISTRATION_ID = "registrationId-1";
    private static final String DEVICE_ID = "ContosoDevice1000";
    private static final String IOTHUB_HOST_NAME = "ContosoHub.azure-devices.net";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Create a new individualEnrollment configurations.
        Attestation attestation = new TpmAttestation(TPM_ENDORSEMENT_KEY);
        IndividualEnrollment individualEnrollment =
           new IndividualEnrollment(
                REGISTRATION_ID,
                attestation);
        individualEnrollment.setDeviceId(DEVICE_ID);
        individualEnrollment.setIotHubHostName(IOTHUB_HOST_NAME);
        individualEnrollment.setProvisioningStatus(ProvisioningStatus.DISABLED);
    
        // Create a new individualEnrollment.
        IndividualEnrollment enrollmentResult =  deviceProvisioningServiceClient.createOrUpdateIndividualEnrollment(individualEnrollment);
    }
    

If the registrationId already exists, this method will update existed enrollments. Note that update the individualEnrollment will not change the status of the device that was already registered using the old individualEnrollment.

The follow code will update the provisioningStatus of the previous individualEnrollment from disabled to enabled.

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Get the content of the previous individualEnrollment.
        IndividualEnrollment individualEnrollment =  deviceProvisioningServiceClient.getIndividualEnrollment(REGISTRATION_ID);
    
        // Change the provisioning status, from disabled to enabled
        individualEnrollment.setProvisioningStatus(ProvisioningStatus.ENABLED);
    
        // Update the individualEnrollment information.
        IndividualEnrollment enrollmentResult =  deviceProvisioningServiceClient.createOrUpdateIndividualEnrollment(individualEnrollment);
    }
    

deleteDeviceRegistrationState(DeviceRegistrationState deviceRegistrationState)

Delete the Registration Status information.

This method will remove the DeviceRegistrationState from the Device Provisioning Service using the provided DeviceRegistrationState information. The Device Provisioning Service will care about the id and the eTag on the DeviceRegistrationState. If you want to delete the deviceRegistrationState regardless the eTag, you can use the deleteDeviceRegistrationState(String id) passing only the id.

If the id does not exists or the eTag does not matches, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the deviceRegistrationState "registrationId-1".

// Registration Status information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Get the registration status information.
        DeviceRegistrationState registrationStateResult =  deviceProvisioningServiceClient.getDeviceRegistrationState(REGISTRATION_ID);
    
        // Delete the registration status information.
        deviceProvisioningServiceClient.deleteDeviceRegistrationState(registrationStateResult);
    }
    

deleteDeviceRegistrationState(String id)

Delete the registration status information.

This method will remove the DeviceRegistrationState from the Device Provisioning Service using the provided id. It will delete the registration status regardless the eTag. It means that this API correspond to the deleteDeviceRegistrationState(String id, String eTag) with theeTag="*"  .

If the id does not exists, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the registration status "registrationId-1".

// deviceRegistrationState information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Delete the registration status information.
        deviceProvisioningServiceClient.deleteDeviceRegistrationState(REGISTRATION_ID);
    }
    

deleteDeviceRegistrationState(String id, String eTag)

Delete the registration status information.

This method will remove the registration status from the Device Provisioning Service using the provided id and eTag. If you want to delete the registration status regardless the eTag, you can use deleteDeviceRegistrationState(String id) or you can pass the eTag asnull  , empty, or "*"  .

If the id does not exists or the eTag does not matches, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the deviceRegistrationState "registrationId-1" regardless the eTag.

// Registration Status information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    private Static final String ANY_ETAG = "*";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Delete the deviceRegistrationState information.
        deviceProvisioningServiceClient.deleteDeviceRegistrationState(REGISTRATION_ID, ANY_ETAG);
    }
    

deleteDeviceRegistrationStatus(DeviceRegistrationState deviceRegistrationState)

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>As of release 1.0.0, replaced by <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.deleteDeviceRegistrationState(DeviceRegistrationState)" data-throw-if-not-resolved="false" data-raw-source="deleteDeviceRegistrationState(DeviceRegistrationState)"></xref> ()} </p>

</xrefdescription>

deleteDeviceRegistrationStatus(String id)

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>As of release 1.0.0, replaced by <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.deleteDeviceRegistrationState(String)" data-throw-if-not-resolved="false" data-raw-source="deleteDeviceRegistrationState(String)"></xref> ()} </p>

</xrefdescription>

deleteDeviceRegistrationStatus(String id, String eTag)

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>As of release 1.0.0, replaced by <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.deleteDeviceRegistrationState(String,String)" data-throw-if-not-resolved="false" data-raw-source="deleteDeviceRegistrationState(String, String)"></xref> ()} </p>

</xrefdescription>

deleteEnrollmentGroup(EnrollmentGroup enrollmentGroup)

Delete the enrollmentGroup information.

This method will remove the enrollmentGroup from the Device Provisioning Service using the provided EnrollmentGroup information. The Device Provisioning Service will care about the enrollmentGroupId and the eTag on the enrollmentGroup. If you want to delete the enrollment regardless the eTag, you can set theeTag="*"  into the enrollmentGroup, or use the deleteEnrollmentGroup(String enrollmentGroupId) passing only the enrollmentGroupId.

Note that delete the enrollmentGroup will not remove the Devices itself from the IotHub.

If the enrollmentGroupId does not exists or the eTag does not matches, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the enrollmentGroup "enrollmentGroupId-1".

// EnrollmentGroup information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String ENROLLMENT_GROUP_ID = "enrollmentGroupId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Get the enrollmentGroup information.
        EnrollmentGroup enrollmentGroupResult =  deviceProvisioningServiceClient.getEnrollmentGroup(ENROLLMENT_GROUP_ID);
    
        // Delete the enrollmentGroup information.
        deviceProvisioningServiceClient.deleteEnrollmentGroup(enrollmentResult);
    }
    

deleteEnrollmentGroup(String enrollmentGroupId)

Delete the enrollmentGroup information.

This method will remove the enrollmentGroup from the Device Provisioning Service using the provided enrollmentGroupId. It will delete the enrollmentGroup regardless the eTag. It means that this API correspond to the deleteEnrollmentGroup(String enrollmentGroupId, String eTag) with theeTag="*"  .

Note that delete the enrollmentGroup will not remove the Devices itself from the IotHub.

If the enrollmentGroupId does not exists, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the enrollmentGroup "enrollmentGroupId-1".

// EnrollmentGroup information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String ENROLLMENT_GROUP_ID = "enrollmentGroupId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Delete the enrollmentGroup information.
        deviceProvisioningServiceClient.deleteEnrollmentGroup(ENROLLMENT_GROUP_ID);
    }
    

deleteEnrollmentGroup(String enrollmentGroupId, String eTag)

Delete the enrollmentGroup information.

This method will remove the enrollmentGroup from the Device Provisioning Service using the provided enrollmentGroupId and eTag. If you want to delete the enrollmentGroup regardless the eTag, you can use deleteEnrollmentGroup(String enrollmentGroupId) or you can pass the eTag asnull  , empty, or "*"  .

Note that delete the enrollmentGroup will not remove the Device itself from the IotHub.

If the enrollmentGroupId does not exists or eTag does not matches, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the enrollmentGroup "enrollmentGroupId-1" regardless the eTag.

// enrollmentGroup information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String ENROLLMENT_GROUP_ID = "enrollmentGroupId-1";
    private Static final String ANY_ETAG = "*";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Delete the enrollmentGroup information.
        deviceProvisioningServiceClient.deleteEnrollmentGroup(ENROLLMENT_GROUP_ID, ANY_ETAG);
    }
    

deleteIndividualEnrollment(IndividualEnrollment individualEnrollment)

Delete the individualEnrollment information.

This method will remove the individualEnrollment from the Device Provisioning Service using the provided IndividualEnrollment information. The Device Provisioning Service will care about the registrationId and the eTag on the individualEnrollment. If you want to delete the individualEnrollment regardless the eTag, you can set theeTag="*"  into the individualEnrollment, or use the deleteIndividualEnrollment(String registrationId) passing only the registrationId.

Note that delete the individualEnrollment will not remove the Device itself from the IotHub.

If the registrationId does not exists or the eTag not matches, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the individualEnrollment "registrationId-1".

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Get the individualEnrollment information.
        IndividualEnrollment enrollmentResult =  deviceProvisioningServiceClient.getIndividualEnrollment(REGISTRATION_ID);
    
        // Delete the individualEnrollment information.
        deviceProvisioningServiceClient.deleteIndividualEnrollment(enrollmentResult);
    }
    

deleteIndividualEnrollment(String registrationId)

Delete the individualEnrollment information.

This method will remove the individualEnrollment from the Device Provisioning Service using the provided registrationId. It will delete the enrollment regardless the eTag. It means that this API correspond to the deleteIndividualEnrollment(String registrationId, String eTag) with theeTag="*"  .

Note that delete the enrollment will not remove the Device itself from the IotHub.

If the registrationId does not exists, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the individualEnrollment "registrationId-1".

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Delete the individualEnrollment information.
        deviceProvisioningServiceClient.deleteIndividualEnrollment(REGISTRATION_ID);
    }
    

deleteIndividualEnrollment(String registrationId, String eTag)

Delete the individualEnrollment information.

This method will remove the individualEnrollment from the Device Provisioning Service using the provided registrationId and eTag. If you want to delete the enrollment regardless the eTag, you can use deleteIndividualEnrollment(String registrationId) or you can pass the eTag asnull  , empty, or "*"  .

Note that delete the enrollment will not remove the Device itself from the IotHub.

If the registrationId does not exists or the eTag does not matches, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will delete the information about the individualEnrollment "registrationId-1" regardless the eTag.

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    private Static final String ANY_ETAG = "*";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Delete the individualEnrollment information.
        deviceProvisioningServiceClient.deleteIndividualEnrollment(REGISTRATION_ID, ANY_ETAG);
    }
    

getDeviceRegistrationState(String id)

Retrieve the registration status information.

This method will return the DeviceRegistrationState for the provided id. It will retrieve the correspondent deviceRegistrationState from the Device Provisioning Service, and return it in the DeviceRegistrationState object.

If the id do not exists, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will get and print the information about the deviceRegistrationState "registrationId-1".

// Registration status information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Get the deviceRegistrationState information.
        DeviceRegistrationState registrationStateResult =  deviceProvisioningServiceClient.getDeviceRegistrationState(REGISTRATION_ID);
        System.out.println(registrationStateResult.toString());
    }
    

getEnrollmentGroup(String enrollmentGroupId)

Retrieve the enrollmentGroup information.

This method will return the enrollmentGroup information for the provided enrollmentGroupId. It will retrieve the correspondent enrollmentGroup from the Device Provisioning Service, and return it in the EnrollmentGroup object.

If the enrollmentGroupId does not exists, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will get and print the information about the enrollmentGroupId "enrollmentGroupId-1".

// EnrollmentGroup information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String ENROLLMENT_GROUP_ID = "enrollmentGroupId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Get the individualEnrollment information.
        EnrollmentGroup enrollmentGroupResult =  deviceProvisioningServiceClient.getEnrollmentGroup(ENROLLMENT_GROUP_ID);
        System.out.println(enrollmentGroupResult.toString());
    }
    

getEnrollmentGroupAttestationMechanism(String enrollmentGroupId)

Get the attestation mechanism details for a given enrollment group

getIndividualEnrollment(String registrationId)

Retrieve the individualEnrollment information.

This method will return the enrollment information for the provided registrationId. It will retrieve the correspondent individualEnrollment from the Device Provisioning Service, and return it in the IndividualEnrollment object.

If the registrationId do not exists, this method will throw ProvisioningServiceClientNotFoundException. for more exceptions that this method can throw, please see ProvisioningServiceClientExceptionManager

Sample:

The follow code will get and print the information about the individualEnrollment "registrationId-1".

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String REGISTRATION_ID = "registrationId-1";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Get the individualEnrollment information.
        IndividualEnrollment enrollmentResult =  deviceProvisioningServiceClient.getIndividualEnrollment(REGISTRATION_ID);
        System.out.println(enrollmentResult.toString());
    }
    

getIndividualEnrollmentAttestationMechanism(String registrationId)

Get the attestation mechanism details for a given individual enrollment

runBulkEnrollmentOperation(BulkOperationMode bulkOperationMode, Collection<IndividualEnrollment> individualEnrollments)

Create, update or delete a set of individual Device Enrollments.

This API provide the means to do a single operation over multiple individualEnrollments. A valid operation is determined by BulkOperationMode, and can be 'create', 'update', 'updateIfMatchETag', or 'delete'.

To use the Device Provisioning Service API, you must include the follow package on your application.

// Include the following imports to use the Device Provisioning Service APIs.
    import com.microsoft.azure.sdk.iot.provisioning.service.*;
    

Sample:

The follow code will create two new enrollment that will provisioning the ContosoDevice1000 and ContosoDevice1001 to the ContosoHub.azure-devices.net using TPM attestation.

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String TPM_ENDORSEMENT_KEY = "tpm-endorsement-key";
    private static final String IOTHUB_HOST_NAME = "ContosoHub.azure-devices.net";
    
    private static final String REGISTRATION_ID_1 = "registrationId-1";
    private static final String DEVICE_ID_1 = "ContosoDevice1000";
    
    private static final String REGISTRATION_ID_2 = "registrationId-2";
    private static final String DEVICE_ID_2 = "ContosoDevice1001";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Create two new individualEnrollment configurations.
        Attestation attestation = new TpmAttestation(TPM_ENDORSEMENT_KEY);
        IndividualEnrollment enrollment1 =
           new IndividualEnrollment(
                REGISTRATION_ID_1,
                attestation);
        enrollment1.setDeviceId(DEVICE_ID_1);
        enrollment1.setIotHubHostName(IOTHUB_HOST_NAME);
        enrollment1.setProvisioningStatus(ProvisioningStatus.DISABLED);
    
        IndividualEnrollment enrollment2 =
           new IndividualEnrollment(
                REGISTRATION_ID_2,
                attestation);
        enrollment2.setDeviceId(DEVICE_ID_2);
        enrollment2.setIotHubHostName(IOTHUB_HOST_NAME);
        enrollment2.setProvisioningStatus(ProvisioningStatus.DISABLED);
    
        // Add these 2 individualEnrollments to a list of individualEnrollments.
        List<IndividualEnrollment> individualEnrollments = new LinkedList<>();
        individualEnrollments.add(enrollment1);
        individualEnrollments.add(enrollment2);
    
        // Create these 2 new individualEnrollment using the bulk operation.
        BulkEnrollmentOperationResult bulkEnrollmentOperationResult =  provisioningServiceClient.runBulkEnrollmentOperation(BulkOperationMode.create, individualEnrollments);
    }
    

适用于