为什么我的Camel http响应正文是空的,尽管流缓存?

jv2fixgn  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(233)

我有一个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开始时中断,这是Exchange在中的响应:

  • 客户端HTTP响应代码:200
  • 驼峰式Http响应文本:““
  • 主体是CachedOutputStream,CachedByteArrayOutputStream的当前流包含我的数据
  • 我曾尝试将调用“enriched”替换为简单的“to”,但即使没有聚合策略,我也遇到了同样的问题
  • 当我尝试使用Spring的RestTemplate进行相同的调用时,我可以毫无问题地返回预期的数据
zwghvu4y

zwghvu4y1#

只需将CachedInputStream作为目标即可,如下所示:

response.getIn().getBody(String.class)

相关问题