Search in sources :

Example 6 with RuntimeIOException

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();
}
Also used : RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) ByteBuffer(java.nio.ByteBuffer)

Example 7 with RuntimeIOException

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);
}
Also used : RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) ByteBuffer(java.nio.ByteBuffer)

Example 8 with RuntimeIOException

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;
    }
}
Also used : ErrorHandler(org.apache.jena.riot.system.ErrorHandler) RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 9 with RuntimeIOException

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;
}
Also used : OperationDeniedException(org.apache.jena.shared.OperationDeniedException) RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpException(org.apache.jena.atlas.web.HttpException) QueryCancelledException(org.apache.jena.query.QueryCancelledException) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP)

Example 10 with RuntimeIOException

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);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) QueryCancelledException(org.apache.jena.query.QueryCancelledException)

Aggregations

RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)17 QueryCancelledException (org.apache.jena.query.QueryCancelledException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 HttpException (org.apache.jena.atlas.web.HttpException)2 Context (org.apache.jena.sparql.util.Context)2 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 URI (java.net.URI)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 Path (java.nio.file.Path)1 InvalidPropertiesFormatException (java.util.InvalidPropertiesFormatException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 InflaterInputStream (java.util.zip.InflaterInputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AtlasException (org.apache.jena.atlas.AtlasException)1 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)1