Search in sources :

Example 11 with RDF4JException

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

the class RDF4JProtocolSession method getNamespace.

public String getNamespace(String prefix) throws IOException, RepositoryException, UnauthorizedException {
    checkRepositoryURL();
    HttpGet method = new HttpGet(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix));
    try {
        HttpResponse response = execute(method);
        int code = response.getStatusLine().getStatusCode();
        if (code == HttpURLConnection.HTTP_OK || code == HttpURLConnection.HTTP_NOT_AUTHORITATIVE) {
            return EntityUtils.toString(response.getEntity());
        } else {
            EntityUtils.consume(response.getEntity());
            return null;
        }
    } catch (RepositoryException e) {
        throw e;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } finally {
        method.reset();
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 12 with RDF4JException

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

the class RDF4JProtocolSession method clearNamespaces.

public void clearNamespaces() throws IOException, RepositoryException, UnauthorizedException {
    checkRepositoryURL();
    HttpDelete method = new HttpDelete(Protocol.getNamespacesLocation(getQueryURL()));
    try {
        executeNoContent(method);
    } catch (RepositoryException e) {
        throw e;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } finally {
        method.reset();
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 13 with RDF4JException

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

the class RDF4JProtocolSession method setNamespacePrefix.

public void setNamespacePrefix(String prefix, String name) throws IOException, RepositoryException, UnauthorizedException {
    checkRepositoryURL();
    HttpPut method = new HttpPut(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix));
    try {
        method.setEntity(new StringEntity(name, ContentType.create("text/plain", "UTF-8")));
        executeNoContent(method);
    } catch (RepositoryException e) {
        throw e;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } finally {
        method.reset();
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) HttpPut(org.apache.http.client.methods.HttpPut)

Example 14 with RDF4JException

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

the class RDF4JProtocolSession method size.

/*-------------------------*
	 * Repository/context size *
	 *-------------------------*/
public long size(Resource... contexts) throws IOException, RepositoryException, UnauthorizedException {
    checkRepositoryURL();
    try {
        String transactionURL = getTransactionURL();
        final boolean useTransaction = transactionURL != null;
        String baseLocation = useTransaction ? appendAction(transactionURL, Action.SIZE) : Protocol.getSizeLocation(getQueryURL());
        URIBuilder url = new URIBuilder(baseLocation);
        String[] encodedContexts = Protocol.encodeContexts(contexts);
        for (int i = 0; i < encodedContexts.length; i++) {
            url.addParameter(Protocol.CONTEXT_PARAM_NAME, encodedContexts[i]);
        }
        final HttpRequestBase method = useTransaction ? new HttpPut(url.build()) : new HttpGet(url.build());
        try {
            String response = EntityUtils.toString(executeOK(method).getEntity());
            pingTransaction();
            try {
                return Long.parseLong(response);
            } catch (NumberFormatException e) {
                throw new RepositoryException("Server responded with invalid size value: " + response);
            }
        } finally {
            method.reset();
        }
    } catch (URISyntaxException e) {
        throw new AssertionError(e);
    } catch (RepositoryException e) {
        throw e;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    }
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpGet(org.apache.http.client.methods.HttpGet) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) HttpPut(org.apache.http.client.methods.HttpPut) URIBuilder(org.apache.http.client.utils.URIBuilder) RDF4JException(org.eclipse.rdf4j.RDF4JException)

Example 15 with RDF4JException

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

the class SPARQLProtocolSession method sendGraphQueryViaHttp.

private HttpResponse sendGraphQueryViaHttp(HttpUriRequest method, boolean requireContext, Set<RDFFormat> rdfFormats) throws RepositoryException, IOException, QueryInterruptedException, MalformedQueryException {
    List<String> acceptParams = RDFFormat.getAcceptParams(rdfFormats, requireContext, getPreferredRDFFormat());
    method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptParams));
    try {
        return executeOK(method);
    } catch (RepositoryException | MalformedQueryException | QueryInterruptedException e) {
        throw e;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    }
}
Also used : MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) QueryInterruptedException(org.eclipse.rdf4j.query.QueryInterruptedException)

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