Rudy B February 2016

Unable to load AWS Ivona Properties File Java

I'm using IVONA SpeachCloud SDK (Create speech sample): https://github.com/IvonaSoftware/ivona-speechcloud-sdk-java/blob/master/src/samples/IvonaSpeechCloudCreateSpeech/SampleIvonaSpeechCloudCreateSpeech.java

Using this code for setting the class path

private static IvonaSpeechCloudClient speechCloud;

private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}

Below is the format for ivona.properties file. File is located in base directory. Required credentials i've got in my SpeechCloud account

accessKey = mykey 
secretKey = mysecretKey

Below is the exception I am getting

Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load AWS credentials from the /resources/ivona.properties file on the classpath
at com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider.getCredentials(ClasspathPropertiesFileCredentialsProvider.java:81)
at com.ivona.services.tts.IvonaSpeechCloudClient.prepareRequest(IvonaSpeechCloudClient.java:279)
at com.ivona.services.tts.IvonaSpeechCloudClient.prepareRequest(IvonaSpeechCloudClient.java:272)
at com.ivona.services.tts.IvonaSpeechCloudClient.invoke(IvonaSpeechCloudClient.java:259)
at com.ivona.services.tts.IvonaSpeechCloudClient.createSpeech(IvonaSpeechCloudClient.java:148)
at SampleIvonaSpeechCloudCreateSpeech.main(SampleIvonaSpeechCloudCreateSpeech.java:45

How can I solve this exception or how can I make a class to get around this and manually enter my accessKey and secretKey as a String. Thanks.

Answers


Rudy B February 2016

Okay I figured this out after a few hours of messing around in the source files. You can make your own Provider Class where you can pass the credentials in as String Parameters.

This is my custom credential Class "IvonaCredentials"

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;

public class IvonaCredentials implements AWSCredentialsProvider{

public IvonaCredentials(String mSecretKey, String mAccessKey) {
    super();
    this.mSecretKey = mSecretKey;
    this.mAccessKey = mAccessKey;
}

private String mSecretKey;
private String mAccessKey;

@Override
public AWSCredentials getCredentials() {
    AWSCredentials awsCredentials = new AWSCredentials() {

        @Override
        public String getAWSSecretKey() {
            // TODO Auto-generated method stub
            return mSecretKey;
        }

        @Override
        public String getAWSAccessKeyId() {
            // TODO Auto-generated method stub
            return mAccessKey;
        };
    };
    return awsCredentials;
}

@Override
public void refresh() {
    // TODO Auto-generated method stub

}



}

This is how I call my class

private static void init() {
    speechCloud = new IvonaSpeechCloudClient(new IvonaCredentials("secretKey", "accessKey"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}

Post Status

Asked in February 2016
Viewed 2,609 times
Voted 11
Answered 1 times

Search




Leave an answer