amazon-web-services - 如何使用 apache camel 以 json 格式发送从 aws s3 下载的文件的内容?
问题描述
我有一个使用 apache camel 的 rest api。当我在一条路线上发出一个发布请求时,它会从 S3 获取一个文件。这是该代码->
public static class HelloRoute extends RouteBuilder {
@Override
public void configure() {
rest("/")
.post("file-from-s3")
.route()
.setHeader(AWS2S3Constants.KEY, constant("filename"))
.to("aws2-s3://bucketname?accessKey=INSERT&secretKey=INSERT®ion=INSERT&operation=getObject")
.endRest();
}
}
这给出了 Postman 中文件的内容。我想要 json 格式的响应,其中文件的内容将在content
json 的键中。这个怎么做?
解决方案
确保您在 REST 配置中启用了绑定模式 (auto|json) 并在您的路线上设置了消费/生产。现在编写您的处理器来构建您的响应对象并将其设置在正文中。Camel 将为您处理剩下的事情。
public static class HelloRoute extends RouteBuilder {
restConfiguration().component("netty-http").host("localhost").port(portNum).bindingMode(RestBindingMode.auto);
@Override
public void configure() {
rest("/")
.post("file-from-s3")
.consumes("application/json").type(YourRequest.class)
.produces("application/json").outType(YourResponse.class)
.route()
.setHeader(AWS2S3Constants.KEY, constant("filename"))
.to("aws2-s3://bucketname?accessKey=INSERT&secretKey=INSERT®ion=INSERT&operation=getObject")
//.process("responseBuilderProcessor")
.endRest();
}
}
推荐阅读
- unified-service-desk - Unified Service Desk 单一登录选项
- powerquery - 电源查询 - 具有动态列数的 List.NonNullCount
- java - 动态报告导出pdf类未找到异常错误
- python - 如何获取来自数组的选定数字的坐标
- php - 递归数组列表类别
- c - C 代码只能在一个项目中工作,不能在任何新项目中工作(不会写 txt 文件)
- javascript - 在 JavaScript 中创建对象数组的所有组合
- swift - 更改 ViewController 后计数器重置为零
- c# - C# SerialPort.Write()方法的误解
- c++ - 为什么在编译 makefile 时出现“错误 1181”?