【发布时间】:2014-02-23 01:50:56
【问题描述】:
我有一个 Applet,它的方法是从浏览器中的 JavaScript 函数调用的。此方法最终会将文件发送到 Amazon S3 存储桶。但是,当此方法尝试创建 AmazonS3Client 时,该方法会失败且不显示任何错误。
方法内代码的相关sn-p为:
InputStream input = DigitalLive.class.getResourceAsStream("AwsCredentials.properties");
System.out.println("File loaded into Input Stream.");
PropertiesCredentials theCredentials = new PropertiesCredentials(input);
System.out.println("Credentials created.");
System.out.println("AccessKey is:" + theCredentials.getAWSAccessKeyId());
System.out.println("SecretKey is:" + theCredentials.getAWSSecretKey());
//All of the above strings print to the console with the correct AccessKey and SecretKey
try{
AmazonS3 s3Client = new AmazonS3Client(theCredentials);
//This message never prints
System.out.println("Client created.");
} catch(Exception e) {
//This message never prints
System.err.println("Error creating AmazonClient: " + e.getMessage());
}
try/catch 块中的任何消息都不会打印。该方法的其余代码(为简洁起见,此处未显示)也不会被触发。
jar 文件编译没有错误。我正在使用 jdk 1.7.0_51 和亚马逊 aws-java-sdk-1.7.1。我使用 Eclipse 作为 IDE,并使用 ANT 构建带有构建文件的 jar。
除了将代码包装在 try/catch 块中之外,我不确定还可以尝试什么。 我是否有不同/更好的方法来调试 Java 代码以了解为什么没有创建 AmazonS3Client?或者可能是上面的代码 sn-p 导致它失败的更明显的原因?
编辑:我在调用 Java 方法的 JavaScript 代码中添加了一个 try/catch 块,它会引发错误:
Error calling method on NPObject
Error: java.lang.reflect.InvocationTargetException
我认为这告诉我 Java Applet 实际上是在抛出错误。我只是不确定如何弄清楚是哪一个以及如何解决它。我试图在 AmazonS3 s3Client = new AmazonS3Client(theCredentials); 周围放置 try/catch 块,但 IDE 告诉我 Unreachable catch block for InvocationTargetException. This exception is never thrown from the try statement body。
【问题讨论】:
-
您是否尝试过使用类而不是接口(AmazonS3Client 而不是 AmazonS3)? AmazonS3Client s3Client = new AmazonS3Client(theCredentials);
-
@sallie 我现在刚试过,但结果和以前一样。
-
另一个黑暗建议 - 尝试使用 system.out 而不是 system.err,以防万一有东西吃掉你的标准错误。我没有什么绝妙的建议。只是“尝试一切”的方法。
-
@sallie 我很欣赏这些镜头。从 'err' 变成 'out' 运气不好。
标签: java javascript amazon-s3