@Override protected void doGet(HttpAction action) { // Assume success - do the set up before grabbing the lock. // Sets content type. MediaType mediaType = ActionLib.contentNegotationRDF(action); ServletOutputStream output; try { output = action.response.getOutputStream(); } catch (IOException ex) { ServletOps.errorOccurred(ex); output = null; } TypedOutputStream out = new TypedOutputStream(output, mediaType); Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType()); if (action.verbose) action.log.info( format( "[%d] Get: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName())); action.beginRead(); setCommonHeaders(action.response); try { Target target = determineTarget(action); if (action.log.isDebugEnabled()) action.log.debug("GET->" + target); boolean exists = target.exists(); if (!exists) ServletOps.errorNotFound("No such graph: <" + target.name + ">"); // If we want to set the Content-Length, we need to buffer. // response.setContentLength(??) ; String ct = lang.getContentType().toHeaderString(); action.response.setContentType(ct); Graph g = target.graph(); // Special case RDF/XML to be the plain (faster, less readable) form RDFFormat fmt = (lang == Lang.RDFXML) ? RDFFormat.RDFXML_PLAIN : RDFWriterRegistry.defaultSerialization(lang); try { RDFDataMgr.write(out, g, fmt); } catch (JenaException ex) { // Some RDF/XML data is unwritable. All we can do is pretend it's a bad // request (inappropriate content type). // Good news - this happens before any output for RDF/XML-ABBREV. if (fmt.getLang().equals(Lang.RDFXML)) ServletOps.errorBadRequest("Failed to write output in RDF/XML: " + ex.getMessage()); else ServletOps.errorOccurred("Failed to write output: " + ex.getMessage(), ex); } ServletOps.success(action); } finally { action.endRead(); } }
private void execute(HttpAction action, InputStream input) { // OPTIONS if (action.request.getMethod().equals(HttpNames.METHOD_OPTIONS)) { // Share with update via SPARQL_Protocol. doOptions(action); return; } UsingList usingList = processProtocol(action.request); // If the dsg is transactional, then we can parse and execute the update in a streaming fashion. // If it isn't, we need to read the entire update request before performing any updates, because // we have to attempt to make the request atomic in the face of malformed queries UpdateRequest req = null; if (!action.isTransactional()) { try { // TODO implement a spill-to-disk version of this req = UpdateFactory.read(usingList, input, UpdateParseBase, Syntax.syntaxARQ); } catch (UpdateException ex) { ServletOps.errorBadRequest(ex.getMessage()); return; } catch (QueryParseException ex) { ServletOps.errorBadRequest(messageForQueryException(ex)); return; } } action.beginWrite(); try { if (req == null) UpdateAction.parseExecute( usingList, action.getActiveDSG(), input, UpdateParseBase, Syntax.syntaxARQ); else UpdateAction.execute(req, action.getActiveDSG()); action.commit(); } catch (UpdateException ex) { action.abort(); incCounter(action.getEndpoint().getCounters(), UpdateExecErrors); ServletOps.errorOccurred(ex.getMessage()); } catch (QueryParseException | QueryBuildException ex) { action.abort(); // Counter inc'ed further out. ServletOps.errorBadRequest(messageForQueryException(ex)); } catch (Throwable ex) { if (!(ex instanceof ActionErrorException)) { try { action.abort(); } catch (Exception ex2) { } ServletOps.errorOccurred(ex.getMessage(), ex); } } finally { action.endWrite(); } }
private void executeBody(HttpAction action) { InputStream input = null; try { input = action.request.getInputStream(); } catch (IOException ex) { ServletOps.errorOccurred(ex); } if (action.verbose) { // Verbose mode only .... capture request for logging (does not scale). String requestStr = null; try { requestStr = IO.readWholeFileAsUTF8(input); } catch (IOException ex) { IO.exception(ex); } action.log.info(format("[%d] Update = %s", action.id, ServletOps.formatForLog(requestStr))); input = new ByteArrayInputStream(requestStr.getBytes()); requestStr = null; } execute(action, input); ServletOps.successNoContent(action); }
protected void executeBody(HttpAction action) { String queryString = null; try { InputStream input = action.request.getInputStream(); queryString = IO.readWholeFileAsUTF8(input); } catch (IOException ex) { ServletOps.errorOccurred(ex); } execute(queryString, action); }
/** * Ship the results to the remote caller. * * @param action * @param result * @param qPrologue */ protected void sendResults(HttpAction action, SPARQLResult result, Prologue qPrologue) { if (result.isResultSet()) ResponseResultSet.doResponseResultSet(action, result.getResultSet(), qPrologue); else if (result.isDataset()) // CONSTRUCT is processed as a extended CONSTRUCT - result is a dataset. ResponseDataset.doResponseDataset(action, result.getDataset()); else if (result.isModel()) // DESCRIBE results are models ResponseDataset.doResponseModel(action, result.getModel()); else if (result.isBoolean()) ResponseResultSet.doResponseResultSet(action, result.getBooleanResult()); else ServletOps.errorOccurred("Unknown or invalid result type"); }