Search in sources :

Example 1 with ClientException

use of org.apache.sling.hapi.client.ClientException in project sling by apache.

the class AbstractHtmlClientImpl method post.

@Override
public <T extends Document> T post(String url, HttpEntity entity) throws ClientException {
    try {
        URI absoluteUri = absoluteUri(url);
        LOG.info("POST " + absoluteUri);
        HttpPost post = new HttpPost(absoluteUri);
        post.setEntity(entity);
        HttpResponse response = this.execute(post);
        return newDocument(EntityUtils.toString(response.getEntity()));
    } catch (URISyntaxException e) {
        throw new ClientException("Invalid post url " + url, e);
    } catch (Exception e) {
        throw new ClientException("Could not execute POST request", e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponse(org.apache.http.HttpResponse) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) URI(java.net.URI) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) IOException(java.io.IOException)

Example 2 with ClientException

use of org.apache.sling.hapi.client.ClientException in project sling by apache.

the class AbstractHtmlClientImpl method delete.

@Override
public <T extends Document> T delete(String url) throws ClientException {
    try {
        URI absoluteUri = absoluteUri(url);
        LOG.info("DELETE " + absoluteUri);
        HttpResponse response = this.execute(new HttpDelete(absoluteUri));
        return newDocument(response.getEntity().toString());
    } catch (URISyntaxException e) {
        throw new ClientException("Invalid post url " + url, e);
    } catch (Exception e) {
        throw new ClientException("Could not execute DELETE request", e);
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) URI(java.net.URI) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) IOException(java.io.IOException)

Example 3 with ClientException

use of org.apache.sling.hapi.client.ClientException in project sling by apache.

the class AbstractHtmlClientImpl method get.

@Override
public <T extends Document> T get(String url) throws ClientException {
    try {
        URI absoluteUri = absoluteUri(url);
        LOG.info("GET " + absoluteUri);
        HttpResponse response = this.execute(new HttpGet(absoluteUri));
        return newDocument(EntityUtils.toString(response.getEntity()));
    } catch (URISyntaxException e) {
        throw new ClientException("Invalid get url " + url, e);
    } catch (Exception e) {
        throw new ClientException("Could not execute GET request", e);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) URI(java.net.URI) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 HttpResponse (org.apache.http.HttpResponse)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 ClientException (org.apache.sling.hapi.client.ClientException)3 HttpDelete (org.apache.http.client.methods.HttpDelete)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPost (org.apache.http.client.methods.HttpPost)1