use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.
the class TransBlob method writeBlobState.
private void writeBlobState() {
ByteBuffer blob = blobRef.get();
blob.rewind();
int x = blob.remaining();
file.truncate(0);
int len = file.write(blob);
if (len != x)
throw new RuntimeIOException("Short write: " + len + " of " + x);
file.sync();
blob.rewind();
}
use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.
the class TransBlob method read.
private void read() {
long x = file.size();
ByteBuffer blob = ByteBuffer.allocate((int) x);
int len = file.read(blob);
if (len != x)
throw new RuntimeIOException("Short read: " + len + " of " + x);
blob.rewind();
blobRef.set(blob);
}
use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.
the class ActionLib method parse.
/**
* Parse RDF content. This wraps up the parse step reading from an input stream.
* @throws RiotParseException
*/
public static void parse(HttpAction action, StreamRDF dest, InputStream input, Lang lang, String base) {
try {
if (!RDFParserRegistry.isRegistered(lang))
ServletOps.errorBadRequest("No parser for language '" + lang.getName() + "'");
ErrorHandler errorHandler = ErrorHandlerFactory.errorHandlerStd(action.log);
RDFParser.create().errorHandler(errorHandler).source(input).lang(lang).base(base).parse(dest);
} catch (RuntimeIOException ex) {
if (ex.getCause() instanceof CharacterCodingException)
throw new RiotException("Character Coding Error: " + ex.getMessage());
throw ex;
}
}
use of org.apache.jena.atlas.RuntimeIOException 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;
}
use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.
the class ActionBase method doCommon.
/**
* Common framework for handling HTTP requests.
* @param request
* @param response
*/
protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
try {
long id = allocRequestId(request, response);
// Lifecycle
HttpAction action = allocHttpAction(id, request, response);
printRequest(action);
action.setStartTime();
// The response may be changed to a HttpServletResponseTracker
response = action.response;
initResponse(request, response);
Context cxt = ARQ.getContext();
try {
execCommonWorker(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 = String.format("Query timed out");
// Possibility :: response.setHeader("Retry-after", "600") ; // 5 minutes
ServletOps.responseSendError(response, HttpSC.SERVICE_UNAVAILABLE_503, message);
} catch (ActionErrorException ex) {
if (ex.getCause() != null)
ex.getCause().printStackTrace(System.err);
// 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 (RuntimeIOException ex) {
log.warn(format("[%d] Runtime IO Exception (client left?) RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex);
ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
} catch (Throwable ex) {
// This should not happen.
//ex.printStackTrace(System.err) ;
log.warn(format("[%d] RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex);
ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
}
action.setFinishTime();
printResponse(action);
archiveHttpAction(action);
} catch (Throwable th) {
log.error("Internal error", th);
}
}
Aggregations