Search in sources :

Example 1 with ConfluenceResourceBuilder

use of org.apache.manifoldcf.crawler.connectors.confluence.v6.model.builder.ConfluenceResourceBuilder in project manifoldcf by apache.

the class ConfluenceClient method pageFromHttpEntity.

/**
 * <p>
 * Creates a Confluence page object from the given entity returned by the server
 * </p>
 *
 * @param entity
 *          the {@code HttpEntity} to create the {@code MutablePage} from
 * @return the Confluence page instance
 * @throws Exception
 */
private MutablePage pageFromHttpEntity(final HttpEntity entity) throws Exception {
    final String stringEntity = EntityUtils.toString(entity, "UTF-8");
    final JSONParser parser = new JSONParser();
    final JSONObject responseObject = (JSONObject) parser.parse(new StringReader(stringEntity));
    @SuppressWarnings("unchecked") final MutablePage response = ((ConfluenceResourceBuilder<MutablePage>) MutablePage.builder()).fromJson(responseObject, new MutablePage());
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) MutablePage(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage) StringReader(java.io.StringReader) ConfluenceResourceBuilder(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.builder.ConfluenceResourceBuilder) JSONParser(org.json.simple.parser.JSONParser)

Example 2 with ConfluenceResourceBuilder

use of org.apache.manifoldcf.crawler.connectors.confluence.v6.model.builder.ConfluenceResourceBuilder in project manifoldcf by apache.

the class ConfluenceClient method getConfluenceRestrictionsResources.

/**
 * <p>
 * Get the {@code ConfluenceResources} from the given url
 * </p>
 *
 * @param url
 *          The url identifying the REST resource to get the documents
 * @param builder
 *          The builder used to build the resources contained in the response
 * @return a {@code ConfluenceRestrictionsResponse} containing the page results
 * @throws Exception
 */
private ConfluenceRestrictionsResponse<? extends ConfluenceResource> getConfluenceRestrictionsResources(final String url, final ConfluenceResourceBuilder<? extends ConfluenceResource> builder) throws Exception {
    logger.debug("[Processing] Hitting url for get confluence resources: {}", sanitizeUrl(url));
    final HttpGet httpGet = createGetRequest(url);
    try (CloseableHttpResponse response = executeRequest(httpGet)) {
        final ConfluenceRestrictionsResponse<? extends ConfluenceResource> confluenceResponse = restrictionsResponseFromHttpEntity(response.getEntity(), builder);
        EntityUtils.consume(response.getEntity());
        return confluenceResponse;
    } catch (final IOException e) {
        logger.error("[Processing] Failed to get page(s)", e);
        throw new Exception("Confluence appears to be down", e);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) ConfluenceException(org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException) IOException(java.io.IOException)

Example 3 with ConfluenceResourceBuilder

use of org.apache.manifoldcf.crawler.connectors.confluence.v6.model.builder.ConfluenceResourceBuilder in project manifoldcf by apache.

the class ConfluenceClient method getConfluenceResources.

/**
 * <p>
 * Get the {@code ConfluenceResources} from the given url
 * </p>
 *
 * @param url
 *          The url identifying the REST resource to get the documents
 * @param builder
 *          The builder used to build the resources contained in the response
 * @return a {@code ConfluenceResponse} containing the page results
 * @throws Exception
 */
private ConfluenceResponse<? extends ConfluenceResource> getConfluenceResources(final String url, final ConfluenceResourceBuilder<? extends ConfluenceResource> builder) throws Exception {
    logger.debug("[Processing] Hitting url for get confluence resources: {}", sanitizeUrl(url));
    final HttpGet httpGet = createGetRequest(url);
    try (CloseableHttpResponse response = executeRequest(httpGet)) {
        final ConfluenceResponse<? extends ConfluenceResource> confluenceResponse = responseFromHttpEntity(response.getEntity(), builder);
        EntityUtils.consume(response.getEntity());
        return confluenceResponse;
    } catch (final IOException e) {
        logger.error("[Processing] Failed to get page(s)", e);
        throw new Exception("Confluence appears to be down", e);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) ConfluenceException(org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 ManifoldCFException (org.apache.manifoldcf.core.interfaces.ManifoldCFException)2 ConfluenceException (org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException)2 StringReader (java.io.StringReader)1 MutablePage (org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage)1 ConfluenceResourceBuilder (org.apache.manifoldcf.crawler.connectors.confluence.v6.model.builder.ConfluenceResourceBuilder)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1