无法解析符号 RetryHttpInitializerWrapper - Google IOT
Cannot resolve symbol RetryHttpInitializerWrapper - Google IOT
我正在尝试在 google 云上的 IOT 平台中创建一个设备。当按照说明和示例进行操作时,我得到 "Cannot resolve symbol "RetryHttpInitializerWrapper”。我检查了我是否有最新的 Maven 版本,用 JDK 11 和 8 进行了测试,并搜索了有同样问题的人。
Link转google云导:https://cloud.google.com/iot/docs/how-tos/devices#iot-core-create-rs256-java
Link 到 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
在我的代码中,唯一的问题在于第 57 行,我尝试在 "createDevice"
方法下创建一个新的 "RetryHttpInitializerWrapper"
这是我的方法:
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;
}
}
}
}
这是我的导入:
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;
我的 POM.xml 文件如下所示:
<?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>
您拥有的任何 Maven 依赖项中似乎都不存在 class RetryHttpInitializerWrapper.class。我还查看了 java-docs-samples 在 github 中引用的 Maven 存储库,但它似乎也没有被推送到那里。您可以查看 Google 在 Github 上的 RetryHttpInitializerWrapper 示例实现,并可能创建您自己的:
我正在尝试在 google 云上的 IOT 平台中创建一个设备。当按照说明和示例进行操作时,我得到 "Cannot resolve symbol "RetryHttpInitializerWrapper”。我检查了我是否有最新的 Maven 版本,用 JDK 11 和 8 进行了测试,并搜索了有同样问题的人。
Link转google云导:https://cloud.google.com/iot/docs/how-tos/devices#iot-core-create-rs256-java
Link 到 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
在我的代码中,唯一的问题在于第 57 行,我尝试在 "createDevice"
方法下创建一个新的 "RetryHttpInitializerWrapper"这是我的方法:
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;
}
}
}
}
这是我的导入:
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;
我的 POM.xml 文件如下所示:
<?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>
您拥有的任何 Maven 依赖项中似乎都不存在 class RetryHttpInitializerWrapper.class。我还查看了 java-docs-samples 在 github 中引用的 Maven 存储库,但它似乎也没有被推送到那里。您可以查看 Google 在 Github 上的 RetryHttpInitializerWrapper 示例实现,并可能创建您自己的: