use of org.apache.jena.sparql.util.Context in project jena by apache.
the class SPARQL_ServletBase method doCommon.
// Common framework for handling HTTP requests
/**
* Handles GET and POST requests.
* @param request HTTP request
* @param response HTTP response
*/
protected void doCommon(HttpServletRequest request, HttpServletResponse response) //throws ServletException, IOException
{
try {
long id = allocRequestId(request, response);
// Lifecycle
HttpAction action = allocHttpAction(id, request, response);
// then add to doCommonWorker
// work with HttpServletResponseTracker
printRequest(action);
action.setStartTime();
response = action.response;
initResponse(request, response);
Context cxt = ARQ.getContext();
try {
execCommonWorker(action);
} catch (QueryCancelledException ex) {
// Also need the per query info ...
String message = String.format("The query timed out (restricted to %s ms)", cxt.get(ARQ.queryTimeout));
// Possibility :: response.setHeader("Retry-after", "600") ; // 5 minutes
responseSendError(response, HttpSC.SERVICE_UNAVAILABLE_503, message);
} catch (ActionErrorException ex) {
if (ex.exception != null)
ex.exception.printStackTrace(System.err);
// Log message done by printResponse in a moment.
if (ex.message != null)
responseSendError(response, ex.rc, ex.message);
else
responseSendError(response, ex.rc);
} catch (RuntimeIOException ex) {
log.warn(format("[%d] Runtime IO Exception (client left?) RC = %d", id, HttpSC.INTERNAL_SERVER_ERROR_500));
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);
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 TupleTable method iterator.
public QueryIterator iterator() {
SDBRequest request = new SDBRequest(store, null);
String tableName = desc.getTableName();
SQLBridge b = store.getSQLBridgeFactory().create(request, sqlTable, vars);
b.build();
try {
String sqlStr = store.getSQLGenerator().generateSQL(request, b.getSqlNode());
//System.out.println(sqlStr) ;
ResultSetJDBC tableData = store.getConnection().execQuery(sqlStr);
ExecutionContext execCxt = new ExecutionContext(new Context(), null, null, null);
return b.assembleResults(tableData, BindingRoot.create(), execCxt);
} catch (SQLException ex) {
throw new SDBExceptionSQL(ex);
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class UpdateProcessRemoteBase method applyServiceConfig.
/**
* <p>
* Helper method which applies configuration from the Context to the query
* engine if a service context exists for the given URI
* </p>
* <p>
* Based off proposed patch for JENA-405 but modified to apply all relevant
* configuration, this is in part also based off of the private
* {@code configureQuery()} method of the {@link Service} class though it
* omits parameter merging since that will be done automatically whenever
* the {@link QueryEngineHTTP} instance makes a query for remote submission.
* </p>
*
* @param serviceURI
* Service URI
*/
private static void applyServiceConfig(String serviceURI, UpdateProcessRemoteBase engine) {
@SuppressWarnings("unchecked") Map<String, Context> serviceContextMap = (Map<String, Context>) engine.context.get(Service.serviceContext);
if (serviceContextMap != null && serviceContextMap.containsKey(serviceURI)) {
Context serviceContext = serviceContextMap.get(serviceURI);
if (log.isDebugEnabled())
log.debug("Endpoint URI {} has SERVICE Context: {} ", serviceURI, serviceContext);
// Apply client settings
HttpClient client = serviceContext.get(Service.queryClient);
if (client != null) {
if (log.isDebugEnabled())
log.debug("Using context-supplied client for endpoint URI {}", serviceURI);
engine.setClient(client);
}
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestJsonLDReader method overrideAtContextTest.
/** Test using the jena Context mechanism to pass the jsonld "@context" */
@Test
public final void overrideAtContextTest() throws JsonGenerationException, IOException {
// some jsonld using schema.org's URI as "@context"
String jsonld = someSchemaDorOrgJsonld();
// a subset of schema.org that can be used as @context for jsonld
String jsonldContext = "{\"name\":{\"@id\":\"http://schema.org/name\"},\"Person\": {\"@id\": \"http://schema.org/Person\"}}";
// pass the jsonldContext to the read using a jena Context
Context jenaCtx = new Context();
Object jsonldContextAsMap = JsonUtils.fromInputStream(new ByteArrayInputStream(jsonldContext.getBytes(StandardCharsets.UTF_8)));
jenaCtx.set(RIOT.JSONLD_CONTEXT, jsonldContextAsMap);
// read the jsonld, replacing its "@context"
Dataset ds = jsonld2dataset(jsonld, jenaCtx);
// check ds is correct
assertJohnDoeIsOK(ds.getDefaultModel());
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestQueryIterSort method testCancelInterruptsExternalSortAfterStartingIteration.
@Test(expected = QueryCancelledException.class)
public void testCancelInterruptsExternalSortAfterStartingIteration() {
assertEquals(0, iterator.getReturnedElementCount());
Context context = new Context();
context.set(ARQ.spillToDiskThreshold, 10L);
ExecutionContext executionContext = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qIter = new QueryIterSort(iterator, comparator, executionContext);
try {
assertEquals(0, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
// throws a QueryCancelledException
qIter.hasNext();
} catch (QueryCancelledException e) {
// expected
assertEquals(26, iterator.getReturnedElementCount());
// This is zero because QueryIteratorBase will call close() before throwing the QueryCancelledException.
// It does this as a failsafe in case the user doesn't close the QueryIterator themselves.
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
throw e;
} finally {
qIter.close();
}
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
}
Aggregations