java jersey client_java jersey客户端的HTTP流异常丢弃

对于我们的一个项目,我们使用java jersey客户机使用HTTP提要流

虽然客户端的Feed消耗很好,但是在10分钟之后,流会异常下降;即使流生成器已经启动并运行并生成流

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 chunkedInput = response.readEntity(new GenericType>() {

});

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();

}

}

如果流没有下降;线程必须在while循环中;一旦流关闭,线程就会出来并打印sysout语句

请帮我下决心;

在这里,对于服务器端的每个负载/块分离,它都是\r\n并且要使它与服务器的连接处于活动状态,请发送(在客户端,我必须忽略这一点)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值