user1950349 user1950349 - 1 year ago 212
Java Question

Getting InputStream with RestTemplate

I am using URL class to read an InputStream from it. Is there any way I can use RestTemplate for this?

InputStream input = new URL(url).openStream();
JsonReader reader = new JsonReader(new InputStreamReader(input, StandardCharsets.UTF_8.displayName()));

How can I get
instead of using

Answer Source

You can't. RestTemplate is meant to encapsulate processing the response (and request) content.

Instead, you can register appropriate HttpMessageConverter objects. Those will have access to the response's InputStream, through a HttpInputMessage object.

Theoretically, you could write a HttpMessageConverter that will retrieve and return the InputStream (or same wrapped version of it), but advise against that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download