use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class SPARQL_Update method execute.
protected void execute(HttpAction action, InputStream input) {
UsingList usingList = processProtocol(action.getRequest());
// 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 updates.
UpdateRequest req = null;
if (!action.isTransactional()) {
try {
req = UpdateFactory.read(usingList, input, UpdateParseBase, Syntax.syntaxARQ);
} catch (UpdateException ex) {
ServletOps.errorBadRequest(ex.getMessage());
return;
} catch (QueryParseException ex) {
ServletOps.errorBadRequest(messageForException(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) {
ActionLib.consumeBody(action);
abortSilent(action);
incCounter(action.getEndpoint().getCounters(), UpdateExecErrors);
ServletOps.errorOccurred(ex.getMessage());
} catch (QueryParseException ex) {
ActionLib.consumeBody(action);
abortSilent(action);
String msg = messageForParseException(ex);
action.log.warn(format("[%d] Parse error: %s", action.id, msg));
ServletOps.errorBadRequest(messageForException(ex));
} catch (QueryBuildException | QueryExceptionHTTP ex) {
ActionLib.consumeBody(action);
abortSilent(action);
// Counter inc'ed further out.
String msg = messageForException(ex);
action.log.warn(format("[%d] Bad request: %s", action.id, msg));
ServletOps.errorBadRequest(messageForException(ex));
} catch (OperationDeniedException ex) {
ActionLib.consumeBody(action);
abortSilent(action);
throw ex;
} catch (Throwable ex) {
ActionLib.consumeBody(action);
if (!(ex instanceof ActionErrorException)) {
abortSilent(action);
ServletOps.errorOccurred(ex.getMessage(), ex);
}
} finally {
action.end();
}
}
use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class GSP_R method execGetGSP.
protected void execGetGSP(HttpAction action) {
ActionLib.setCommonHeaders(action);
MediaType mediaType = ActionLib.contentNegotationRDF(action);
OutputStream output;
try {
output = action.getResponseOutputStream();
} catch (IOException ex) {
ServletOps.errorOccurred(ex);
output = null;
}
Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentTypeStr());
if (lang == null)
lang = RDFLanguages.TURTLE;
action.beginRead();
if (action.verbose)
action.log.info(format("[%d] Get: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentTypeStr(), mediaType.getCharset(), lang.getName()));
try {
DatasetGraph dsg = decideDataset(action);
GraphTarget target = determineTargetGSP(dsg, action);
if (action.log.isDebugEnabled())
action.log.debug("GET->" + target);
boolean exists = target.exists();
if (!exists)
ServletOps.errorNotFound("No such graph: " + target.label());
Graph graph = target.graph();
// Special case RDF/XML to be the plain (faster, less readable) form
try {
// Use the preferred MIME type.
ActionLib.graphResponse(action, graph, lang);
ServletOps.success(action);
} catch (OperationDeniedException ex) {
throw ex;
} catch (JenaException ex) {
// ActionLib.graphResponse has special handling for RDF/XML but for
// other syntax forms unexpected errors mean we may or may not have
// written some output because of output buffering.
// Attempt to send an error - which may not work.
// "406 Not Acceptable" - Accept header issue; target is fine.
ServletOps.error(HttpSC.NOT_ACCEPTABLE_406, "Failed to write output: " + ex.getMessage());
}
} finally {
action.endRead();
}
}
use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class GSP_R method execGetQuads.
protected void execGetQuads(HttpAction action) {
ActionLib.setCommonHeaders(action);
// If this asks for triples, get N-Quads. Don't want the named graphs hidden.
MediaType mediaType = ActionLib.contentNegotationQuads(action);
ServletOutputStream output;
try {
output = action.getResponseOutputStream();
} catch (IOException ex) {
ServletOps.errorOccurred(ex);
output = null;
}
Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentTypeStr());
if (lang == null)
lang = RDFLanguages.TRIG;
if (action.verbose)
action.log.info(format("[%d] Get: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentTypeStr(), mediaType.getCharset(), lang.getName()));
if (!RDFLanguages.isQuads(lang))
ServletOps.errorBadRequest("Not a quads format: " + mediaType);
action.beginRead();
try {
DatasetGraph dsg = decideDataset(action);
try {
// Use the preferred MIME type.
ActionLib.datasetResponse(action, dsg, lang);
ServletOps.success(action);
} catch (OperationDeniedException ex) {
throw ex;
} catch (JenaException ex) {
// Attempt to send an error - which may not work.
// "406 Not Acceptable" - Accept header issue; target is fine.
ServletOps.error(HttpSC.NOT_ACCEPTABLE_406, "Failed to write output: " + ex.getMessage());
}
} finally {
action.endRead();
}
}
use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class GSP_RW method triplesPutPostTxn.
/**
* Directly add data in a transaction.
* Assumes recovery from parse errors by transaction abort.
* Return whether the target existed before.
*/
private UploadDetails triplesPutPostTxn(HttpAction action, boolean replaceOperation) {
action.beginWrite();
try {
DatasetGraph dsg = decideDataset(action);
GraphTarget target = determineTargetGSP(dsg, action);
if (action.log.isDebugEnabled())
action.log.debug(action.getRequestMethod().toUpperCase() + "->" + target);
if (target.isUnion())
ServletOps.errorBadRequest("Can't load into the union graph");
// Check URI.
if (!target.isDefault() && target.graphName() != null && !target.graphName().isBlank()) {
String uri = target.graphName().getURI();
try {
Validators.graphName(uri);
} catch (FusekiConfigException ex) {
ServletOps.errorBadRequest("Bad URI: " + uri);
return null;
}
}
boolean existedBefore = target.exists();
Graph g = target.graph();
if (replaceOperation && existedBefore)
clearGraph(target);
StreamRDF sink = StreamRDFLib.graph(g);
UploadDetails upload = DataUploader.incomingData(action, sink);
upload.setExistedBefore(existedBefore);
action.commit();
return upload;
} catch (RiotParseException ex) {
action.abortSilent();
ServletOps.errorParseError(ex);
return null;
} catch (RiotException ex) {
// Parse error
action.abortSilent();
ServletOps.errorBadRequest(ex.getMessage());
return null;
} catch (OperationDeniedException ex) {
action.abortSilent();
throw ex;
} catch (ActionErrorException ex) {
// Any ServletOps.error from calls in the try{} block.
action.abortSilent();
throw ex;
} catch (Exception ex) {
// Something unexpected.
action.abortSilent();
ServletOps.errorOccurred(ex.getMessage());
return null;
} finally {
action.end();
}
}
use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class ActionExecLib method execActionSub.
private static boolean execActionSub(HttpAction action, Supplier<ActionProcessor> processor) {
logRequest(action);
action.setStartTime();
initResponse(action);
HttpServletResponse response = action.getResponse();
startRequest(action);
try {
// Get the processor inside the startRequest - error handling - finishRequest sequence.
ActionProcessor proc = processor.get();
if (proc == null) {
// Only for the logging.
finishRequest(action);
logNoResponse(action);
archiveHttpAction(action);
// Can't find the URL (the /dataset/service case) - not handled here.
return false;
}
proc.process(action);
} catch (QueryCancelledException ex) {
// To put in the action timeout, need (1) global, (2) dataset and (3) protocol settings.
// See
// global -- cxt.get(ARQ.queryTimeout)
// dataset -- dataset.getContect(ARQ.queryTimeout)
// protocol -- SPARQL_Query.setAnyTimeouts
String message = "Query timed out";
ServletOps.responseSendError(response, HttpSC.SERVICE_UNAVAILABLE_503, message);
} catch (OperationDeniedException ex) {
if (ex.getMessage() == null)
FmtLog.info(action.log, "[%d] OperationDeniedException", action.id);
else
FmtLog.info(action.log, "[%d] OperationDeniedException: %s", action.id, ex.getMessage());
ServletOps.responseSendError(response, HttpSC.FORBIDDEN_403);
} catch (ActionErrorException ex) {
if (ex.getCause() != null)
FmtLog.warn(action.log, ex, "[%d] ActionErrorException with cause", action.id);
// Log message done by printResponse in a moment.
if (ex.getMessage() != null)
ServletOps.responseSendError(response, ex.getRC(), ex.getMessage());
else
ServletOps.responseSendError(response, ex.getRC());
} catch (HttpException ex) {
int sc = ex.getStatusCode();
if (sc <= 0)
// -1: Connection problem.
sc = 400;
// Some code is passing up its own HttpException.
if (ex.getMessage() == null)
ServletOps.responseSendError(response, sc);
else
ServletOps.responseSendError(response, sc, ex.getMessage());
} catch (QueryExceptionHTTP ex) {
// SERVICE failure.
int sc = ex.getStatusCode();
if (sc <= 0)
// -1: Connection problem. "Bad Gateway"
sc = 502;
if (ex.getMessage() == null)
ServletOps.responseSendError(response, sc);
else
ServletOps.responseSendError(response, sc, ex.getMessage());
} catch (RuntimeIOException ex) {
FmtLog.warn(action.log, /*ex,*/
"[%d] Runtime IO Exception (client left?) RC = %d : %s", action.id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
} catch (Throwable ex) {
// This should not happen.
// ex.printStackTrace(System.err);
FmtLog.warn(action.log, ex, "[%d] RC = %d : %s", action.id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
} finally {
action.setFinishTime();
finishRequest(action);
}
// Handled - including sending back errors.
logResponse(action);
archiveHttpAction(action);
return true;
}
Aggregations