0

我有一个 JPA 消费者路线,它可以进行 POST 并丰富原始 Exchange:


@Component
public class GetDocumentPlaceholderRoute extends LateDeadLetterRoute {

    private static final AggregationStrategy finalizeImageProcess = (request, response) -> {
        var documentId = response.getMessage(DocumentResponseDto.class).getIntId();
        var imageProcess = request.getIn().getHeader("image-process",ImageProcess.class);
        imageProcess.setDocumentId(documentId);
        imageProcess.setDocumentIdReceivedTime(LocalDateTime.now(ZoneId.of("America/New_York")));

        imageProcess.setImageStatus("complete");
        imageProcess.setStepNote(null);
        var step = Optional.ofNullable(request.getIn().getHeader(STEP)).map(String::valueOf).orElse(null);
        imageProcess.setStep(step);

        return request;
    };

    @Autowired
    private ImageProcessJpaConsumerProperties jpaProps;

    @Autowired
    private AuditorServiceProperties auditorProps;

    @Autowired
    private DocumentIdFetcherProperties routeProps;

    @Override
    //@formatter:off
    public void configure() throws Exception {
        super.configure();

        HttpComponent httpComponent = getContext().getComponent("https", HttpComponent.class);
        httpComponent.setHttpClientConfigurer(new SelfSignedHttpClientConfigurer());

        from(
                jpa(ImageProcess.class.getName())
                        .query(routeProps.getJpaQuery())
                        .delay(jpaProps.getQueryDelay())
                        .maximumResults(jpaProps.getMaxResults())
                        .consumeDelete(jpaProps.getConsumeDelete())
                        .advanced()
                            .sharedEntityManager(true)
        )
                .streamCaching()
                .autoStartup(routeProps.isAutostart())
                .routeId("bill-image-document-id-placeholder-route")
                .description("Retrieves a document ID from the Auditor service")
                .setHeader(STEP, constant(routeProps.getStep()))
                .setHeader("image-process", simple("${body}"))
                .bean(DocumentRequestDto.class, "constructFromImageProcess")
                .setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .bean(ClientCredentialGrant.class, "setTokenHeader")
                .setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
                .marshal().json()
                .enrich(auditorProps.getBaseUrl() + auditorProps.getPath(),
                        finalizeImageProcess);
    }
    //@formatter:on
}

在 AggregationStrategy 的开头打破,这是响应交换中:

  • 来了HttpResponseCode:200
  • CamelHttpResponseText:“”
  • body 是 CachedOutputStream,包含我的数据的 CachedByteArrayOutputStream 的 currentStream
  • 我尝试用简单的“to”替换对“enrich”的调用,但我遇到了同样的问题,即使没有聚合策略
  • 当我尝试使用 Spring 的 RestTemplate 进行相同的调用时,我可以毫无问题地取回预期的数据
4

1 回答 1

0

这只是像这样定位 CachedInputStream 的问题:

response.getIn().getBody(String.class)
于 2021-11-14T16:27:52.103 回答