if (log.isDebugEnabled()) log.debug("Using context-supplied HTTP client for endpoint URI {}", serviceURI); engine.setClient(client);
private QueryEngineHTTP(String serviceURI, Query query, String queryString, HttpClient client, HttpContext httpContext) { this.query = query; this.queryString = queryString; this.service = serviceURI; this.context = ARQ.getContext().copy(); // Apply service configuration if relevant applyServiceConfig(serviceURI, this); // Don't want to overwrite client config we may have picked up from // service context in the parent constructor if the specified // client is null if (client != null) setClient(client); if (httpContext != null) setHttpContext(httpContext); }
@Override public SPARQLExecutionResult call() { Map<String, Set<String>> resultSet = new HashMap<>(); markers.forEach(marker -> resultSet.put(marker, new HashSet<>())); Model unionModel = ModelFactory.createDefaultModel(); SPARQLServiceConverter converter = new SPARQLServiceConverter(schema); String sparqlQuery = converter.getSelectQuery(query, inputSubset, rootType); logger.info(sparqlQuery); CredentialsProvider credsProvider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(this.sparqlEndpointService.getUser(), this.sparqlEndpointService.getPassword()); credsProvider.setCredentials(AuthScope.ANY, credentials); HttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider) .build(); HttpOp.setDefaultHttpClient(httpclient); Query jenaQuery = QueryFactory.create(sparqlQuery); QueryEngineHTTP qEngine = QueryExecutionFactory.createServiceRequest(this.sparqlEndpointService.getUrl(), jenaQuery); qEngine.setClient(httpclient); ResultSet results = qEngine.execSelect(); results.forEachRemaining(solution -> { markers.stream().filter(solution::contains).forEach(marker -> resultSet.get(marker).add(solution.get(marker).asResource().getURI())); unionModel.add(this.sparqlEndpointService.getModelFromResults(query, solution, schema)); }); SPARQLExecutionResult sparqlExecutionResult = new SPARQLExecutionResult(resultSet, unionModel); logger.info(sparqlExecutionResult); return sparqlExecutionResult; }
@Override public SPARQLExecutionResult call() { Map<String, Set<String>> resultSet = new HashMap<>(); markers.forEach(marker -> resultSet.put(marker, new HashSet<>())); Model unionModel = ModelFactory.createDefaultModel(); SPARQLServiceConverter converter = new SPARQLServiceConverter(schema); String sparqlQuery = converter.getSelectQuery(query, inputSubset, rootType); logger.info(sparqlQuery); CredentialsProvider credsProvider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(this.sparqlEndpointService.getUser(), this.sparqlEndpointService.getPassword()); credsProvider.setCredentials(AuthScope.ANY, credentials); HttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider) .build(); HttpOp.setDefaultHttpClient(httpclient); Query jenaQuery = QueryFactory.create(sparqlQuery); QueryEngineHTTP qEngine = QueryExecutionFactory.createServiceRequest(this.sparqlEndpointService.getUrl(), jenaQuery); qEngine.setClient(httpclient); ResultSet results = qEngine.execSelect(); results.forEachRemaining(solution -> { markers.stream().filter(solution::contains).forEach(marker -> resultSet.get(marker).add(solution.get(marker).asResource().getURI())); unionModel.add(this.sparqlEndpointService.getModelFromResults(query, solution, schema)); }); SPARQLExecutionResult sparqlExecutionResult = new SPARQLExecutionResult(resultSet, unionModel); logger.info(sparqlExecutionResult); return sparqlExecutionResult; }
@Override protected QueryExecution createQueryExecution(Query q) throws SQLException { if (this.remoteConn.getQueryEndpoint() == null) throw new SQLException("This statement is backed by a write-only connection, read operations are not supported"); // Create basic execution QueryEngineHTTP exec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(this.remoteConn.getQueryEndpoint(), q); // Apply HTTP settings if (this.client != null) { exec.setClient(client); } // Apply default and named graphs if appropriate if (this.remoteConn.getDefaultGraphURIs() != null) { exec.setDefaultGraphURIs(this.remoteConn.getDefaultGraphURIs()); } if (this.remoteConn.getNamedGraphURIs() != null) { exec.setNamedGraphURIs(this.remoteConn.getNamedGraphURIs()); } // Set result types if (this.remoteConn.getSelectResultsType() != null) { exec.setSelectContentType(this.remoteConn.getSelectResultsType()); } if (this.remoteConn.getModelResultsType() != null) { exec.setModelContentType(this.remoteConn.getModelResultsType()); } // Return execution return exec; }
@Override protected QueryExecution createQueryExecution(Query q) throws SQLException { if (this.remoteConn.getQueryEndpoint() == null) throw new SQLException("This statement is backed by a write-only connection, read operations are not supported"); // Create basic execution QueryEngineHTTP exec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(this.remoteConn.getQueryEndpoint(), q); // Apply HTTP settings if (this.client != null) { exec.setClient(this.client); } // Apply default and named graphs if appropriate if (this.remoteConn.getDefaultGraphURIs() != null) { exec.setDefaultGraphURIs(this.remoteConn.getDefaultGraphURIs()); } if (this.remoteConn.getNamedGraphURIs() != null) { exec.setNamedGraphURIs(this.remoteConn.getNamedGraphURIs()); } // Set result types if (this.remoteConn.getSelectResultsType() != null) { exec.setSelectContentType(this.remoteConn.getSelectResultsType()); } if (this.remoteConn.getModelResultsType() != null) { exec.setModelContentType(this.remoteConn.getModelResultsType()); } // Return execution return exec; }