Need to add a response to a ListenableFuture<ResponseEntity<byte[]>>

149 Views Asked by At

I have this code:

AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate();
asyncRestTemplate.setMessageConverters(new ArrayList<HttpMessageConverter<?>>() {{
    add(new ByteArrayHttpMessageConverter());
    add(new MappingJackson2HttpMessageConverter(mapper));
    add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
}});

ListenableFuture<ResponseEntity<byte[]>> f = asyncRestTemplate.exchange(
        templateUrlAndParams.getUrl(),
        HttpMethod.POST,
        new HttpEntity<>(reportScope, new HttpHeaders() {{
            add(HEADER_AUTHORIZATION, authToken);
            add(HEADER_ACCEPT, settings.getMediaType());
            add(HEADER_ACCEPT_LANGUAGE, DEFAULT_ACCEPT_LANGUAGE);
        }}),
        byte[].class, templateUrlAndParams.getQueryParams());

return FutureUtils.transformError(f, (ex)->chainSourceHttpException(ex, pathToInthinc, log));

And Other people need to create the endpoint that I'm calling. But in mind time I need to add a "mock response" with a ResponseEntity<byte[]> I tried to override the response but still don't make it working. Any idea of what I can do? Or how to send a fake response?

0

There are 0 best solutions below