use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestContext method testCxt9.
@Test(expected = ARQException.class)
public void testCxt9() {
Context cxt = new Context();
assertEquals(-1L, cxt.getLong(p1, -1L));
cxt.set(p1, 1L);
// Bad. Long for Integer.
cxt.getInt(p1, -2);
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestContext method testCxt8.
@Test
public void testCxt8() {
Context cxt = new Context();
assertEquals(-1L, cxt.getLong(p1, -1L));
cxt.set(p1, 1L);
long x = cxt.getLong(p1, -2L);
assertEquals(1L, x);
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class QueryEngineHTTP 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, QueryEngineHTTP engine) {
if (engine.context == null)
return;
@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 behavioral options
engine.setAllowCompression(serviceContext.isTrueOrUndef(Service.queryCompression));
applyServiceTimeouts(engine, serviceContext);
// Apply context-supplied client settings
HttpClient client = serviceContext.get(Service.queryClient);
if (client != null) {
if (log.isDebugEnabled())
log.debug("Using context-supplied HTTP client for endpoint URI {}", serviceURI);
engine.setClient(client);
}
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class QueryEngineHTTP method makeHttpQuery.
private HttpQuery makeHttpQuery() {
if (closed)
throw new ARQException("HTTP execution already closed");
HttpQuery httpQuery = new HttpQuery(service);
httpQuery.merge(getServiceParams(service, context));
httpQuery.addParam(HttpParams.pQuery, queryString);
for (String dft : defaultGraphURIs) {
httpQuery.addParam(HttpParams.pDefaultGraph, dft);
}
for (String name : namedGraphURIs) {
httpQuery.addParam(HttpParams.pNamedGraph, name);
}
if (params != null)
httpQuery.merge(params);
httpQuery.setAllowCompression(allowCompression);
// check for service context overrides
if (context.isDefined(Service.serviceContext)) {
Map<String, Context> servicesContext = context.get(Service.serviceContext);
if (servicesContext.containsKey(service)) {
Context serviceContext = servicesContext.get(service);
if (serviceContext.isDefined(Service.queryClient))
client = serviceContext.get(Service.queryClient);
}
}
httpQuery.setClient(client);
HttpClientContext hcc = (httpContext == null) ? null : HttpClientContext.adapt(httpContext);
httpQuery.setContext(hcc);
// Apply timeouts
if (connectTimeout > 0)
httpQuery.setConnectTimeout((int) connectTimeoutUnit.toMillis(connectTimeout));
if (readTimeout > 0)
httpQuery.setReadTimeout((int) readTimeoutUnit.toMillis(readTimeout));
return httpQuery;
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class Service method configureQuery.
/**
* Create and configure the HttpQuery object.
*
* The parentContext is not modified but is used to create a new context
* copy.
*
* @param uri
* The uri of the endpoint
* @param parentContext
* The initial context.
* @param Query
* the Query to execute.
* @return An HttpQuery configured as per the context.
*/
private static HttpQuery configureQuery(String uri, Context parentContext, Query query) {
HttpQuery httpQuery = new HttpQuery(uri);
Context context = new Context(parentContext);
// add the context settings from the service context
@SuppressWarnings("unchecked") Map<String, Context> serviceContextMap = (Map<String, Context>) context.get(serviceContext);
if (serviceContextMap != null) {
Context serviceContext = serviceContextMap.get(uri);
if (serviceContext != null)
context.putAll(serviceContext);
}
// configure the query object.
httpQuery.merge(QueryEngineHTTP.getServiceParams(uri, context));
httpQuery.addParam(HttpParams.pQuery, query.toString());
httpQuery.setAllowCompression(context.isTrueOrUndef(queryCompression));
HttpClient client = context.get(queryClient);
if (client != null)
httpQuery.setClient(client);
setAnyTimeouts(httpQuery, context);
return httpQuery;
}
Aggregations