use of org.apache.jena.http.sys.RegistryRequestModifier in project jena by apache.
the class TestAuthRemote method auth_service_tuning_1_RegistryRequestModifier.
// Other ways of setting auth.
// Using HttpClient is preferred but the basic operations can use
// ServiceTuning or directly supply the headers.
// ServiceTuning
@Test
public void auth_service_tuning_1_RegistryRequestModifier() {
// using RegistryRequestModifier
HttpRequestModifier mods = (params, headers) -> headers.put(HttpNames.hAuthorization, HttpLib.basicAuth(user, password));
RegistryRequestModifier svcReg = new RegistryRequestModifier();
svcReg.add(env.datasetURL(), mods);
ARQ.getContext().put(ARQ.httpRegistryRequestModifer, svcReg);
try {
// Component level
UpdateExecHTTP.newBuilder().endpoint(env.datasetURL()).updateString("INSERT DATA { <x:s> <x:p> <x:o> }").build().execute();
try (QueryExec qExec = QueryExecHTTP.newBuilder().endpoint(env.datasetURL()).queryString("ASK{ <x:s> <x:p> <x:o> }").build()) {
boolean b = qExec.ask();
assertTrue(b);
}
} finally {
// clear up
ARQ.getContext().remove(ARQ.httpRegistryRequestModifer);
}
}
use of org.apache.jena.http.sys.RegistryRequestModifier 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);
}
}
Aggregations