Search in sources :

Example 1 with TransactionWriter

use of org.eclipse.rdf4j.http.protocol.transaction.TransactionWriter 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Header (org.apache.http.Header)1 HttpPost (org.apache.http.client.methods.HttpPost)1 AbstractHttpEntity (org.apache.http.entity.AbstractHttpEntity)1 BasicHeader (org.apache.http.message.BasicHeader)1 RDF4JException (org.eclipse.rdf4j.RDF4JException)1 TransactionWriter (org.eclipse.rdf4j.http.protocol.transaction.TransactionWriter)1 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)1