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
java rest inputstream jax-rs


source to share


No one has answered this question yet

Check out similar questions:

3799
How do I read / convert an InputStream to a string in Java?
2248
Is a finally block always executable in Java?
826
Creating a byte array from a stream
356
Best Practice for REST Token Based Authentication with JAX-RS and Jersey
50
Read lock on InputStream Java
0
java.net.Socket> InputStream> BufferedReader.read (char []) is blocking the stream
0
BufferedReader Deadlock: How to properly shutdown BufferedReader
0
Reading data line by line in Java from input stream
0
MalformedInputException while streaming execution process execution results (cobol obj) through Java to AS400
0
Reading JSON file twice with BufferedReader



All Articles
Loading...
X
Show
Funny
Dev
Pics