当ObjectNode从extractFramesFlow(通过ObjectNode)并到达httpCallbackFlow(),成功地执行HTTP请求和JSON格式净荷“POST'ed到‘call_back’URI指定。奇怪的行为返回时从IntegrationFlows
@Bean
public IntegrationFlow extractFramesFlow() {
return IntegrationFlows.from(extractFramesChannel())
.handle(ObjectNode.class, (payload, headers) -> {
payload = validateFields(payload);
String path = payload.get("path").asText();
try {
File moviePath = new File(path);
ArrayNode arrayNode = mapper.createArrayNode();
String imageType = payload.path("image_type").asText("JPG");
String prefix = payload.path("prefix").asText();
Tools.thumbnails(moviePath, payload.get("slice").asInt(), payload.get("scale").asInt(),
imageType, prefix, file -> arrayNode.add(file.toString()));
payload.set("files", arrayNode);
} catch (IOException e) {
e.printStackTrace();
}
return payload;
}).enrichHeaders(h-> h.header("errorChannel", "asyncErrorChannel", true))
.<ObjectNode, Boolean>route(p-> !p.hasNonNull("id"),
m->m.channelMapping("true","httpCallbackFlow.input")
.channelMapping("false","uploadToS3Channel")).get();
}
@Bean
public IntegrationFlow httpCallbackFlow() {
return f->f.handle(Http.<JsonNode>outboundChannelAdapter(m->m.getPayload().get("call_back").asText()));
}
然而,当ObjectNode从handleAsyncErrors链()流动并到达同一httpCallbackFlow(),我们得到这是由
org.springframework.web.client.RestClientException引起一个异常:无法写入请求:在org.springframework.web.client.RestTemplate找不到适合请求类型[com.fasterxml.jackson.databind.node.ObjectNode]和内容类型[application/x-java-serialized-object] 的HttpMessageConverter $ HttpEntityRequestCallback.doWithRequest(RestTemplate.java:811) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:594) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:572) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:493) at org.springframework.integration.http。 outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:382) ...... 24多个
@Bean
public IntegrationFlow handleAsyncErrors() {
return IntegrationFlows.from(asyncErrorChannel())
.<MessagingException>handle((p, h) -> {
ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("call_back", "http://some.test.uri");
return objectNode;
}).channel("httpCallbackFlow.input").get();
}
我不知道为什么我们得到这个异常由完全相同的IntegrationFlow尽管处理。
谢谢你的回应,你是对的。 IntegrationFlow接受来自http客户端的POST请求,并且其contentType头部值设置为“application/json”,正如您已经指出的那样。该消息异步处理,结果将被发送回在JSON请求负载中定义的“call_back”URL。以这种方式重新使用标题可能不是一个好习惯。 – hanishi
是的;最好使用头richter(overwrite = true)明确设置contentType,而不是依赖某个上游组件设置(比如从入站请求继承它)。 –