【发布时间】:2020-10-26 23:56:30
【问题描述】:
我有一个从 S3 下载文件的 apache camel rest api。我发送 json input(key, bucketname, accessKey, secretKey, region) 以编写 URI。代码如下所示:
public static class HelloRoute extends RouteBuilder {
@Override
public void configure() {
rest("/")
.post("file-from-s3")
.route()
.setHeader(AWS2S3Constants.KEY, key)
.to("aws2-s3://bucketname?accessKey=INSERT&secretKey=INSERT®ion=INSERT&operation=getObject")
.endRest();
}
}
通过使用JSONObject 作为正文,我能够在上述代码中提到的位置获取相应的 json 输入。
如果假设,我在我的 json 输入中输入了错误的值(例如 accessKey),我会收到类似的错误
The AWS Access Key Id you provided does not exist in our records. (Service: S3, Status Code: 403, Request ID: 6923BEC55C1FD5F1, Extended Request ID: re5Rb7I76j9jvGqhSQXgjUoMwOZqsprg22bOGD+BDbuj0zrRrf0FceLaapvpR4KcNDY6GntNiF0=)
这不是很用户友好。我怎样才能为此编写一个自定义错误处理程序,它只会为上述情况返回一条错误消息,如 Wrong Access Key
【问题讨论】:
-
您能否发布完整的堆栈跟踪以查看异常是直接
AmazonS3Exception还是包含在另一个异常中? -
@Bedla 我收到此错误
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: aws2-s3://accesskey=AKIARGSIOJPSQRMGNS5&secretkey=xxxxxx&bucketname=jcnu-2020-swarnim-shukla&region=us-east-1&operation=getObject due to: useIAMCredentials is set to false, AmazonS3Client or accessKey and secretKey must be specified
标签: java exception error-handling apache-camel