Search in sources :

Example 11 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class RDFXMLParserCustomTest method testEntityExpansionNoSecureProcessing.

/**
 * Test with Secure processing setting off.
 * <p>
 * IMPORTANT: Only turn this on to verify it is still working, as there is no way to safely perform this
 * test.
 * <p>
 * WARNING: This test will cause an OutOfMemoryException when it eventually fails, as it will eventually
 * fail.
 *
 * @throws Exception
 */
@Ignore
@Test(timeout = 10000)
public void testEntityExpansionNoSecureProcessing() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).set(XMLParserSettings.SECURE_PROCESSING, false).setParseErrorListener(errorCollector);
    try {
        // IMPORTANT: This will not use the entity limit
        aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the"));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class SPARQLConnection method add.

@Override
public void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    // to preserve bnode identity, we need to make sure all statements are
    // processed in a single INSERT DATA command
    StatementCollector collector = new StatementCollector();
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(file, baseURI, dataFormat, collector);
        add(collector.getStatements(), contexts);
        conditionalCommit(localTransaction);
    } catch (RDFHandlerException e) {
        conditionalRollback(localTransaction);
        // RDFInserter only throws wrapped RepositoryExceptions
        throw (RepositoryException) e.getCause();
    } catch (RDFParseException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (IOException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) IOException(java.io.IOException) RDFLoader(org.eclipse.rdf4j.repository.util.RDFLoader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 13 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class SPARQLConnection method add.

@Override
public void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    // to preserve bnode identity, we need to make sure all statements are
    // processed in a single INSERT DATA command
    StatementCollector collector = new StatementCollector();
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(reader, baseURI, dataFormat, collector);
        add(collector.getStatements(), contexts);
        conditionalCommit(localTransaction);
    } catch (RDFHandlerException e) {
        conditionalRollback(localTransaction);
        // RDFInserter only throws wrapped RepositoryExceptions
        throw (RepositoryException) e.getCause();
    } catch (RDFParseException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (IOException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) IOException(java.io.IOException) RDFLoader(org.eclipse.rdf4j.repository.util.RDFLoader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 14 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class SPARQLConnection method add.

@Override
public void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    // to preserve bnode identity, we need to make sure all statements are
    // processed in a single INSERT DATA command
    StatementCollector collector = new StatementCollector();
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(in, baseURI, dataFormat, collector);
        add(collector.getStatements(), contexts);
        conditionalCommit(localTransaction);
    } catch (RDFHandlerException e) {
        conditionalRollback(localTransaction);
        // RDFInserter only throws wrapped RepositoryExceptions
        throw (RepositoryException) e.getCause();
    } catch (RDFParseException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (IOException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) IOException(java.io.IOException) RDFLoader(org.eclipse.rdf4j.repository.util.RDFLoader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 15 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method addModel.

private void addModel(Model m) throws RepositoryException {
    // TODO we should dynamically pick a format from the available writers
    // perhaps?
    RDFFormat format = RDFFormat.BINARY;
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Rio.write(m, out, format);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        client.addData(in, null, format);
    } catch (RDFHandlerException e) {
        throw new RepositoryException("error while writing statement", e);
    } catch (RDFParseException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Aggregations

RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)50 Test (org.junit.Test)22 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)19 IOException (java.io.IOException)16 StringReader (java.io.StringReader)13 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)9 RDFLoader (org.eclipse.rdf4j.repository.util.RDFLoader)8 Model (org.eclipse.rdf4j.model.Model)7 RDFParser (org.eclipse.rdf4j.rio.RDFParser)7 Statement (org.eclipse.rdf4j.model.Statement)6 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)6 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)5 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 Reader (java.io.Reader)4 RDFInserter (org.eclipse.rdf4j.repository.util.RDFInserter)4 SAXException (org.xml.sax.SAXException)4 IRI (org.eclipse.rdf4j.model.IRI)3 Literal (org.eclipse.rdf4j.model.Literal)3