FaraBara
FaraBara

Reputation: 115

Why is my Camel http response body empty despite stream caching?

I have a JPA consumer route which makes a POST and enriches the original 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
}

Breaking at the beginning of the AggregationStrategy, this is the response Exchange in:

Upvotes: 0

Views: 649

Answers (1)

FaraBara
FaraBara

Reputation: 115

It was just a matter of targeting the CachedInputStream like this:

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

Upvotes: 0

Related Questions