org.glassfish.jersey.server.ChunkedOutput을 사용하여 요청에 대한 청크 응답을 받았습니다. 브라우저를 통해 URL을 조회하면 별도의 청크로 출력되는 대신 모든 청크를 한 번에 가져옵니다. 하지만 테스트 클라이언트를 사용하여 리소스를 공격하면 별도의 청크로 출력됩니다.ChunkedOutput이 브라우저에서 즉시 응답을 반환합니다.
@GET
@Path("chunk")
public ChunkedOutput<String> getChunkedResponse(@Context HttpServletRequest request) {
final ChunkedOutput<String> output = new ChunkedOutput<String>(
String.class);
new Thread() {
public void run() {
try {
Thread.sleep(2000);
String chunk;
String arr[] = { "America\r\n", "London\r\n", "Delhi\r\n", "null" };
int i = 0;
while (!(chunk = arr[i]).equals("null")) {
output.write(chunk);
i++;
Thread.sleep(2000);
}
} catch (IOException e) {
logger.error("IOException : ", e);
} catch (InterruptedException e) {
logger.error("InterruptedException : ", e);
e.printStackTrace();
} finally {
try {
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("IOException IN finally : ", e);
}
}
}
}.start();
// the output will be probably returned even before
// a first chunk is written by the new thread
return output;
}
테스트 클라이언트 방법은 다음과 같다 :
private static void testChunkedResponse(WebTarget target){
final Response response = target.path("restRes").path("chunk")
.request().get();
final ChunkedInput<String> chunkedInput =
response.readEntity(new GenericType<ChunkedInput<String>>() {});
String chunk;
while ((chunk = chunkedInput.read()) != null) {
logger.info("Next chunk received: " + chunk);
}
}
사람은 나를 이해하는 데 도움 주실 래요 사용
서버 : 다음과 같이 글래스 피시 4.0 저지 버전은 2.13
자원의 방법은 왜 응답이 브라우저에서 크랭크되지 않고 무엇이 완료 될 수 있습니까?