Examples of QueryEngineHTTP


Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

  }

  @Override
  public ResultSet sparql(String sparql) {
    //we use QueryEngineHTTP to skip query validation as Virtuoso needs non-standardised extensions and will not pass ARQ validation
    QueryEngineHTTP qExec = new QueryEngineHTTP(sparqlEndpointUrl, sparql);
    if(defaultGraphUri!=null){
      qExec.setDefaultGraphURIs(Collections.singletonList(defaultGraphUri));
    }
    ResultSet res = qExec.execSelect();
    return res;
  }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

    {
        checkNotNull(service, "URL for service is null") ;
        //checkNotNull(defaultGraphURIs, "List of default graph URIs is null") ;
        //checkNotNull(namedGraphURIs, "List of named graph URIs is null") ;
        checkArg(query) ;
        QueryEngineHTTP qe = createServiceRequest(service, query) ;
        if ( defaultGraphURIs != null )
            qe.setDefaultGraphURIs(defaultGraphURIs) ;
        if ( namedGraphURIs != null )
            qe.setNamedGraphURIs(namedGraphURIs) ;
        return qe ;
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

    static public QueryExecution sparqlService(String service, Query query, String defaultGraph)
    {
        checkNotNull(service, "URL for service is null") ;
        //checkNotNull(defaultGraph, "IRI for default graph is null") ;
        checkArg(query) ;
        QueryEngineHTTP qe = createServiceRequest(service, query) ;
        qe.addDefaultGraph(defaultGraph) ;
        return qe ;
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

     * {@link QueryEngineHTTP},
     * allows various HTTP specific paramters to be set.
     */
    static public QueryEngineHTTP createServiceRequest(String service, Query query)
    {
        QueryEngineHTTP qe = new QueryEngineHTTP(service, query) ;
        return qe ;
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

    public QueryExecution sparqlService(String endpointURI, Query query, MultivaluedMap<String, String> params)
    {
  if (log.isDebugEnabled()) log.debug("Remote service {} Query: {} ", endpointURI, query);
  if (query == null) throw new IllegalArgumentException("Query must be not null");

  QueryEngineHTTP request = new QueryEngineHTTP(endpointURI, query, getHttpAuthenticator(endpointURI));
  if (params != null)
      for (Entry<String, List<String>> entry : params.entrySet())
    if (!entry.getKey().equals("query")) // query param is handled separately
        for (String value : entry.getValue())
        {
      if (log.isTraceEnabled()) log.trace("Adding param to SPARQL request with name: {} and value: {}", entry.getKey(), value);
      request.addParam(entry.getKey(), value);
        }
 
  return request;
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

              + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
              + "ASK {[] rdf:type <" + possible + "> }";
        }
        try {
          Query query = Query.create(sparqlString);
          QueryEngineHTTP qExecution = QueryExecutionFactory.createServiceRequest(endpoint, query);
          if (qExecution.execAsk()) {
            certains.get(type).add(possible);
          }
        } catch (Exception e) {
          //fail silently, don't care!
        }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

  @SuppressWarnings("rawtypes")
  public static ResultSet query(String endpoint, String queryString, HashMap<String, String> args) throws SparqlException {
    ResultSet results;
    try {
      Query query = QueryFactory.create(queryString);
      QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint, query);
      Iterator iterator = args.entrySet().iterator();
      while (iterator.hasNext()) {
        Map.Entry entry = (Map.Entry) iterator.next();
        String key = (String) entry.getKey();
        String val = (String)entry.getValue();
        queryExecution.addParam(key, val);
      }
      results = queryExecution.execSelect();
    } catch (QueryParseException e) {
      throw new SparqlException(e.getMessage(), e);
    }
    return results;
  }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

            "PREFIX italy: <http://data.kasabi.com/dataset/italy/schema/>" +
            "SELECT ?region WHERE { " +
            "  ?region rdf:type italy:Region" +
            "}";
        Query query = QueryFactory.create(queryString);
        QueryEngineHTTP qexec = (QueryEngineHTTP)QueryExecutionFactory.createServiceRequest("http://api.kasabi.com/dataset/italy/apis/sparql", query);
        qexec.addParam("apikey", apikey);
        try {
            ResultSet results = qexec.execSelect();
            while ( results.hasNext() ) {
                QuerySolution soln = results.nextSolution();
                Resource region = soln.getResource("region");
                System.out.println(region.getURI());
            }
        } finally {
            qexec.close();
        }
  }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

   
    @Test
    public void query_with_auth_11() {
        Context ctx = ARQ.getContext();
        try {
            QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "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<String, Context>();
            Context authContext = new Context();
            authContext.put(Service.queryAuthUser, "allowed");
            authContext.put(Service.queryAuthPwd, "password");
            serviceContext.put(urlRoot, authContext);
            ctx.put(Service.serviceContext, serviceContext);

            qe.setAuthenticator(new ServiceAuthenticator());
            Assert.assertTrue(qe.execAsk());
        } finally {
            ctx.remove(Service.serviceContext);
        }
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP

   
    @Test
    public void query_with_auth_12() {
        ARQ.getContext().remove(Service.serviceContext);

        QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }");

        // Auth credentials for valid user with correct password
        // Use service authenticator with fallback credentials.
        qe.setAuthenticator(new ServiceAuthenticator("allowed", "password".toCharArray()));
        Assert.assertTrue(qe.execAsk());
     }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.