Search in sources :

Example 1 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class AbstractRDFInserter method handleStatement.

@Override
public void handleStatement(Statement st) throws RDFHandlerException {
    Resource subj = st.getSubject();
    IRI pred = st.getPredicate();
    Value obj = st.getObject();
    Resource ctxt = st.getContext();
    if (!preserveBNodeIDs) {
        if (subj instanceof BNode) {
            subj = mapBNode((BNode) subj);
        }
        if (obj instanceof BNode) {
            obj = mapBNode((BNode) obj);
        }
        if (!enforcesContext() && ctxt instanceof BNode) {
            ctxt = mapBNode((BNode) ctxt);
        }
    }
    try {
        addStatement(subj, pred, obj, ctxt);
    } catch (RDF4JException e) {
        throw new RDFHandlerException(e);
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) BNode(org.eclipse.rdf4j.model.BNode) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value) RDF4JException(org.eclipse.rdf4j.RDF4JException)

Example 2 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class AbstractRDFInserter method endRDF.

@Override
public void endRDF() throws RDFHandlerException {
    for (Map.Entry<String, String> entry : namespaceMap.entrySet()) {
        String prefix = entry.getKey();
        String name = entry.getValue();
        try {
            addNamespace(prefix, name);
        } catch (RDF4JException e) {
            throw new RDFHandlerException(e);
        }
    }
    namespaceMap.clear();
    bNodesMap.clear();
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) RDF4JException(org.eclipse.rdf4j.RDF4JException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class RDF4JProtocolSession method upload.

protected void upload(HttpEntity reqEntity, String baseURI, boolean overwrite, boolean preserveNodeIds, Action action, Resource... contexts) throws IOException, RDFParseException, RepositoryException, UnauthorizedException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    checkRepositoryURL();
    String transactionURL = getTransactionURL();
    boolean useTransaction = transactionURL != null;
    try {
        String baseLocation = useTransaction ? transactionURL : Protocol.getStatementsLocation(getQueryURL());
        URIBuilder url = new URIBuilder(baseLocation);
        // Set relevant query parameters
        for (String encodedContext : Protocol.encodeContexts(contexts)) {
            url.addParameter(Protocol.CONTEXT_PARAM_NAME, encodedContext);
        }
        if (baseURI != null && baseURI.trim().length() != 0) {
            String encodedBaseURI = Protocol.encodeValue(SimpleValueFactory.getInstance().createIRI(baseURI));
            url.setParameter(Protocol.BASEURI_PARAM_NAME, encodedBaseURI);
        }
        if (preserveNodeIds) {
            url.setParameter(Protocol.PRESERVE_BNODE_ID_PARAM_NAME, "true");
        }
        if (useTransaction) {
            if (action == null) {
                throw new IllegalArgumentException("action can not be null on transaction operation");
            }
            url.setParameter(Protocol.ACTION_PARAM_NAME, action.toString());
        }
        // Select appropriate HTTP method
        HttpEntityEnclosingRequestBase method = null;
        try {
            if (overwrite || useTransaction) {
                method = new HttpPut(url.build());
            } else {
                method = new HttpPost(url.build());
            }
            // Set payload
            method.setEntity(reqEntity);
            // Send request
            try {
                executeNoContent((HttpUriRequest) method);
            } catch (RepositoryException e) {
                throw e;
            } catch (RDFParseException e) {
                throw e;
            } catch (RDF4JException e) {
                throw new RepositoryException(e);
            }
        } finally {
            if (method != null) {
                method.reset();
            }
        }
    } catch (URISyntaxException e) {
        throw new AssertionError(e);
    }
    pingTransaction();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) HttpPut(org.apache.http.client.methods.HttpPut) URIBuilder(org.apache.http.client.utils.URIBuilder) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 4 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class RDF4JProtocolSession method sendTransaction.

/**
 * Sends a transaction list as serialized XML to the server.
 *
 * @deprecated since 2.8.0
 * @param txn
 * @throws IOException
 * @throws RepositoryException
 * @throws UnauthorizedException
 */
@Deprecated
public void sendTransaction(final Iterable<? extends TransactionOperation> txn) throws IOException, RepositoryException, UnauthorizedException {
    checkRepositoryURL();
    HttpPost method = new HttpPost(Protocol.getStatementsLocation(getQueryURL()));
    try {
        // Create a RequestEntity for the transaction data
        method.setEntity(new AbstractHttpEntity() {

            public long getContentLength() {
                // don't know
                return -1;
            }

            public Header getContentType() {
                return new BasicHeader("Content-Type", Protocol.TXN_MIME_TYPE);
            }

            public boolean isRepeatable() {
                return true;
            }

            public boolean isStreaming() {
                return true;
            }

            public InputStream getContent() throws IOException, IllegalStateException {
                ByteArrayOutputStream buf = new ByteArrayOutputStream();
                writeTo(buf);
                return new ByteArrayInputStream(buf.toByteArray());
            }

            public void writeTo(OutputStream out) throws IOException {
                TransactionWriter txnWriter = new TransactionWriter();
                txnWriter.serialize(txn, out);
            }
        });
        try {
            executeNoContent(method);
        } catch (RepositoryException e) {
            throw e;
        } catch (RDF4JException e) {
            throw new RepositoryException(e);
        }
    } finally {
        method.reset();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) TransactionWriter(org.eclipse.rdf4j.http.protocol.transaction.TransactionWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) ByteArrayInputStream(java.io.ByteArrayInputStream) RDF4JException(org.eclipse.rdf4j.RDF4JException) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity) BasicHeader(org.apache.http.message.BasicHeader)

Example 5 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class RDF4JProtocolSession method getServerProtocol.

/*------------------*
	 * Protocol version *
	 *------------------*/
public String getServerProtocol() throws IOException, RepositoryException, UnauthorizedException {
    checkServerURL();
    HttpGet method = new HttpGet(Protocol.getProtocolLocation(serverURL));
    try {
        return EntityUtils.toString(executeOK(method).getEntity());
    } catch (RepositoryException e) {
        throw e;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } finally {
        method.reset();
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Aggregations

RDF4JException (org.eclipse.rdf4j.RDF4JException)16 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)13 IOException (java.io.IOException)4 HttpGet (org.apache.http.client.methods.HttpGet)3 HttpPut (org.apache.http.client.methods.HttpPut)3 URISyntaxException (java.net.URISyntaxException)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPost (org.apache.http.client.methods.HttpPost)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)2 QueryInterruptedException (org.eclipse.rdf4j.query.QueryInterruptedException)2 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCursor (com.mongodb.DBCursor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1