I extended QueryEngineHTTP to achieve what I had described: https://raw.github.com/Graphity/graphity-ldp/rf-input-mode/src/main/java/org/graphity/ldp/query/QueryEngineHTTP.java
I think endpoint (authentication) config is useful in a broader scope than SERVICE only. Martynas On Tue, Feb 26, 2013 at 1:49 PM, Martynas Jusevičius <[email protected]> wrote: > Hey, > > I'm running SPARQL queries on endpoints with HTTP Basic > authentication, and am looking for a convenient way to manage and > configure the credentials. > > Currently I've implemented a simple registry that checks endpoint URIs > against a map and sets the credentials using > QueryEngineHTTP.setBasicAuthentication(). > > Recently however I came across query Context configuration: > http://jena.apache.org/documentation/query/service.html > > That seemed exactly what I needed, but there is a problem: it doesn't > seem to work with basic QueryEngineHTTP? Am I right to assume that > srv:serviceContext only works with explicit SERVICE endpoints? > > Any reason why the approaches cannot be unified and > QueryEngineHTTP.setBasicAuthentication() would use the Context? It is > executing the query against some service after all (even if it's not > explicit SERVICE). What class(es) would I need to extend to achieve > this? > > The code I tried on ARQ 2.9.2 (endpoint and credentials are bogus): > > Context sparqlContext = new Context(); > > sparqlContext.put(ARQConstants.allocSymbol("http://jena.hpl.hp.com/Service#", > "queryAuthUser"), "xxxxx"); > > sparqlContext.put(ARQConstants.allocSymbol("http://jena.hpl.hp.com/Service#", > "queryAuthPwd"), "yyyy"); > Map<String,Context> serviceContext = new HashMap<String,Context>(); > serviceContext.put("http://dydra.com/graphity/repository/sparql", > sparqlContext); > > ARQ.getContext().put(ARQConstants.allocSymbol("http://jena.hpl.hp.com/Service#", > "serviceContext"), serviceContext); > ... > QueryEngineHTTP request = > QueryExecutionFactory.createServiceRequest(endpointURI, query); > if (log.isDebugEnabled()) log.debug("SPARQL Context: {} ", > request.getContext()); > request.execConstruct(); > > I see the credentials in the debug output: > > symbol:http://jena.hpl.hp.com/Service#serviceContext = > {http://dydra.com/graphity/repository/sparql=symbol:http://jena.hpl.hp.com/Service#queryAuthPwd > = yyyy > symbol:http://jena.hpl.hp.com/Service#queryAuthUser = xxxxx} > > but the serviceContext doesn't seem to have effect since I'm getting > > 13:21:54,149 TRACE HttpQuery:242 - Exception in exec > HttpException: 401 Unauthorized > You need to sign in or sign up before continuing. > at > com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:431) > > where QueryEngineHTTP.setBasicAuthentication() used to work fine. Am I > doing it wrong? > > Help appreciated :) > > Martynas > graphity.org
