#StackBounty: #java #jersey #jersey-client HTTP Stream dropping abnormally with java jersey client

Bounty: 50

For one of our project, we are consuming HTTP feed stream by using java jersey client

With the client Feed consuming is fine, but after the 10 mins of time, stream dropping abnormally; even though stream producer is up and running and producing the stream

This is what I tried;

import java.util.Date;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.ChunkedInput;

public class StreamClient {

    private static final String BOUNDARY = "n";

    public void makeCall() {
        System.out.println("Start Time"+ new Date()) ;
        Client client = ClientBuilder.newClient();
        BasicAuth auth = new BasicAuth();
        auth.setPassword("username");
        auth.setUserName("password");
        BasicAuthentication basicAuthentication = new BasicAuthentication(auth);
        client.register(basicAuthentication);
        WebTarget target = client.target("https://localhost:7211/stream/v1/");
        Builder request = target.request(MediaType.APPLICATION_JSON);
        Response response = request.get();

        final ChunkedInput<String> chunkedInput = response.readEntity(new GenericType<ChunkedInput<String>>() {
        });

        chunkedInput.setParser(ChunkedInput.createParser(BOUNDARY));
        String chunk;
        do {
            if((chunk = chunkedInput.read()) != null) 
                System.out.println(chunk);  
        }while (chunkedInput.isClosed());
        System.out.println("End Time " + new Date());
    }

    public static void main(String[] args) {
        StreamClient client = new StreamClient();
        client.makeCall();
    }


}

If stream doesn’t drop; thread has to be within the while loop; once the stream closes then thread will come out and print sysout statement

Here the question is; why chunkedinput is closed.

Please help me with resolution;


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.