Search in sources :

Example 1 with RuntimeIOException

use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.

the class SPARQL_ServletBase method doCommon.

// Common framework for handling HTTP requests
/**
     * Handles GET and POST requests.
     * @param request HTTP request
     * @param response HTTP response
     */
protected void doCommon(HttpServletRequest request, HttpServletResponse response) //throws ServletException, IOException
{
    try {
        long id = allocRequestId(request, response);
        // Lifecycle
        HttpAction action = allocHttpAction(id, request, response);
        // then add to doCommonWorker
        // work with HttpServletResponseTracker
        printRequest(action);
        action.setStartTime();
        response = action.response;
        initResponse(request, response);
        Context cxt = ARQ.getContext();
        try {
            execCommonWorker(action);
        } catch (QueryCancelledException ex) {
            // Also need the per query info ...
            String message = String.format("The query timed out (restricted to %s ms)", cxt.get(ARQ.queryTimeout));
            // Possibility :: response.setHeader("Retry-after", "600") ;    // 5 minutes
            responseSendError(response, HttpSC.SERVICE_UNAVAILABLE_503, message);
        } catch (ActionErrorException ex) {
            if (ex.exception != null)
                ex.exception.printStackTrace(System.err);
            // Log message done by printResponse in a moment.
            if (ex.message != null)
                responseSendError(response, ex.rc, ex.message);
            else
                responseSendError(response, ex.rc);
        } catch (RuntimeIOException ex) {
            log.warn(format("[%d] Runtime IO Exception (client left?) RC = %d", id, HttpSC.INTERNAL_SERVER_ERROR_500));
            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);
            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)

Example 2 with RuntimeIOException

use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.

the class BinaryDataFileRandomAccess method open.

@Override
public void open() {
    if (file != null)
        throw new RuntimeIOException("Already open");
    try {
        file = new RandomAccessFile(filename, "rw");
        writePosition = file.length();
        readPosition = 0;
        readMode = true;
    } catch (IOException e) {
        IO.exception(e);
    }
}
Also used : RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) RandomAccessFile(java.io.RandomAccessFile) RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) IOException(java.io.IOException)

Example 3 with RuntimeIOException

use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.

the class BinaryDataFileMem method open.

@Override
public synchronized void open() {
    if (storage != null)
        throw new RuntimeIOException("Already open");
    storage = new SegmentedMemBuffer();
    readMode = true;
}
Also used : RuntimeIOException(org.apache.jena.atlas.RuntimeIOException)

Example 4 with RuntimeIOException

use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.

the class TransBinaryDataFile method truncate.

/**
 * Truncate only supported for an abort - this transactional version of
 * {@link BinaryDataFile} will not truncate to earlier than the committed length.
 */
@Override
public void truncate(long size) {
    requireWriteTxn();
    TxnBinFile state = getDataState();
    if (size < state.length)
        throw new RuntimeIOException("truncate(" + size + ") to smaller than commited length " + state.length);
    binFile.truncate(size);
}
Also used : RuntimeIOException(org.apache.jena.atlas.RuntimeIOException)

Example 5 with RuntimeIOException

use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.

the class ActionService method executeLifecycle.

/**
 * Add counters to the validate-execute lifecycle.
 */
@Override
protected void executeLifecycle(HttpAction action) {
    // And also HTTP counter
    CounterSet csService = (action.getDataService() == null) ? null : action.getDataService().getCounters();
    CounterSet csOperation = null;
    if (action.getEndpoint() != null)
        // Direct naming GSP does not have an "endpoint".
        csOperation = action.getEndpoint().getCounters();
    incCounter(csService, Requests);
    incCounter(csOperation, Requests);
    // or in execution in perform.
    try {
        validate(action);
    } catch (ActionErrorException ex) {
        incCounter(csOperation, RequestsBad);
        incCounter(csService, RequestsBad);
        throw ex;
    }
    try {
        execute(action);
        // Success
        incCounter(csOperation, RequestsGood);
        incCounter(csService, RequestsGood);
    } catch (ActionErrorException | QueryCancelledException | RuntimeIOException ex) {
        incCounter(csOperation, RequestsBad);
        incCounter(csService, RequestsBad);
        throw ex;
    }
}
Also used : RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) CounterSet(org.apache.jena.fuseki.server.CounterSet) 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