Jax rs client lock input thread

I am working on a JAX-RS client application (using resteasy-client 3.0.8Final) that needs to read the (text) output passed by the REST service and just print it one by one to the console.

A manual hangup request for a service confirms that the output is being sent correctly, one at a time, as expected. However, when I try to read it from the java client, it seems that I can read (and therefore display) from the input stream after the stream is closed and the service call has completed. In other words, if the service produces one line of output every second or so, instead of displaying one line every second, I need to wait for the service call to complete, and then all the lines are displayed at once. Here's the code that handles the response:

final InputStream is = (InputStream)response.readEntity(InputStream.class);
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new BufferedInputStream(is)));

try
{
    String line;

    while ((line = bufferedReader.readLine()) != null)
    {
        System.out.println(line);
        System.out.flush();
    }
}
catch (Exception e)
{
    throw new IllegalStateException(e);
}

      

I expect the call to readLine

block and wait for a newline to appear, but seems to expect the InputStream to be closed (on a different thread?) Before reading, but my understanding is obviously faulty.

Does anyone see what I am missing?

+3


source to share





All Articles