Search in sources :

Example 6 with ARQException

use of org.apache.jena.sparql.ARQException 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;
}
Also used : Context(org.apache.jena.sparql.util.Context) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) HttpContext(org.apache.http.protocol.HttpContext) ARQException(org.apache.jena.sparql.ARQException) HttpClientContext(org.apache.http.client.protocol.HttpClientContext)

Example 7 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class TSVInput method fromTSV.

/**
	 * Reads SPARQL Results from TSV format into a {@link ResultSet} instance
	 * @param in Input Stream
	 */
public static ResultSet fromTSV(InputStream in) {
    BufferedReader reader = IO.asBufferedUTF8(in);
    List<Var> vars = new ArrayList<>();
    List<String> varNames = new ArrayList<>();
    String str = null;
    try {
        // Here we try to parse only the Header Row
        str = reader.readLine();
        if (str == null)
            throw new ARQException("TSV Results malformed, input is empty (no header row)");
        if (!str.isEmpty()) {
            String[] tokens = pattern.split(str, -1);
            for (String token : tokens) {
                Node v;
                try {
                    v = NodeFactoryExtra.parseNode(token);
                    if (v == null || !v.isVariable())
                        throw new ResultSetException("TSV Results malformed, not a variable: " + token);
                } catch (RiotException ex) {
                    throw new ResultSetException("TSV Results malformed, variable names must begin with a ? in the header: " + token);
                }
                Var var = Var.alloc(v);
                vars.add(var);
                varNames.add(var.getName());
            }
        }
    } catch (IOException ex) {
        throw new ARQException(ex);
    }
    //This will parse actual result rows as needed thus minimising memory usage
    return new ResultSetStream(varNames, null, new TSVInputIterator(reader, vars));
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream) RiotException(org.apache.jena.riot.RiotException) ARQException(org.apache.jena.sparql.ARQException) BufferedReader(java.io.BufferedReader)

Example 8 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class TSVOutput method format.

@Override
public void format(OutputStream out, boolean booleanResult) {
    try {
        out.write(headerBytes);
        if (booleanResult)
            out.write(yesBytes);
        else
            out.write(noBytes);
        out.write(NLBytes);
    } catch (IOException ex) {
        throw new ARQException(ex);
    }
}
Also used : ARQException(org.apache.jena.sparql.ARQException) IOException(java.io.IOException)

Example 9 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class TestSSE_Basic method parseBad.

private void parseBad(String str) {
    try {
        Item item = SSE.parse(str);
        //System.out.println(str+" => "+item) ;
        fail("Did not get a parse failure");
    } catch (ARQException ex) {
    }
}
Also used : Item(org.apache.jena.sparql.sse.Item) ARQException(org.apache.jena.sparql.ARQException)

Example 10 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class TestSSE_Basic method parseBadNode.

private void parseBadNode(String str) {
    try {
        // Not NodeFactory.parseNode which does not have all the features (e.g. "_" and "?") 
        Node node = parseNode(str);
        //System.out.println(str+" => "+item) ;
        fail("Did not get a parse failure");
    }//catch (RiotException ex) {}
     catch (ARQException ex) {
    }
}
Also used : ARQException(org.apache.jena.sparql.ARQException) Node(org.apache.jena.graph.Node)

Aggregations

ARQException (org.apache.jena.sparql.ARQException)48 IOException (java.io.IOException)11 Var (org.apache.jena.sparql.core.Var)7 ArrayList (java.util.ArrayList)5 Lang (org.apache.jena.riot.Lang)5 BufferedReader (java.io.BufferedReader)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 Node (org.apache.jena.graph.Node)4 Syntax (org.apache.jena.query.Syntax)4 RDFNode (org.apache.jena.rdf.model.RDFNode)4 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 Triple (org.apache.jena.graph.Triple)2 Query (org.apache.jena.query.Query)2 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 RiotException (org.apache.jena.riot.RiotException)2 HttpParams (org.apache.jena.sparql.engine.http.HttpParams)2 Item (org.apache.jena.sparql.sse.Item)2 UpdateRequest (org.apache.jena.update.UpdateRequest)2 BufferedWriter (java.io.BufferedWriter)1