80
80
*/
81
81
public class DeviceRegistryExample {
82
82
83
+ static final String APP_NAME = "DeviceRegistryExample" ;
84
+
83
85
/** Creates a topic and grants the IoT service account access. */
84
86
public static Topic createIotTopic (String projectId , String topicId ) throws Exception {
85
87
// Create a new topic
@@ -111,8 +113,9 @@ public static void createRegistry(String cloudRegion, String projectId, String r
111
113
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
112
114
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
113
115
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
114
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
115
- init );
116
+ final CloudIot service = new CloudIot .Builder (
117
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
118
+ .setApplicationName (APP_NAME ).build ();
116
119
117
120
final String projectPath = "projects/" + projectId + "/locations/" + cloudRegion ;
118
121
final String fullPubsubPath = "projects/" + projectId + "/topics/" + pubsubTopicPath ;
@@ -137,8 +140,9 @@ public static void deleteRegistry(String cloudRegion, String projectId, String r
137
140
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
138
141
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
139
142
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
140
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
141
- init );
143
+ final CloudIot service = new CloudIot .Builder (
144
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
145
+ .setApplicationName (APP_NAME ).build ();
142
146
143
147
String projectPath = "projects/" + projectId + "/locations/" + cloudRegion ;
144
148
String registryPath = projectPath + "/registries/" + registryName ;
@@ -154,8 +158,9 @@ public static void listDevices(String projectId, String cloudRegion, String regi
154
158
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
155
159
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
156
160
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
157
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
158
- init );
161
+ final CloudIot service = new CloudIot .Builder (
162
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
163
+ .setApplicationName (APP_NAME ).build ();
159
164
160
165
String registryPath = "projects/" + projectId + "/locations/" + cloudRegion + "/registries/"
161
166
+ registryName ;
@@ -193,8 +198,9 @@ public static void createDeviceWithEs256(String deviceId, String publicKeyFilePa
193
198
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
194
199
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
195
200
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
196
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
197
- init );
201
+ final CloudIot service = new CloudIot .Builder (
202
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
203
+ .setApplicationName (APP_NAME ).build ();
198
204
199
205
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
200
206
+ "/registries/" + registryName ;
@@ -233,8 +239,9 @@ public static void createDeviceWithRs256(String deviceId, String certificateFile
233
239
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
234
240
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
235
241
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
236
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
237
- init );
242
+ final CloudIot service = new CloudIot .Builder (
243
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
244
+ .setApplicationName (APP_NAME ).build ();
238
245
239
246
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
240
247
+ "/registries/" + registryName ;
@@ -276,8 +283,9 @@ public static void createDeviceWithNoAuth(String deviceId, String projectId, Str
276
283
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
277
284
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
278
285
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
279
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
280
- init );
286
+ final CloudIot service = new CloudIot .Builder (
287
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
288
+ .setApplicationName (APP_NAME ).build ();
281
289
282
290
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
283
291
+ "/registries/" + registryName ;
@@ -306,8 +314,9 @@ public static void deleteDevice(String deviceId, String projectId, String cloudR
306
314
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
307
315
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
308
316
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
309
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
310
- init );
317
+ final CloudIot service = new CloudIot .Builder (
318
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
319
+ .setApplicationName (APP_NAME ).build ();
311
320
312
321
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
313
322
+ "/registries/" + registryName ;
@@ -324,8 +333,9 @@ public static Device getDevice(String deviceId, String projectId, String cloudRe
324
333
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
325
334
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
326
335
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
327
- CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
328
- init );
336
+ final CloudIot service = new CloudIot .Builder (
337
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
338
+ .setApplicationName (APP_NAME ).build ();
329
339
330
340
String registryPath = "projects/" + projectId + "/locations/" + cloudRegion + "/registries/"
331
341
+ registryName ;
@@ -343,8 +353,9 @@ public static List<DeviceState> getDeviceStates(
343
353
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
344
354
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
345
355
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
346
- CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
347
- init );
356
+ final CloudIot service = new CloudIot .Builder (
357
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
358
+ .setApplicationName (APP_NAME ).build ();
348
359
349
360
String registryPath = "projects/" + projectId + "/locations/" + cloudRegion + "/registries/"
350
361
+ registryName ;
@@ -365,8 +376,9 @@ public static DeviceRegistry getRegistry(
365
376
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
366
377
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
367
378
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
368
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
369
- init );
379
+ final CloudIot service = new CloudIot .Builder (
380
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
381
+ .setApplicationName (APP_NAME ).build ();
370
382
371
383
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
372
384
+ "/registries/" + registryName ;
@@ -381,8 +393,9 @@ public static void listDeviceConfigs(
381
393
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
382
394
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
383
395
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
384
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
385
- init );
396
+ final CloudIot service = new CloudIot .Builder (
397
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
398
+ .setApplicationName (APP_NAME ).build ();
386
399
387
400
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
388
401
+ "/registries/" + registryName ;
@@ -414,8 +427,9 @@ public static void listRegistries(String projectId, String cloudRegion)
414
427
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
415
428
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
416
429
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
417
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
418
- init );
430
+ final CloudIot service = new CloudIot .Builder (
431
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
432
+ .setApplicationName (APP_NAME ).build ();
419
433
420
434
final String projectPath = "projects/" + projectId + "/locations/" + cloudRegion ;
421
435
@@ -451,8 +465,9 @@ public static void modifyCloudToDeviceConfig(String deviceId, String configData,
451
465
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
452
466
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
453
467
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
454
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
455
- init );
468
+ final CloudIot service = new CloudIot .Builder (
469
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
470
+ .setApplicationName (APP_NAME ).build ();
456
471
457
472
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
458
473
+ "/registries/" + registryName ;
@@ -480,8 +495,9 @@ public static void patchEs256ForAuth(String deviceId, String publicKeyFilePath,
480
495
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
481
496
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
482
497
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
483
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
484
- init );
498
+ final CloudIot service = new CloudIot .Builder (
499
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
500
+ .setApplicationName (APP_NAME ).build ();
485
501
486
502
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
487
503
+ "/registries/" + registryName ;
@@ -505,7 +521,7 @@ public static void patchEs256ForAuth(String deviceId, String publicKeyFilePath,
505
521
.registries ()
506
522
.devices ()
507
523
.patch (devicePath , device )
508
- .setFields ("credentials" )
524
+ .setUpdateMask ("credentials" )
509
525
.execute ();
510
526
511
527
System .out .println ("Patched device is " + patchedDevice .toPrettyString ());
@@ -520,8 +536,9 @@ public static void patchRsa256ForAuth(String deviceId, String publicKeyFilePath,
520
536
GoogleCredential .getApplicationDefault ().createScoped (CloudIotScopes .all ());
521
537
JsonFactory jsonFactory = JacksonFactory .getDefaultInstance ();
522
538
HttpRequestInitializer init = new RetryHttpInitializerWrapper (credential );
523
- final CloudIot service = new CloudIot (GoogleNetHttpTransport .newTrustedTransport (), jsonFactory ,
524
- init );
539
+ final CloudIot service = new CloudIot .Builder (
540
+ GoogleNetHttpTransport .newTrustedTransport (),jsonFactory , init )
541
+ .setApplicationName (APP_NAME ).build ();
525
542
526
543
final String registryPath = "projects/" + projectId + "/locations/" + cloudRegion
527
544
+ "/registries/" + registryName ;
@@ -545,7 +562,7 @@ public static void patchRsa256ForAuth(String deviceId, String publicKeyFilePath,
545
562
.registries ()
546
563
.devices ()
547
564
.patch (devicePath , device )
548
- .setFields ("credentials" )
565
+ .setUpdateMask ("credentials" )
549
566
.execute ();
550
567
551
568
System .out .println ("Patched device is " + patchedDevice .toPrettyString ());
0 commit comments