use of org.apache.jena.shared.JenaException in project jena by apache.
the class REST_Quads_R method doGet.
@Override
protected void doGet(HttpAction action) {
MediaType mediaType = ActionLib.contentNegotationQuads(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 (lang == null)
lang = RDFLanguages.TRIG;
if (action.verbose)
action.log.info(format("[%d] Get: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName()));
if (!RDFLanguages.isQuads(lang))
ServletOps.errorBadRequest("Not a quads format: " + mediaType);
action.beginRead();
try {
DatasetGraph dsg = action.getActiveDSG();
action.response.setHeader("Content-type", lang.getContentType().toHeaderString());
// ActionLib.contentNegotationQuads above
// RDF/XML is not a choice but this code is general.
RDFFormat fmt = // Choose streaming.
(lang == Lang.RDFXML) ? RDFFormat.RDFXML_PLAIN : RDFWriterRegistry.defaultSerialization(lang);
try {
RDFDataMgr.write(out, dsg, fmt);
} catch (JenaException ex) {
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();
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class ResponseDataset method doResponseDataset.
public static void doResponseDataset(HttpAction action, Dataset dataset) {
HttpServletRequest request = action.request;
HttpServletResponse response = action.response;
// Header request type
String mimeType = null;
MediaType i = ConNeg.chooseContentType(request, DEF.constructOffer, DEF.acceptTurtle);
if (i != null)
mimeType = i.getContentType();
String outputField = ResponseOps.paramOutput(request, shortNamesModel);
if (outputField != null)
mimeType = outputField;
String writerMimeType = mimeType;
if (mimeType == null) {
Fuseki.actionLog.warn("Can't find MIME type for response");
String x = WebLib.getAccept(request);
String msg;
if (x == null)
msg = "No Accept: header";
else
msg = "Accept: " + x + " : Not understood";
ServletOps.error(HttpSC.NOT_ACCEPTABLE_406, msg);
}
String contentType = mimeType;
String charset = charsetUTF8;
String forceAccept = ResponseOps.paramForceAccept(request);
if (forceAccept != null) {
contentType = forceAccept;
charset = charsetUTF8;
}
Lang lang = RDFLanguages.contentTypeToLang(contentType);
if (lang == null)
ServletOps.errorBadRequest("Can't determine output content type: " + contentType);
try {
ResponseResultSet.setHttpResponse(action, contentType, charset);
response.setStatus(HttpSC.OK_200);
ServletOutputStream out = response.getOutputStream();
try {
if (RDFLanguages.isQuads(lang))
RDFDataMgr.write(out, dataset, lang);
else
RDFDataMgr.write(out, dataset.getDefaultModel(), lang);
out.flush();
} catch (JenaException ex) {
// request (inappropriate content type).
if (lang.equals(Lang.RDFXML))
ServletOps.errorBadRequest("Failed to write output in RDF/XML: " + ex.getMessage());
else
ServletOps.errorOccurred("Failed to write output: " + ex.getMessage(), ex);
}
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
action.log.info("Exception while writing the response model: " + ex.getMessage(), ex);
ServletOps.errorOccurred("Exception while writing the response model: " + ex.getMessage(), ex);
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class ParserARQUpdate method _parse.
private void _parse(UpdateSink sink, Reader r) {
ARQParser parser = null;
try {
parser = new ARQParser(r);
parser.setUpdateSink(sink);
parser.UpdateUnit();
} catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.arq.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.error(this, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class ParserSPARQL11 method perform.
// All throwable handling.
private static void perform(Query query, String string, Action action) {
Reader in = new StringReader(string);
SPARQLParser11 parser = new SPARQLParser11(in);
try {
query.setStrict(true);
parser.setQuery(query);
action.exec(parser);
} catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.sparql_11.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
System.err.println(err.getMessage());
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.warn(ParserSPARQL11.class, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class ParserSPARQL11Update method _parse.
private void _parse(UpdateSink sink, Reader r) {
SPARQLParser11 parser = null;
try {
parser = new SPARQLParser11(r);
parser.setUpdateSink(sink);
parser.UpdateUnit();
} catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.sparql_11.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (UpdateException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.error(this, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
Aggregations