I am trying to create a device in my IOT platform on google cloud. When following instructions and example i get "Cannot resolve symbol "RetryHttpInitializerWrapper". I have checked if I have the last Maven version, tested with both JDK 11 and 8, and searched around for anyone with the same problem.
Link to google cloud guide: https://cloud.google.com/iot/docs/how-tos/devices#iot-core-create-rs256-java
Link to google Github: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExample.java
In my code the only problem lies in line 57 where I try to create a new "RetryHttpInitializerWrapper" under the method "createDevice"
Here is my method:
public static void createDevice(
String projectId, String cloudRegion, String registryName, String deviceId)
throws GeneralSecurityException, IOException {
// [START create_device]
GoogleCredential credential =
GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
.build();
final String registryPath =
String.format(
"projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);
List<Device> devices =
service
.projects()
.locations()
.registries()
.devices()
.list(registryPath)
.setFieldMask("config,gatewayConfig")
.execute()
.getDevices();
if (devices != null) {
System.out.println("Found " + devices.size() + " devices");
for (Device d : devices) {
if ((d.getId() != null && d.getId().equals(deviceId))
|| (d.getName() != null && d.getName().equals(deviceId))) {
System.out.println("Device exists, skipping.");
return;
}
}
}
}
Here is my imports:
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.cloudiot.v1.CloudIot;
import com.google.api.services.cloudiot.v1.CloudIotScopes;
import com.google.api.services.cloudiot.v1.model.Device;
import com.google.cloud.Role;
import com.google.cloud.pubsub.v1.TopicAdminClient;
import com.google.iam.v1.Binding;
import com.google.pubsub.v1.Topic;
import com.google.pubsub.v1.TopicName;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
My POM.xml file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>no.something</groupId>
<artifactId>MQTTbridge</artifactId>
<version>11.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-pubsub-v1</artifactId>
<version>0.1.19</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.24.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-cloudiot</artifactId>
<version>v1-rev20181120-1.27.0</version>
</dependency>
</dependencies>