Search in sources :

Example 6 with OperationDeniedException

use of org.apache.jena.shared.OperationDeniedException in project jena by apache.

the class UploadRDF method quadsPutPostNonTxn.

/**
 * Load data, without assuming the dataset of an action is transactional -
 * specifically, whether it supports "abort". This requires loading the data into
 * a temporary dataset, which means we check the data is legal RDF, then copying
 * it into the finally destination.
 * <p>
 * Delayed choice of dataset via a function so that the decision is made inside the transaction updating the data.
 */
public static UploadDetails quadsPutPostNonTxn(HttpAction action, Function<HttpAction, DatasetGraph> decideDataset, boolean replaceOperation) {
    DatasetGraph dsgTmp = DatasetGraphFactory.create();
    StreamRDF dest = StreamRDFLib.dataset(dsgTmp);
    UploadDetails details;
    try {
        details = DataUploader.incomingData(action, dest);
    } catch (RiotException ex) {
        ServletOps.errorBadRequest(ex.getMessage());
        return null;
    }
    // Now insert into dataset
    action.beginWrite();
    try {
        DatasetGraph dsg = decideDataset.apply(action);
        if (replaceOperation)
            dsg.clear();
        FusekiNetLib.addDataInto(dsgTmp, dsg);
        action.commit();
    } catch (OperationDeniedException ex) {
        action.abortSilent();
        throw ex;
    } catch (Exception ex) {
        // We're in a non-transactional upload so this probably will not
        // work but there still may be transaction state tracking.
        // There is no harm safely trying.
        action.abortSilent();
        ServletOps.errorOccurred(ex.getMessage());
    } finally {
        action.end();
    }
    return details;
}
Also used : OperationDeniedException(org.apache.jena.shared.OperationDeniedException) UploadDetails(org.apache.jena.fuseki.system.UploadDetails) RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) OperationDeniedException(org.apache.jena.shared.OperationDeniedException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 7 with OperationDeniedException

use of org.apache.jena.shared.OperationDeniedException in project jena by apache.

the class UploadRDF method quadsPutPostTxn.

/**
 * Load data using a transaction into the dataset of an action. if the data is bad,
 * abort the transaction.
 * <p>
 * Delayed choice of dataset via a function so that the decision is made inside the transaction.
 */
public static UploadDetails quadsPutPostTxn(HttpAction action, Function<HttpAction, DatasetGraph> decideDataset, boolean replaceOperation) {
    UploadDetails details = null;
    action.beginWrite();
    try {
        DatasetGraph dsg = decideDataset.apply(action);
        if (replaceOperation)
            dsg.clear();
        StreamRDF dest = StreamRDFLib.dataset(dsg);
        details = DataUploader.incomingData(action, dest);
        action.commit();
    } catch (RiotException ex) {
        // Parse error
        action.abortSilent();
        if (ex.getMessage() != null)
            action.log.info(format("[%d] Data error: %s", action.id, ex.getMessage()));
        else
            action.log.info(format("[%d] Data error", action.id), ex);
        ServletOps.errorBadRequest(ex.getMessage());
    } catch (OperationDeniedException ex) {
        action.abortSilent();
        throw ex;
    } catch (ActionErrorException ex) {
        action.abortSilent();
        if (ex.getMessage() != null)
            action.log.info(format("[%d] Upload error: %s", action.id, ex.getMessage()));
        else
            action.log.info(format("[%d] Upload error", action.id), ex);
        throw ex;
    } catch (Exception ex) {
        // Something else went wrong. Backout.
        action.abortSilent();
        ServletOps.errorOccurred(ex.getMessage());
    } finally {
        action.end();
    }
    return details;
}
Also used : OperationDeniedException(org.apache.jena.shared.OperationDeniedException) UploadDetails(org.apache.jena.fuseki.system.UploadDetails) RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) OperationDeniedException(org.apache.jena.shared.OperationDeniedException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 8 with OperationDeniedException

use of org.apache.jena.shared.OperationDeniedException in project jena by apache.

the class GSP_RW method triplesPutPostNonTxn.

/**
 * Add data where the destination does not support full transactions.
 *  In particular, with no abort, and actions probably going to the real storage
 *  parse errors can lead to partial updates.  Instead, parse to a temporary
 *  graph, then insert that data.
 */
private UploadDetails triplesPutPostNonTxn(HttpAction action, boolean replaceOperation) {
    Graph graphTmp = GraphFactory.createGraphMem();
    StreamRDF dest = StreamRDFLib.graph(graphTmp);
    UploadDetails details;
    try {
        details = DataUploader.incomingData(action, dest);
    } catch (RiotParseException ex) {
        ServletOps.errorParseError(ex);
        return null;
    }
    // Now insert into dataset
    action.beginWrite();
    try {
        DatasetGraph dsg = decideDataset(action);
        GraphTarget target = determineTargetGSP(dsg, action);
        if (action.log.isDebugEnabled())
            action.log.debug("  ->" + target);
        if (target.isUnion())
            ServletOps.errorBadRequest("Can't load into the union graph");
        boolean existedBefore = target.exists();
        if (replaceOperation && existedBefore)
            clearGraph(target);
        FusekiNetLib.addDataInto(graphTmp, target.dataset(), target.graphName());
        details.setExistedBefore(existedBefore);
        action.commit();
        return details;
    } catch (OperationDeniedException ex) {
        action.abortSilent();
        throw ex;
    } catch (Exception ex) {
        // We parsed into a temporary graph so an exception at this point
        // is not because of a parse error.
        // We're in the non-transactional branch, this probably will not work
        // but it might and there is no harm safely trying.
        action.abortSilent();
        ServletOps.errorOccurred(ex.getMessage());
        return null;
    } finally {
        action.end();
    }
}
Also used : OperationDeniedException(org.apache.jena.shared.OperationDeniedException) RiotParseException(org.apache.jena.riot.RiotParseException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) UploadDetails(org.apache.jena.fuseki.system.UploadDetails) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException) OperationDeniedException(org.apache.jena.shared.OperationDeniedException) RiotParseException(org.apache.jena.riot.RiotParseException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

OperationDeniedException (org.apache.jena.shared.OperationDeniedException)8 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)6 UploadDetails (org.apache.jena.fuseki.system.UploadDetails)4 RiotException (org.apache.jena.riot.RiotException)4 StreamRDF (org.apache.jena.riot.system.StreamRDF)4 Graph (org.apache.jena.graph.Graph)3 IOException (java.io.IOException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 MediaType (org.apache.jena.atlas.web.MediaType)2 FusekiConfigException (org.apache.jena.fuseki.FusekiConfigException)2 Lang (org.apache.jena.riot.Lang)2 RiotParseException (org.apache.jena.riot.RiotParseException)2 JenaException (org.apache.jena.shared.JenaException)2 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)2 OutputStream (java.io.OutputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 HttpException (org.apache.jena.atlas.web.HttpException)1 QueryBuildException (org.apache.jena.query.QueryBuildException)1 QueryCancelledException (org.apache.jena.query.QueryCancelledException)1