Service { public static QueryIterator exec(OpService op, Context context) { if ( context != null && context.isFalse(serviceAllowed) ) throw new QueryExecException("SERVICE execution disabled") ; if (!op.getService().isURI()) throw new QueryExecException("Service URI not bound: " + op.getService()); Op opRemote = Rename.reverseVarRename(op.getSubOp(), true); Map<Var, Var> varMapping = new HashMap<>(); Set<Var> originalVars = OpVars.visibleVars(op); Set<Var> remoteVars = OpVars.visibleVars(opRemote); boolean requiresRemapping = false; for (Var v : originalVars) { if (v.getName().contains("/")) { String origName = v.getName().substring(v.getName().lastIndexOf('/') + 1); Var remoteVar = Var.alloc(origName); if (remoteVars.contains(remoteVar)) { varMapping.put(remoteVar, v); requiresRemapping = true; } } else { if (remoteVars.contains(v)) varMapping.put(v, v); } } Query query; query = OpAsQuery.asQuery(opRemote); Explain.explain("HTTP", query, context); String uri = op.getService().getURI(); HttpQuery httpQuery = configureQuery(uri, context, query); QueryIterator qIter; try (InputStream in = httpQuery.exec()) { ResultSet rs = ResultSetFactory.fromXML(in); qIter = QueryIter.materialize(new QueryIteratorResultSet(rs)); } catch (IOException e) { throw new QueryExecException("Could not parse result set from XML", e); } if (requiresRemapping) { qIter = QueryIter.map(qIter, varMapping); } return qIter; }  static QueryIterator exec(OpService op, Context context); static final String base; static final Symbol queryCompression; static final Symbol queryClient; static final Symbol serviceContext; static final Symbol serviceAllowed; static final Symbol queryTimeout; }
@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 ) { } else { Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage())); } } }
@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 ) { } else { Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage())); } } }
@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 ) { } else { Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage())); } } }