使用AWSCredentials创建AmazonDynamoDBClient

时间:2015-05-05 23:28:22

标签: amazon-web-services android-studio amazon-dynamodb

我们正在开发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 罐子。如果有人知道我在哪里可以找到适合 aws-android-sdk-2.2.0 罐子的例子,那将会非常有用!

以下是所请求的整个堆栈跟踪:

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);

以下是我要求的导入列表:

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;

1 个答案:

答案 0 :(得分:1)

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