use of java.net.http.HttpClient in project jena by apache.
the class RemoteEndpointDriver method connect.
@Override
protected JenaConnection connect(Properties props, int compatibilityLevel) throws SQLException {
String queryEndpoint = props.getProperty(PARAM_QUERY_ENDPOINT);
String updateEndpoint = props.getProperty(PARAM_UPDATE_ENDPOINT);
// Validate at least one endpoint present
if (queryEndpoint == null && updateEndpoint == null)
throw new SQLException("At least one of the " + PARAM_QUERY_ENDPOINT + " or " + PARAM_UPDATE_ENDPOINT + " connection parameters must be specified to make a remote connection");
// Gather dataset related parameters
List<String> defaultGraphs = this.getValues(props, PARAM_DEFAULT_GRAPH_URI);
List<String> namedGraphs = this.getValues(props, PARAM_NAMED_GRAPH_URI);
List<String> usingGraphs = this.getValues(props, PARAM_USING_GRAPH_URI);
List<String> usingNamedGraphs = this.getValues(props, PARAM_USING_NAMED_GRAPH_URI);
// Authentication settings
HttpClient client = this.configureClient(props);
// Result Types
String selectResultsType = props.getProperty(PARAM_SELECT_RESULTS_TYPE, null);
String modelResultsType = props.getProperty(PARAM_MODEL_RESULTS_TYPE, null);
// Create connection
return openConnection(queryEndpoint, updateEndpoint, defaultGraphs, namedGraphs, usingGraphs, usingNamedGraphs, client, JenaConnection.DEFAULT_HOLDABILITY, compatibilityLevel, selectResultsType, modelResultsType);
}
use of java.net.http.HttpClient in project jena by apache.
the class ExecHTTPBuilder method build.
public final X build() {
Objects.requireNonNull(serviceURL, "No service URL");
if (queryString == null && query == null)
throw new QueryException("No query for QueryExecHTTP");
HttpClient hClient = HttpEnv.getHttpClient(serviceURL, httpClient);
Query queryActual = query;
String queryStringActual = queryString;
if (substitutionMap != null && !substitutionMap.isEmpty()) {
if (query == null)
throw new QueryException("Substitution only supported if a Query object was provided");
queryActual = QueryTransformOps.transform(query, substitutionMap);
queryStringActual = queryActual.toString();
}
Context cxt = contextAcc.context();
return buildX(hClient, queryActual, queryStringActual, cxt);
}
use of java.net.http.HttpClient in project jena by apache.
the class ExecUpdateHTTPBuilder method build.
public X build() {
Objects.requireNonNull(serviceURL, "No service URL");
if (updateOperations == null && updateString == null)
throw new QueryException("No update for UpdateExecutionHTTP");
if (updateOperations != null && updateString != null)
throw new InternalErrorException("UpdateRequest and update string");
HttpClient hClient = HttpEnv.getHttpClient(serviceURL, httpClient);
UpdateRequest updateActual = updateOperations;
if (substitutionMap != null && !substitutionMap.isEmpty()) {
if (updateActual == null)
throw new UpdateException("Substitution only supported if an UpdateRequest object was provided");
updateActual = UpdateTransformOps.transform(updateActual, substitutionMap);
}
Context cxt = (context != null) ? context : ARQ.getContext().copy();
return buildX(hClient, updateActual, cxt);
}
use of java.net.http.HttpClient in project jena by apache.
the class ExAuth02_QueryExecutionPW method exampleQueryAuthWithHttpClient.
// HttpClient
public static void exampleQueryAuthWithHttpClient() {
System.out.println();
System.out.println("HttpClient + QueryExecutionHTTP");
Authenticator authenticator = AuthLib.authenticator("u", "p");
HttpClient httpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).authenticator(authenticator).build();
try (QueryExecution qexec = QueryExecutionHTTP.service(dataURL).httpClient(httpClient).endpoint(dataURL).queryString("ASK{}").build()) {
qexec.execAsk();
}
}
use of java.net.http.HttpClient in project jena by apache.
the class ExAuth04_ServicePW method exampleServiceByHttpClient.
private static void exampleServiceByHttpClient() {
System.out.println();
System.out.println("Custom HttpClient + SERVICE call");
Authenticator authenticator = AuthLib.authenticator("u", "p");
HttpClient httpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).authenticator(authenticator).build();
Context cxt = ContextAccumulator.newBuilder().set(ARQ.httpQueryClient, httpClient).context();
Query query = QueryFactory.create("SELECT * { SERVICE <" + dataURL + "> { ?s ?p ?o } }");
Dataset emptyLocal = DatasetFactory.empty();
try (QueryExecution qExec = QueryExecution.create().query(query).dataset(emptyLocal).context(cxt).build()) {
System.out.println("Call using SERVICE...");
ResultSet rs = qExec.execSelect();
ResultSetFormatter.out(rs);
}
}
Aggregations