public JsonParser fetchResult()

in asterixdb-jdbc/asterix-jdbc-driver/src/main/java/org/apache/asterix/jdbc/ADBProtocol.java [312:358]


    public JsonParser fetchResult(QueryServiceResponse response, SubmitStatementOptions options) throws SQLException {
        if (response.handle == null) {
            throw getErrorReporter().errorInProtocol();
        }
        int p = response.handle.lastIndexOf("/");
        if (p < 0) {
            throw getErrorReporter().errorInProtocol(response.handle);
        }
        String handlePath = response.handle.substring(p);
        URI resultRequestURI;
        try {
            resultRequestURI = new URI(queryResultEndpoint + handlePath);
        } catch (URISyntaxException e) {
            throw getErrorReporter().errorInProtocol(handlePath);
        }
        HttpGet httpGet = new HttpGet(resultRequestURI);
        httpGet.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());

        CloseableHttpResponse httpResponse = null;
        InputStream httpContentStream = null;
        JsonParser parser = null;
        try {
            httpResponse = httpClient.execute(httpGet, httpClientContext);
            int httpStatus = httpResponse.getStatusLine().getStatusCode();
            if (httpStatus != HttpStatus.SC_OK) {
                throw getErrorReporter().errorNoResult();
            }
            HttpEntity entity = httpResponse.getEntity();
            httpContentStream = entity.getContent();
            parser = driverContext.getGenericObjectReader().getFactory()
                    .createParser(new InputStreamWithAttachedResource(httpContentStream, httpResponse));
            if (!advanceToArrayField(parser, RESULTS)) {
                throw getErrorReporter().errorInProtocol();
            }
            parser.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true);
            return parser;
        } catch (SQLException e) {
            closeQuietly(e, parser, httpContentStream, httpResponse);
            throw e;
        } catch (JsonProcessingException e) {
            closeQuietly(e, parser, httpContentStream, httpResponse);
            throw getErrorReporter().errorInProtocol(e);
        } catch (IOException e) {
            closeQuietly(e, parser, httpContentStream, httpResponse);
            throw getErrorReporter().errorInConnection(e);
        }
    }