Search in sources :

Example 1 with RegistryRequestModifier

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);
    }
}
Also used : DatasetGraphFactory(org.apache.jena.sparql.core.DatasetGraphFactory) RDFLinkHTTP(org.apache.jena.rdflink.RDFLinkHTTP) BeforeClass(org.junit.BeforeClass) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) RDFLinkFactory(org.apache.jena.rdflink.RDFLinkFactory) UpdateExecHTTP(org.apache.jena.sparql.exec.http.UpdateExecHTTP) RDFLink(org.apache.jena.rdflink.RDFLink) DSP(org.apache.jena.sparql.exec.http.DSP) Graph(org.apache.jena.graph.Graph) HttpNames(org.apache.jena.riot.web.HttpNames) QueryExecHTTP(org.apache.jena.sparql.exec.http.QueryExecHTTP) HttpTest.expect401(org.apache.jena.fuseki.test.HttpTest.expect401) EnvTest(org.apache.jena.test.conn.EnvTest) Before(org.junit.Before) AfterClass(org.junit.AfterClass) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Triple(org.apache.jena.graph.Triple) Test(org.junit.Test) GSP(org.apache.jena.sparql.exec.http.GSP) SSE(org.apache.jena.sparql.sse.SSE) ARQ(org.apache.jena.query.ARQ) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) QueryExec(org.apache.jena.sparql.exec.QueryExec) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) QueryExec(org.apache.jena.sparql.exec.QueryExec) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 2 with RegistryRequestModifier

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);
    }
}
Also used : RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier)

Aggregations

HttpRequestModifier (org.apache.jena.http.sys.HttpRequestModifier)2 RegistryRequestModifier (org.apache.jena.http.sys.RegistryRequestModifier)2 HttpTest.expect401 (org.apache.jena.fuseki.test.HttpTest.expect401)1 Graph (org.apache.jena.graph.Graph)1 Triple (org.apache.jena.graph.Triple)1 ARQ (org.apache.jena.query.ARQ)1 RDFLink (org.apache.jena.rdflink.RDFLink)1 RDFLinkFactory (org.apache.jena.rdflink.RDFLinkFactory)1 RDFLinkHTTP (org.apache.jena.rdflink.RDFLinkHTTP)1 HttpNames (org.apache.jena.riot.web.HttpNames)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 DatasetGraphFactory (org.apache.jena.sparql.core.DatasetGraphFactory)1 QueryExec (org.apache.jena.sparql.exec.QueryExec)1 DSP (org.apache.jena.sparql.exec.http.DSP)1 GSP (org.apache.jena.sparql.exec.http.GSP)1 QueryExecHTTP (org.apache.jena.sparql.exec.http.QueryExecHTTP)1 UpdateExecHTTP (org.apache.jena.sparql.exec.http.UpdateExecHTTP)1 GraphFactory (org.apache.jena.sparql.graph.GraphFactory)1 SSE (org.apache.jena.sparql.sse.SSE)1 EnvTest (org.apache.jena.test.conn.EnvTest)1