0

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?

David_Garcia
  • 622
  • 7
  • 15
  • you need an `f` to return a fake byte[] here? just create an own implementation, a new instance and return it. – Balázs Németh Mar 28 '20 at 11:17
  • The problem is that `asyncRestTemplate.exchange` do the call and I dont want to do the call. I want to add this to the Future:```HttpHeaders headers = new HttpHeaders(); headers.setCacheControl(CacheControl.noCache().getHeaderValue()); ResponseEntity responseEntity = new ResponseEntity<>(extractPDF(), headers, HttpStatus.OK);``` – David_Garcia Mar 28 '20 at 11:41

0 Answers0