【发布时间】:2022-12-10 00:23:58
【问题描述】:
通常你需要用InputPath, ResultPath and OutputPath做一些事情来处理你的数据。
但有时您需要像修改输入消息一样简单的操作,例如 camel do 和 Message EIP 或 Enricher EIP
这不是我能够轻易实现的。有什么解决办法?
【问题讨论】:
标签: java amazon-web-services aws-lambda integration-patterns
通常你需要用InputPath, ResultPath and OutputPath做一些事情来处理你的数据。
但有时您需要像修改输入消息一样简单的操作,例如 camel do 和 Message EIP 或 Enricher EIP
这不是我能够轻易实现的。有什么解决办法?
【问题讨论】:
标签: java amazon-web-services aws-lambda integration-patterns
考虑 Jackson tree model 的方法:
public class MyHandler extends JsonHandler<ObjectNode> {
@Override
public ObjectNode handleRequest(ObjectNode json, Context context) {
// enrich the input
json.putPOJO("enriched", pojo);
// return (the same) modified input object
return json;
// or replace it with something totally different
// return "Some other POJO";
}
}
其中 JsonHandler 父类定义为
public abstract class JsonHandler<R> implements RequestStreamHandler, RequestHandler<ObjectNode, R> {
private ObjectMapper objectMapper = new ObjectMapper();
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
ObjectNode json = (ObjectNode) objectMapper.readTree(input);
R result = handleRequest(json, context);
output.write(objectMapper.writeValueAsString(result).getBytes());
}
@Override
public abstract R handleRequest(ObjectNode json, Context context);
}
【讨论】: