gpt4 book ai didi

amazon-web-services - 使用 AWSCredentials 创建 AmazonDynamoDBClient

转载 作者:行者123 更新时间:2023-12-03 17:25:57 24 4
gpt4 key购买 nike

我们正在为 Android 手机开发一款基本游戏,最近已从 Eclipse IDE 切换到 Android Studios。通过切换,我被迫从 aws-java-sdk-1.9.30 迁移到 aws-android-sdk-2.2.0

我尝试更新 AWS 代码,它现在正在编译,但是我在创建 AmazonDynamoDBClient 时遇到了问题。

我收到这个运行时错误:

Exception in thread "main" java.lang.IllegalArgumentException: no HostnameVerifier specified

我不确定我是否在某处遗漏了一步。如果有人可以帮助阐明可能导致问题的原因,我将非常感激!

在相关说明中,我能够找到的大多数示例以及我的初始代码所基于的示例似乎都是针对 aws-java-sdk-1.9.30 jar 。如果有人知道我在哪里可以找到适合 aws-android-sdk-2.2.0 jar 的示例,那将会非常有帮助!

这是请求的整个堆栈跟踪:

CLIENT:com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient@5ef04b5
Creating Match Details...
Exception in thread "main" java.lang.IllegalArgumentException: no HostnameVerifier specified
at javax.net.ssl.HttpsURLConnection.setHostnameVerifier(HttpsURLConnection.java:265)
at com.amazonaws.http.UrlHttpClient.configureConnection(UrlHttpClient.java:169)
at com.amazonaws.http.UrlHttpClient.createConnection(UrlHttpClient.java:105)
at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:60)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:361)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:211)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2930)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.query(AmazonDynamoDBClient.java:1240)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.query(DynamoDBMapper.java:2181)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.query(DynamoDBMapper.java:2137)
at com.towerfield.aws.MatchDetails.getMatchIds(MatchDetails.java:201)
at com.towerfield.aws.MatchDetails.<init>(MatchDetails.java:109)
at com.towerfield.aws.MatchDetails.main(MatchDetails.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Process finished with exit code 1

这里是抛出异常的地方(在 HTTPSURLConnection.java 中):

public void setHostnameVerifier(HostnameVerifier v) 
{
if (v == null)
{
throw new IllegalArgumentException("HostnameVerifier is null");
}
hostnameVerifier = v;
}

这是导致运行时错误的相关代码:

static AmazonDynamoDBClient client;
...
BasicAWSCredentials credentials = new BasicAWSCredentials("KEY","SECRETKEY");
client = new AmazonDynamoDBClient(credentials);
...
DynamoDBMapper mapper = new DynamoDBMapper(client);
...
List<PlayersListOfActiveMatches> latestReplies = mapper.query(PlayersListOfActiveMatches.class, queryExpression);

这是我所要求的进口 list :

import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBAttribute;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBHashKey;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBQueryExpression;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBRangeKey;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBTable;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.Condition;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

最佳答案

适用于 Android 的 AWS 开发工具包的 DynamoDB 示例在 AWS documentation 中可用。 .

关于amazon-web-services - 使用 AWSCredentials 创建 AmazonDynamoDBClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30064911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com