public void callForHttpResultEvents()

in aliyun-sdk-opensearch/src/main/java/com/aliyun/opensearch/OpenSearchClient.java [202:237]


    public void callForHttpResultEvents(String path, Map<String, String> params, String method,
                                        OpenSearchResponseConsumer<ServerSentEvent<HttpResult>> eventConsumer) throws OpenSearchClientException {
        HttpResponse httpResponse = authAndCallForHttpResponse(path, params, method);

        try {
            InputStream responseBodyStream = httpResponse.getEntity()
                .getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(responseBodyStream, ENCODE_UTF8));
            StringLineConsumer stringLineConsumer = new StringLineConsumer(e -> {
                HttpResult httpResult = new HttpResult(httpResponse.getStatusLine().getStatusCode(),
                    httpResponse.getStatusLine().getReasonPhrase(), e.data(), null, null,
                    Arrays.asList(httpResponse.getAllHeaders()));
                eventConsumer.accept(ServerSentEvent.builder(httpResult)
                    .id(e.id())
                    .comment(e.comment())
                    .event(e.event())
                    .retry(e.retry())
                    .build()
                );
            });
            String line;
            while ((line = br.readLine()) != null) {
                stringLineConsumer.accept(line);
            }
            // Trigger potential last event
            stringLineConsumer.accept("");

            br.close();

            // 请求成功
            getHttpClientManager().getClientTracer().success(httpResponse, "");
        } catch (Throwable e) {
            log.debug(String.format("failed to request [%s]", path), e);
            throw new OpenSearchClientException(e);
        }
    }