Search in sources :

Example 1 with QueryExceptionHTTP

use of org.apache.jena.sparql.engine.http.QueryExceptionHTTP in project jena by apache.

the class TestService method testStringTimeout2.

@Test
public void testStringTimeout2() {
    BasicPattern basicPattern = new BasicPattern();
    basicPattern.add(Triple.ANY);
    Node serviceNode = NodeFactory.createURI(SERVICE);
    OpService opService = new OpService(serviceNode, new OpBGP(basicPattern), false);
    Context context = new Context();
    ARQ.setNormalMode(context);
    context.set(Service.queryTimeout, "10,10000");
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof ConnectTimeoutException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) OpService(org.apache.jena.sparql.algebra.op.OpService) BasicPattern(org.apache.jena.sparql.core.BasicPattern) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Example 2 with QueryExceptionHTTP

use of org.apache.jena.sparql.engine.http.QueryExceptionHTTP in project jena by apache.

the class TestService method testNumericTimeout.

@Test
public void testNumericTimeout() {
    BasicPattern basicPattern = new BasicPattern();
    basicPattern.add(Triple.ANY);
    Node serviceNode = NodeFactory.createURI(SERVICE);
    OpService opService = new OpService(serviceNode, new OpBGP(basicPattern), false);
    Context context = new Context();
    ARQ.setNormalMode(context);
    context.set(Service.queryTimeout, 10);
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof ConnectTimeoutException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) OpService(org.apache.jena.sparql.algebra.op.OpService) BasicPattern(org.apache.jena.sparql.core.BasicPattern) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Example 3 with QueryExceptionHTTP

use of org.apache.jena.sparql.engine.http.QueryExceptionHTTP in project jena by apache.

the class TestService method testStringTimeout.

@Test
public void testStringTimeout() {
    BasicPattern basicPattern = new BasicPattern();
    basicPattern.add(Triple.ANY);
    Node serviceNode = NodeFactory.createURI(SERVICE);
    OpService opService = new OpService(serviceNode, new OpBGP(basicPattern), false);
    Context context = new Context();
    ARQ.setNormalMode(context);
    context.set(Service.queryTimeout, "10");
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof ConnectTimeoutException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) OpService(org.apache.jena.sparql.algebra.op.OpService) BasicPattern(org.apache.jena.sparql.core.BasicPattern) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Example 4 with QueryExceptionHTTP

use of org.apache.jena.sparql.engine.http.QueryExceptionHTTP in project jena by apache.

the class rsparql method exec.

@Override
protected void exec() {
    Query query = modQuery.getQuery();
    try {
        String serviceURL = modRemote.getServiceURL();
        QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURL, query);
        if (modRemote.usePost())
            HttpQuery.urlLimit = 0;
        QueryExecUtils.executeQuery(query, qe, modResults.getResultsFormat());
    } catch (QueryExceptionHTTP ex) {
        throw new CmdException("HTTP Exeception", ex);
    } catch (Exception ex) {
        System.out.flush();
        ex.printStackTrace(System.err);
    }
}
Also used : HttpQuery(org.apache.jena.sparql.engine.http.HttpQuery) Query(org.apache.jena.query.Query) CmdException(jena.cmd.CmdException) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) QueryExecution(org.apache.jena.query.QueryExecution) CmdException(jena.cmd.CmdException)

Aggregations

QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)4 SocketException (java.net.SocketException)3 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)3 Node (org.apache.jena.graph.Node)3 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)3 OpService (org.apache.jena.sparql.algebra.op.OpService)3 BasicPattern (org.apache.jena.sparql.core.BasicPattern)3 Context (org.apache.jena.sparql.util.Context)3 Test (org.junit.Test)3 CmdException (jena.cmd.CmdException)1 Query (org.apache.jena.query.Query)1 QueryExecution (org.apache.jena.query.QueryExecution)1 HttpQuery (org.apache.jena.sparql.engine.http.HttpQuery)1