use of org.apache.jena.riot.RiotException in project jena by apache.
the class SPARQL_GSP_RW method addDataIntoTxn.
/** Directly add data in a transaction.
* Assumes recovery from parse errors by transaction abort.
* Return whether the target existed before.
* @param action
* @param cleanDest Whether to remove data first (true = PUT, false = POST)
* @return whether the target existed beforehand
*/
protected static UploadDetails addDataIntoTxn(HttpAction action, boolean overwrite) {
action.beginWrite();
try {
Target target = determineTarget(action);
if (action.log.isDebugEnabled())
action.log.debug(action.request.getMethod().toUpperCase() + "->" + target);
boolean existedBefore = target.exists();
Graph g = target.graph();
if (overwrite && existedBefore)
clearGraph(target);
StreamRDF sink = StreamRDFLib.graph(g);
UploadDetails upload = Upload.incomingData(action, sink);
upload.setExistedBefore(existedBefore);
action.commit();
return upload;
} catch (RiotException ex) {
// Parse error
action.abort();
ServletOps.errorBadRequest(ex.getMessage());
return null;
} catch (Exception ex) {
// Something else went wrong. Backout.
action.abort();
ServletOps.errorOccurred(ex.getMessage());
return null;
} finally {
action.endWrite();
}
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class SPARQL_GSP method determineTarget.
protected static final Target determineTarget(HttpAction action) {
// Delayed until inside a transaction.
if (action.getActiveDSG() == null)
ServletOps.errorOccurred("Internal error : No action graph (not in a transaction?)");
boolean dftGraph = getOneOnly(action.request, HttpNames.paramGraphDefault) != null;
String uri = getOneOnly(action.request, HttpNames.paramGraph);
if (!dftGraph && uri == null) {
// No params - direct naming.
if (!Fuseki.GSP_DIRECT_NAMING)
ServletOps.errorBadRequest("Neither default graph nor named graph specified");
// Direct naming.
String directName = action.request.getRequestURL().toString();
if (action.request.getRequestURI().equals(action.getDatasetName()))
// No name (should have been a quads operations).
ServletOps.errorBadRequest("Neither default graph nor named graph specified and no direct name");
Node gn = NodeFactory.createURI(directName);
return namedTarget(action, directName);
}
if (dftGraph)
return Target.createDefault(action.getActiveDSG());
// Named graph
if (uri.equals(HttpNames.valueDefault))
// But "named" default
return Target.createDefault(action.getActiveDSG());
// Strictly, a bit naughty on the URI resolution. But more sensible.
// Base is dataset.
// XXX Remove any service.
//wholeRequestURL(request) ;
String base = action.request.getRequestURL().toString();
// Make sure it ends in "/", ie. dataset as container.
if (action.request.getQueryString() != null && !base.endsWith("/"))
base = base + "/";
String absUri = null;
try {
absUri = IRIResolver.resolveString(uri, base);
} catch (RiotException ex) {
// Bad IRI
ServletOps.errorBadRequest("Bad IRI: " + ex.getMessage());
}
return namedTarget(action, absUri);
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class StreamRDFLimited method quad.
@Override
public void quad(Quad quad) {
count++;
if (count > limit)
throw new RiotException("Limit (" + limit + ") reached");
super.quad(quad);
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class SPARQL_QueryGeneral method datasetFromDescriptionWeb.
/**
* Construct a Dataset based on a dataset description. Loads graph from the
* web.
*/
protected Dataset datasetFromDescriptionWeb(HttpAction action, DatasetDescription datasetDesc) {
try {
if (datasetDesc == null)
return null;
if (datasetDesc.isEmpty())
return null;
List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
if (graphURLs.size() == 0 && namedGraphs.size() == 0)
return null;
Dataset dataset = DatasetFactory.create();
// Look in cache for loaded graphs!!
// ---- Default graph
{
Model model = ModelFactory.createDefaultModel();
for (String uri : graphURLs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Default graph URI is null or the empty string");
try {
GraphLoadUtils.loadModel(model, uri, MaxTriples);
action.log.info(format("[%d] Load (default graph) %s", action.id, uri));
} catch (RiotException ex) {
action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
action.log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL " + uri);
}
}
dataset.setDefaultModel(model);
}
// ---- Named graphs
if (namedGraphs != null) {
for (String uri : namedGraphs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Named graph URI is null or the empty string");
try {
Model model = ModelFactory.createDefaultModel();
GraphLoadUtils.loadModel(model, uri, MaxTriples);
action.log.info(format("[%d] Load (named graph) %s", action.id, uri));
dataset.addNamedModel(uri, model);
} catch (RiotException ex) {
action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
action.log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL " + uri);
}
}
}
return dataset;
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
action.log.info(format("[%d] SPARQL parameter error: " + ex.getMessage(), action.id, ex));
ServletOps.errorBadRequest("Parameter error: " + ex.getMessage());
return null;
}
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class ReaderTriX method read.
@Override
public void read(InputStream in, String baseURI, ContentType ct, StreamRDF output, Context context) {
XMLInputFactory xf = XMLInputFactory.newInstance();
XMLStreamReader xReader;
try {
xReader = xf.createXMLStreamReader(in);
} catch (XMLStreamException e) {
throw new RiotException("Can't initialize StAX parsing engine", e);
}
read(xReader, baseURI, output);
}
Aggregations