HTTP Stream dropping abnormally with java jersey client

Creator :

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;

Here, for every payload/chunk separation on the server end it is \r\n and to make it connection active from the server, sending \n (on the client end, I have to ignore this.)

Raul Lapeira Herrero :

I would recommend using wireshark to analyze the traffic exactly at the moment the connection is lost, chances are a firewall is cutting the conection.

In any case trying to debug these scenarios without dual side logging is a 50% russian rulette situation.

If you want to discard scenarios try to vary the amount of data being transfered, the parameters of the connection (using other constructor methods) and see if the timeout is consistent in time, if the timeout is depending on the amount of traffic that is usually a clue that you trigger some threshold in an intermediary device like a firewall.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=36707&siteId=1