use of org.apache.jena.http.sys.HttpRequestModifier in project jena by apache.
the class TestAuthRemote method auth_service_tuning_2_HttpRequestModifer.
@Test
public void auth_service_tuning_2_HttpRequestModifer() {
// As HttpRequestModifer
HttpRequestModifier mods = (params, headers) -> headers.put(HttpNames.hAuthorization, HttpLib.basicAuth(user, password));
ARQ.getContext().put(ARQ.httpRequestModifer, mods);
try {
try (RDFLink link = RDFLinkHTTP.newBuilder().destination(env.datasetURL()).build()) {
link.update("INSERT DATA { <x:s> <x:p> <x:z> }");
boolean b = link.queryAsk("ASK{ <x:s> <x:p> <x:z> }");
assertTrue(b);
}
} finally {
// clear up
ARQ.getContext().remove(ARQ.httpRequestModifer);
}
}
use of org.apache.jena.http.sys.HttpRequestModifier in project jena by apache.
the class TestService method service_query_modified_registry.
@Test
public void service_query_modified_registry() {
DatasetGraph dsg = env.dsg();
dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
String queryString = "SELECT * { SERVICE <" + SERVICE + "> { ?s ?p ?o }} ";
RDFLink link = RDFLinkFactory.connect(localDataset());
// RequestModifer that sets a flag to show it has been run.
AtomicInteger COUNTER = new AtomicInteger(0);
HttpRequestModifier testModifier = (Params params, Map<String, String> httpHeaders) -> {
COUNTER.incrementAndGet();
};
runWithModifier(SERVICE, testModifier, () -> {
// Connect to local, unused, permanently empty dataset
try (QueryExec qExec = QueryExec.dataset(localDataset()).query(queryString).build()) {
RowSet rs = qExec.select();
long x = Iter.count(rs);
assertEquals(1, x);
}
});
assertEquals("Modifier did not run", 1, COUNTER.get());
}
use of org.apache.jena.http.sys.HttpRequestModifier in project jena by apache.
the class TestService method service_query_modified_cxt.
@Test
public void service_query_modified_cxt() {
DatasetGraph dsg = env.dsg();
String queryString = "SELECT * { SERVICE <" + SERVICE + "> { BIND (123 AS ?X) } }";
// RequestModifer that sets a flag to show it has been run.
AtomicInteger COUNTER = new AtomicInteger(0);
HttpRequestModifier testModifier = (Params params, Map<String, String> httpHeaders) -> {
COUNTER.incrementAndGet();
};
DatasetGraph localdsg = localDataset();
localdsg.getContext().put(ARQ.httpRequestModifer, testModifier);
try (RDFLink link = RDFLinkFactory.connect(localdsg)) {
try (QueryExec qExec = link.query(queryString)) {
RowSet rs = qExec.select();
long x = Iter.count(rs);
assertEquals(1, x);
}
}
assertEquals("Modifier did not run", 1, COUNTER.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 TestService method service_query_extra_params_oldstyle_by_context_1.
// Uses a HttpRequestModifier to check the changes.
@Test
public void service_query_extra_params_oldstyle_by_context_1() {
Map<String, Map<String, List<String>>> testServiceParams = new HashMap<>();
Map<String, List<String>> settings = new HashMap<>();
settings.put("apikey", List.of("BristolCalling"));
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());
}
Aggregations