/** * Test specifically for JSONP callback support. */ protected void doTupleJSONPCallback(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); // only do this test if the callback is enabled if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.JSONP_CALLBACK)) { String callback = "nextfunctionname" + Math.abs(new Random().nextInt()); writer.getWriterConfig().set(BasicQueryWriterSettings.JSONP_CALLBACK, callback); QueryResults.report(input, writer); String result = out.toString("UTF-8"); // System.out.println("output: " + result); assertTrue(result.startsWith(callback + "(")); assertTrue(result.endsWith(");")); // Strip off the callback function and verify that it contains a valid // JSON object containing the correct results result = result.substring(callback.length() + 1, result.length() - 2); ByteArrayInputStream in = new ByteArrayInputStream(result.getBytes("UTF-8")); TupleQueryResult output = QueryResultIO.parseTuple(in, format); assertQueryResultsEqual(expected, output); } }
TupleQueryResult tupleQueryResult = (TupleQueryResult)model.get(QUERY_RESULT_KEY); if (qrWriter.getSupportedSettings().contains(BasicQueryWriterSettings.JSONP_CALLBACK)) { String parameter = request.getParameter(DEFAULT_JSONP_CALLBACK_PARAMETER);
private TupleQueryResultWriter getTupleResultWriter(String format, OutputStream os) { TupleQueryResultFormat resultFormat; if(format == null) { resultFormat = TupleQueryResultFormat.SPARQL; } else { resultFormat = QueryResultIO.getWriterFormatForMIMEType(format); if(resultFormat == null) { throw new InvalidArgumentException("could not produce format "+format); } } TupleQueryResultWriter writer = QueryResultIO.createWriter(resultFormat, os); if(writer.getSupportedSettings().contains(SPARQLHTMLSettings.TEMPLATING_SERVICE)) { writer.getWriterConfig().set(SPARQLHTMLSettings.TEMPLATING_SERVICE, templatingService); } return writer; }
private TupleQueryResultWriter getTupleResultWriter(String format, OutputStream os) { TupleQueryResultFormat resultFormat; if(format == null) { resultFormat = TupleQueryResultFormat.SPARQL; } else { resultFormat = QueryResultIO.getWriterFormatForMIMEType(format); if(resultFormat == null) { throw new InvalidArgumentException("could not produce format "+format); } } TupleQueryResultWriter writer = QueryResultIO.createWriter(resultFormat, os); if(writer.getSupportedSettings().contains(SPARQLHTMLSettings.TEMPLATING_SERVICE)) { writer.getWriterConfig().set(SPARQLHTMLSettings.TEMPLATING_SERVICE, templatingService); } return writer; }
if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.ADD_SESAME_QNAME)) { if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.ADD_SESAME_QNAME)) { assertTrue(result.contains("test:bindingA")); assertFalse(result.contains("other:bindingB"));