use of org.apache.jena.http.sys.HttpRequestModifier in project jena by apache.
the class TestService method service_query_extra_params_oldstyle_by_context_2.
// Uses a HttpRequestModifier to check the changes.
@Test
public void service_query_extra_params_oldstyle_by_context_2() {
Map<String, Map<String, List<String>>> testServiceParams = new HashMap<>();
Map<String, List<String>> settings = new HashMap<>();
settings.put("apikey", List.of("BristolCallingToTheFarawayTowns"));
testServiceParams.put(SERVICE, settings);
DatasetGraph clientDGS = localDataset();
clientDGS.getContext().set(ARQ.serviceParams, testServiceParams);
AtomicBoolean seen = new AtomicBoolean(false);
HttpRequestModifier inspector = (params, header) -> {
seen.set(params.containsParam("apikey"));
};
logOnlyErrors(Fuseki.class, () -> {
runWithModifier(SERVICE, inspector, () -> {
String queryString = "ASK { SERVICE <" + SERVICE + "> { BIND(now() AS ?now) } }";
try (QueryExec qExec = QueryExec.dataset(clientDGS).query(queryString).build()) {
boolean b = qExec.ask();
assertTrue(b);
}
});
});
assertTrue(seen.get());
}
use of org.apache.jena.http.sys.HttpRequestModifier in project jena by apache.
the class HttpLib method modifyByService.
/**
* Allow setting additional/optional query parameters on a per remote service (including for SERVICE).
* <ul>
* <li>ARQ.httpRequestModifer - the specific modifier</li>
* <li>ARQ.httpRegistryRequestModifer - the registry, keyed by service URL.</li>
* </ul>
*/
/*package*/
public static void modifyByService(String serviceURI, Context context, Params params, Map<String, String> httpHeaders) {
HttpRequestModifier modifier = context.get(ARQ.httpRequestModifer);
if (modifier != null) {
modifier.modify(params, httpHeaders);
return;
}
RegistryRequestModifier modifierRegistry = context.get(ARQ.httpRegistryRequestModifer);
if (modifierRegistry == null)
modifierRegistry = RegistryRequestModifier.get();
if (modifierRegistry != null) {
HttpRequestModifier mods = modifierRegistry.find(serviceURI);
if (mods != null)
mods.modify(params, httpHeaders);
}
}
use of org.apache.jena.http.sys.HttpRequestModifier in project jena by apache.
the class ExModification01 method exampleMod.
private static void exampleMod() {
AtomicLong counter = new AtomicLong(0);
HttpRequestModifier modifier = (params, headers) -> {
long x = counter.incrementAndGet();
headers.put("X-Tracker", "Call=" + x);
};
RegistryRequestModifier.get().addPrefix(serverURL, modifier);
// RegistryRequestModifier.get().add(dataURL, modifier);
// GSP : NO MODIFICATION no call to modifyByService
// GSP : calls HttpRDF
// Pass in request or at least request type.
/*
org.apache.jena.http.sys.RegistryRequestModifier.get()
auth.examples.ExModification01.exampleMod()
org.apache.jena.http.HttpLib.modifyByService(String, Context, Params, Map<String, String>)
org.apache.jena.sparql.exec.http.UpdateExecHTTP.execute()
org.apache.jena.sparql.exec.http.QueryExecHTTP.query(String)
==> SERVICE via QueryExecHTTP
==> GSP ?
org.apache.jena.sparql.exec.http.TestService.runWithModifier(String, HttpRequestModifier, Runnable)
*/
GSP.service(dataURL).defaultGraph().GET();
try (RDFLink link = RDFLinkHTTP.service(dataURL).build()) {
boolean b = link.queryAsk("ASK{}");
}
}
Aggregations