private Response buildQueryResponse(final ContentType format, final String query, final QueryType queryType) throws Exception { StreamingOutput entity = new StreamingOutput() { @Override public void write(OutputStream output) throws IOException, WebApplicationException { try { sparqlService.query(QueryLanguage.SPARQL, query, output, format.getMime(), configurationService.getIntConfiguration("sparql.timeout", 60)); } catch (MarmottaException | MalformedQueryException ex) { throw new WebApplicationException(ex.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(ex)).build()); } catch (TimeoutException e) { throw new WebApplicationException(e.getCause(), Response.status(Response.Status.GATEWAY_TIMEOUT).entity(WebServiceUtil.jsonErrorResponse(e)).build()); } } }; final ResponseBuilder responseBuilder = Response.ok().entity(entity).header(CONTENT_TYPE, format.getMime()); final TupleQueryResultFormat fmt = QueryResultIO.getWriterFormatForMIMEType(format.getMime()); if (fmt != null && !"html".equals(fmt.getDefaultFileExtension())) { responseBuilder.header("Content-Disposition", String.format("attachment; filename=\"%s.%s\"", queryType.toString().toLowerCase(), fmt.getDefaultFileExtension())); } return responseBuilder.build(); }
private Response buildQueryResponse(final ContentType format, final String query, final QueryType queryType) throws Exception { StreamingOutput entity = new StreamingOutput() { @Override public void write(OutputStream output) throws IOException, WebApplicationException { try { sparqlService.query(QueryLanguage.SPARQL, query, output, format.getMime(), configurationService.getIntConfiguration("sparql.timeout", 60)); } catch (MarmottaException | MalformedQueryException ex) { throw new WebApplicationException(ex.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(ex)).build()); } catch (TimeoutException e) { throw new WebApplicationException(e.getCause(), Response.status(Response.Status.GATEWAY_TIMEOUT).entity(WebServiceUtil.jsonErrorResponse(e)).build()); } } }; final ResponseBuilder responseBuilder = Response.ok().entity(entity).header(CONTENT_TYPE, format.getMime()); final TupleQueryResultFormat fmt = QueryResultIO.getWriterFormatForMIMEType(format.getMime()); if (fmt != null && !"html".equals(fmt.getDefaultFileExtension())) { responseBuilder.header("Content-Disposition", String.format("attachment; filename=\"%s.%s\"", queryType.toString().toLowerCase(), fmt.getDefaultFileExtension())); } return responseBuilder.build(); }
mimeType = format.getDefaultMIMEType(); charset = format.getCharset(); fileExt = format.getDefaultFileExtension();
mimeType = format.getDefaultMIMEType(); charset = format.getCharset(); fileExt = format.getDefaultFileExtension();