use of org.apache.jena.sparql.util.Context in project jena by apache.
the class ActionBase method doCommon.
/**
* Common framework for handling HTTP requests.
* @param request
* @param response
*/
protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
try {
long id = allocRequestId(request, response);
// Lifecycle
HttpAction action = allocHttpAction(id, request, response);
printRequest(action);
action.setStartTime();
// The response may be changed to a HttpServletResponseTracker
response = action.response;
initResponse(request, response);
Context cxt = ARQ.getContext();
try {
execCommonWorker(action);
} catch (QueryCancelledException ex) {
// To put in the action timeout, need (1) global, (2) dataset and (3) protocol settings.
// See
// global -- cxt.get(ARQ.queryTimeout)
// dataset -- dataset.getContect(ARQ.queryTimeout)
// protocol -- SPARQL_Query.setAnyTimeouts
String message = String.format("Query timed out");
// Possibility :: response.setHeader("Retry-after", "600") ; // 5 minutes
ServletOps.responseSendError(response, HttpSC.SERVICE_UNAVAILABLE_503, message);
} catch (ActionErrorException ex) {
if (ex.getCause() != null)
ex.getCause().printStackTrace(System.err);
// Log message done by printResponse in a moment.
if (ex.getMessage() != null)
ServletOps.responseSendError(response, ex.getRC(), ex.getMessage());
else
ServletOps.responseSendError(response, ex.getRC());
} catch (RuntimeIOException ex) {
log.warn(format("[%d] Runtime IO Exception (client left?) RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex);
ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
} catch (Throwable ex) {
// This should not happen.
//ex.printStackTrace(System.err) ;
log.warn(format("[%d] RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex);
ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
}
action.setFinishTime();
printResponse(action);
archiveHttpAction(action);
} catch (Throwable th) {
log.error("Internal error", th);
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestJsonLDReader method overrideAtContextByURITest.
/** Not really useful, but one can replace the @context by a URI: in this case, this URI is used when expanding the json
* (letting JSON-LD java API taking care of downloading the context. */
// well, as of this writing, it doesn't work, as we get a "loading remote context failed"
// But it is about the replacing URI, not the replaced one, showing that the mechanism does work
@Test
public final void overrideAtContextByURITest() throws JsonGenerationException, IOException {
// some jsonld using a (fake) pseudo.schema.org's URI as "@context"
String jsonld = "{\"@id\":\"_:b0\",\"@type\":\"Person\",\"name\":\"John Doe\",\"@context\":\"http://pseudo.schema.org/\"}";
// a subset of schema.org that can be used as @context for jsonld
String jsonldContext = "\"http://schema.org\"";
// pass the jsonldContext to the read using a jena Context
Context jenaCtx = new Context();
Object jsonldContextAsObject = JsonUtils.fromInputStream(new ByteArrayInputStream(jsonldContext.getBytes(StandardCharsets.UTF_8)));
jenaCtx.set(RIOT.JSONLD_CONTEXT, jsonldContextAsObject);
try {
// read the jsonld, replacing its "@context"
Dataset ds = jsonld2dataset(jsonld, jenaCtx);
// check ds is correct
assertJohnDoeIsOK(ds.getDefaultModel());
} catch (RiotException e) {
// cf. org.apache.jena.riot.RiotException: loading remote context failed: http://schema.org/
// There's a line printed anyway
// e.printStackTrace();
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestAuth method query_with_auth_11.
@Test
public void query_with_auth_11() {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password and scoped
// to base URI of the actual service URL
// Provided via Service Context and its associated authenticator
Map<String, Context> serviceContext = new HashMap<>();
Context authContext = new Context();
HttpClient client = withBasicAuth(ANY, "allowed", "password");
authContext.put(Service.queryClient, client);
serviceContext.put(authServiceQuery, authContext);
qe.getContext().put(Service.serviceContext, serviceContext);
Assert.assertTrue(qe.execAsk());
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestAuth method query_with_auth_10.
@Test
public void query_with_auth_10() {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password and scoped
// to correct URI
// Provided via Service Context and its associated authenticator
Map<String, Context> serviceContext = new HashMap<>();
Context authContext = new Context();
HttpClient client = withBasicAuth(ANY, "allowed", "password");
authContext.put(Service.queryClient, client);
serviceContext.put(authServiceQuery, authContext);
qe.getContext().put(Service.serviceContext, serviceContext);
Assert.assertTrue(qe.execAsk());
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class ProcEval method build.
// ----
public static Procedure build(Node procId, PropFuncArg subjArg, PropFuncArg objArg, ExecutionContext execCxt) {
Context context = execCxt.getContext();
PropertyFunctionRegistry reg = PropertyFunctionRegistry.chooseRegistry(context);
PropertyFunctionFactory f = reg.get(procId.getURI());
PropertyFunction pf = f.create(procId.getURI());
pf.build(subjArg, procId, objArg, execCxt);
//Make wrapper
return new ProcedurePF(pf, subjArg, procId, objArg);
}
Aggregations