Search in sources :

Example 1 with OpService

use of org.apache.jena.sparql.algebra.op.OpService 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 OpService

use of org.apache.jena.sparql.algebra.op.OpService 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 OpService

use of org.apache.jena.sparql.algebra.op.OpService 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 OpService

use of org.apache.jena.sparql.algebra.op.OpService in project jena by apache.

the class QueryIterService method nextStage.

@Override
protected QueryIterator nextStage(Binding outerBinding) {
    boolean silent = opService.getSilent();
    ExecutionContext execCxt = getExecContext();
    Context cxt = execCxt.getContext();
    ServiceExecutorRegistry registry = ServiceExecutorRegistry.get(cxt);
    ServiceExecution svcExec = null;
    OpService substitutedOp = (OpService) QC.substitute(opService, outerBinding);
    try {
        // ---- Find handler
        if (registry != null) {
            for (ServiceExecutorFactory factory : registry.getFactories()) {
                // Internal consistency check
                if (factory == null) {
                    Log.warn(this, "SERVICE <" + opService.getService().toString() + ">: Null item in custom ServiceExecutionRegistry");
                    continue;
                }
                svcExec = factory.createExecutor(substitutedOp, opService, outerBinding, execCxt);
                if (svcExec != null)
                    break;
            }
        }
        // ---- Execute
        if (svcExec == null)
            throw new QueryExecException("No SERVICE handler");
        QueryIterator qIter = svcExec.exec();
        qIter = QueryIter.makeTracked(qIter, getExecContext());
        // There should be no variables in common because of the OpSubstitute.substitute
        return new QueryIterCommonParent(qIter, outerBinding, getExecContext());
    } catch (RuntimeException ex) {
        if (silent) {
            Log.warn(this, "SERVICE " + NodeFmtLib.strTTL(substitutedOp.getService()) + " : " + ex.getMessage());
            // Return the input
            return QueryIterSingleton.create(outerBinding, getExecContext());
        }
        throw ex;
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ServiceExecutorFactory(org.apache.jena.sparql.service.ServiceExecutorFactory) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ServiceExecution(org.apache.jena.sparql.service.ServiceExecution) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) QueryIterCommonParent(org.apache.jena.sparql.engine.iterator.QueryIterCommonParent) OpService(org.apache.jena.sparql.algebra.op.OpService) ServiceExecutorRegistry(org.apache.jena.sparql.service.ServiceExecutorRegistry) QueryExecException(org.apache.jena.query.QueryExecException)

Example 5 with OpService

use of org.apache.jena.sparql.algebra.op.OpService in project jena by apache.

the class TestServiceSetup 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.httpQueryTimeout, "10");
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof HttpConnectTimeoutException || thrown instanceof UnknownHostException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or HttpConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) UnknownHostException(java.net.UnknownHostException) 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) HttpConnectTimeoutException(java.net.http.HttpConnectTimeoutException) Test(org.junit.Test)

Aggregations

OpService (org.apache.jena.sparql.algebra.op.OpService)12 Context (org.apache.jena.sparql.util.Context)9 Test (org.junit.Test)8 Node (org.apache.jena.graph.Node)6 SocketException (java.net.SocketException)5 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)5 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)5 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)3 EnvTest (org.apache.jena.test.conn.EnvTest)3 UnknownHostException (java.net.UnknownHostException)2 HttpConnectTimeoutException (java.net.http.HttpConnectTimeoutException)2 Op (org.apache.jena.sparql.algebra.Op)2 Element (org.apache.jena.sparql.syntax.Element)2 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)2 ElementTriplesBlock (org.apache.jena.sparql.syntax.ElementTriplesBlock)2 QueryExecException (org.apache.jena.query.QueryExecException)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)1