Search in sources :

Example 1 with ConfluenceException

use of org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException in project manifoldcf by apache.

the class ConfluenceClient method getSpacePermissionsForUser.

private List<String> getSpacePermissionsForUser(final Space space, final String username) throws Exception {
    final String url = String.format(Locale.ROOT, "%s://%s:%s%s%sgetPermissionsForUser", protocol, host, port, path, AUTHORITY_PATH);
    logger.debug("[Processing] Hitting url {} for getting Confluence permissions for user {} in space {}", url, username, space.getKey());
    final HttpPost httpPost = createPostRequest(url);
    final JSONArray jsonArray = new JSONArray();
    jsonArray.add(space.getKey());
    jsonArray.add(username);
    final StringEntity stringEntity = new StringEntity(jsonArray.toJSONString());
    httpPost.setEntity(stringEntity);
    final HttpResponse response = httpClient.execute(httpPost);
    if (response.getStatusLine().getStatusCode() != 200) {
        throw new ConfluenceException("Confluence error. " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase());
    }
    final HttpEntity entity = response.getEntity();
    final List<String> permissions = permissionsFromHttpEntity(entity);
    EntityUtils.consume(entity);
    return permissions;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ConfluenceException(org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException) HttpEntity(org.apache.http.HttpEntity) JSONArray(org.json.simple.JSONArray) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpResponse(org.apache.http.HttpResponse)

Aggregations

HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1 ConfluenceException (org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException)1 JSONArray (org.json.simple.JSONArray)1